sentry-java
sentry-java copied to clipboard
Allow using a custom Hub with SentryTraced for Jetpack Compose
Problem Statement
I would like to provide my own Hub when using the SentryTraced composable.
Currently, the default SentryTraced composable relies on the top-level static Sentry object for fetching the current transaction (by way of the getRootSpan() function), which can be limiting for users who wish to utilize a custom hub. This limitation can lead to potential issues when attempting to manage multiple Sentry/Hub instances or when needing to apply custom configurations to individual instances.
Solution Brainstorm
Some potential solutions could be:
- Allowing a
Hubto be passed in to the composable - Allowing a
Transactionto be passed in to the composable
@vanshg thanks for trying out the new tracing feature! To me this totally makes sense to allow passing a hub instance, @markushi what do you think?
Hello again! Any update on this?
Hey @vanshg, thanks for reaching out!
I guess expanding SentryTraced with a hub argument should be easy enough to cover your use case
public fun SentryTraced(
tag: String,
modifier: Modifier = Modifier,
hub = Sentry.getCurrentHub(),
enableUserInteractionTracing: Boolean = true,
content: @Composable BoxScope.() -> Unit
)
Just out of curiosity: Could you elaborate a bit why you'd want to use a custom hub?
On a second thought, https://developer.android.com/jetpack/compose/compositionlocal would be a more "Compose" way of doing this. We even do that right now (see source) we would just need to expose the APIs, as they're private right now.
Just out of curiosity: Could you elaborate a bit why you'd want to use a custom hub?
We develop an SDK and we track crashes via our own Hub with our own DSN, so as not to intrude on the application developer's usage of Sentry from the top-level/static Sentry
https://developer.android.com/jetpack/compose/compositionlocal would be a more "Compose" way of doing this
I wouldn't be opposed to a composition local approach. But I wonder how the interface for that would work? If you're setting the composition local inside the SentryTraced composable, how could I override it from outside? Is there a way to have a default composition local value if one hasn't been set? (I haven't worked directly with creating my own composition locals, so pardon any ignorance)