Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the signalsBufferDir under context.getFilesDir() #859

Open
bencehornak opened this issue Feb 28, 2025 · 5 comments
Open

Move the signalsBufferDir under context.getFilesDir() #859

bencehornak opened this issue Feb 28, 2025 · 5 comments

Comments

@bencehornak
Copy link

At the moment the signalsBufferDir, which is used to store un-exported telemetry batches, is stored within context.getCacheDir():

val signalsBufferDir: File
get() {
val dir = File(cacheStorage.cacheDir, "opentelemetry/signals")
ensureExistingOrThrow(dir)
return dir
}

public File getCacheDir() {
return appContext.getCacheDir();
}

According to the docs there are no persistency guarantees for context.getCacheDir():

The system will automatically delete files in this directory as disk space is needed elsewhere on the device.

For those applications, where telemetry is a nice-to-have this sounds like an acceptable trade-off. In my case I cannot afford to lose telemetry because of the internal quirks of the OS, as there might be important business events standing in the device's queue.

So my recommendation is to move the signalsBufferDir under the more persistent getFilesDir() to prevent telemetry data loss caused by OS clean-ups.

@marandaneto
Copy link
Member

The system will automatically delete files in this directory as disk space is needed elsewhere on the device

This is handled by the OS when using getCacheDir

So I'd say it's better to provide a dir configuration rather than changing it, I think getCacheDir is perfect for telemetry data.
In this case, if you provide a custom dir, you have to deal with that manually.

@bencehornak
Copy link
Author

@marandaneto do you mean adding a new property to the DiskBufferingConfig like this?

Before:

val signalsBufferDir: File
get() {
val dir = File(cacheStorage.cacheDir, "opentelemetry/signals")
ensureExistingOrThrow(dir)
return dir
}

After:

    val signalsBufferDir: File
        get() {
            val dir = diskBufferingConfig.signalsBufferDir ?: File(cacheStorage.cacheDir, "opentelemetry/signals")
            ensureExistingOrThrow(dir)
            return dir
        }

If yes, I'm fine with that too, that would satisfy my goal too.

@marandaneto
Copy link
Member

Yes

@LikeTheSalad
Copy link
Contributor

I agree with @marandaneto and like your proposed solution, @bencehornak. Would you like to contribute it?

@bencehornak
Copy link
Author

Sure, I'll implement the new property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants