Restrict Sentry events just from the Android SDK/Library

We have created an Android SDK/Library which is available for public use. We have integrated Sentry in our Android Library and handling/logging exceptions from our SDK only.

But when our SDK/Library is installed in an Android app, the exceptions from the app are also coming to our account which is polluting the real exceptions that we should handle in our Library/SDK.

How can we restrict the Sentry to capture events/exceptions generated from our Android Library only (or how can we exclude the events/exceptions from the app where our Android Library is being used)?

Tried to search StackOverflow, this forum and documentation but couldn’t find anything any such thing.

how are you initializing the Android SDK in your Android library and how are you capturing events using the Android SDK, can you share some code snippets?

The Sentry Android SDK is tailored for apps and not libraries, if the final App also uses Sentry, both will be in conflict.

Have a look at this issue Support two instances of sentry client · Issue #993 · getsentry/sentry-java · GitHub
Ideally, you create an instance of Hub and uses this object to capture events.

Hi Manoel,

Thanks for reverting back. I’m sharing some code snippet screenshot of how we are initializing the Sentry and adding some global tags.

Apart from the above initialization, we also have the same DNS value initialize in the AndroidManifest.xml of our Android library like–

<meta-data
        android:name="io.sentry.dsn"

No, the final app does not have Sentry but thanks for sharing that GitHub issue. Will read about Hub.

1 Like

the way how you’re doing it is not correct for library authors.
I’ve just created this issue, Document if the Android SDK is supported for library authors · Issue #3611 · getsentry/sentry-docs · GitHub please follow up on it.

if you are sure that the final App that uses your library is never adding Sentry as well, you could pretty much do this:

use the beforeSend callback to filter out events that don’t contain your library’s package inspecting the SentryEvent#exception#values#stacktrace#frames#module field.

Also have a look at Manual Initialization for Android | Sentry Documentation
if you are initing the Sentry Android SDK manually using SentryAndroid#init, you’ve to disable the auto-init mode.

1 Like