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

Setting proguard uuid dynamically #1333

Closed
lwasyl opened this issue Mar 18, 2021 · 5 comments
Closed

Setting proguard uuid dynamically #1333

lwasyl opened this issue Mar 18, 2021 · 5 comments

Comments

@lwasyl
Copy link

lwasyl commented Mar 18, 2021

I'm using SentryAndroid and I'd like to set the proguard uuid dynamically from code. The reason is that apparently the Gradle plugin doesn't always work, and adding a .properties file with the ID is not convenient. I want to generate the uuid from the application id + version code, and these information are trivial to get in code, much less to figure out during the build, put in a file, put file in proper source sets and make sure I didn't break Gradle's caching. Ideally I'd want something like

Sentry.setProguardUuid("${BuildConfig.APPLICATION_ID}-${BuildConfig.VERSION_CODE}")

I understand it's not that easy right now so I'm willing to use some less-public, unsupported API that can break in the future, but will work now. From what I see the proguard uuid value is currently stored somewhere in event.debugMeta.images and I'd need to set it there, but I'm not sure:

  • can I do it once or I need to add the key for every event using an event processor
  • how I should do that to make sure DefaultAndroidEventProcessor doesn't override the value I set

Right now my guess is that I should be able to do:

Sentry.configureScope { scope ->
    scope.addEventProcessor { event, _ ->
        val customProguardDebugImageType = "_custom_proguard_image"
        if (event.debugMeta.images.none { it.type == customProguardDebugImageType }) {
            event.debugMeta.images.add(
                DebugImage().apply {
                    type = customProguardDebugImageType
                    uuid = currentProguardId
                }
            )
        }
        event
    }
}

and if I don't put the Sentry .properties file anywhere, then DefaultAndroidEventProcessor won't put proguard key entry at all so my currentProguardId would be used?

@marandaneto
Copy link
Contributor

thanks for reporting @lwasyl

dup of #1236 please read the issue and there's a workaround for it, you are on the right track though.
if u are having problems with the Gradle plugin, we are currently working on it too, see getsentry/sentry-android-gradle-plugin#50

@lwasyl
Copy link
Author

lwasyl commented Mar 18, 2021

@marandaneto I saw that issue, but it specifically referred to non-Android app. Big chunk of my doubts is related to the fact that the default android processor already does whatever the workaround suggests, in particular setting the debug meta images iff event.getDebugMeta().getImages() == null). This seems like something that can break when both my custom listener and default android processor are executed - either my or Android one would not set its own images, isn't that right? Or the getDebugMeta is cloned for each event and the clone is only mutated by each processor once?

@marandaneto
Copy link
Contributor

it just adds to the list if one already exists, so being Android or non Android app, it'd work the same way:

private void mergeDebugImages(final @NotNull SentryEvent event) {
final List<DebugImage> debugImages = getDebugImages();
if (debugImages == null) {
return;
}
DebugMeta debugMeta = event.getDebugMeta();
if (debugMeta == null) {
debugMeta = new DebugMeta();
}
// sets the imageList or append to the list if it already exists
if (debugMeta.getImages() == null) {
debugMeta.setImages(debugImages);
} else {
debugMeta.getImages().addAll(debugImages);
}
event.setDebugMeta(debugMeta);
}

@lwasyl
Copy link
Author

lwasyl commented Mar 18, 2021

Ah, that's right. Well then the last question is, should I check for my custom image and only add it if it's not present, because DebugMeta is reused between events, or every processing will get a fresh DebugMeta instance and I can just add my image to it?

@marandaneto
Copy link
Contributor

both would work, the later is ideal

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

2 participants