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

Allow setting proguard via Options and/or external resources #1236

Closed
marandaneto opened this issue Feb 9, 2021 · 3 comments · Fixed by #1728
Closed

Allow setting proguard via Options and/or external resources #1236

marandaneto opened this issue Feb 9, 2021 · 3 comments · Fixed by #1728
Labels
enhancement New feature or request
Milestone

Comments

@marandaneto
Copy link
Contributor

marandaneto commented Feb 9, 2021

A Java App (non Android-probably Desktop) may be obfuscated using the Proguard tooling and right now there's no easy way to set up the proguard id if not using the beforeSend callback.
Ideally, this would be possible via SentryOptions or external resources.

See on Android:

for (String item : proguardUUIDs) {
DebugImage debugImage = new DebugImage();
debugImage.setType("proguard");
debugImage.setUuid(item);
images.add(debugImage);
}

on Android the Sentry Gradle plugin uploads the mapping file via sentry-cli and injects its id in the assets folder of the App which is packaged in the final APK.
At runtime, the SDK reads this file and sets the id to the debug images.

@marandaneto marandaneto added the enhancement New feature or request label Feb 9, 2021
@bruno-garcia bruno-garcia added this to the Desktop milestone Feb 9, 2021
@marandaneto
Copy link
Contributor Author

every Java app would benefit from it, so removing the specific labels

@marandaneto
Copy link
Contributor Author

a dumb example would be:

        sentryOptions.setBeforeSend { event, _ ->
            if (event.debugMeta == null) {
                event.debugMeta = DebugMeta()
            }
            if (event.debugMeta.images == null) {
                event.debugMeta.images = mutableListOf()
            }
            event.debugMeta.images.add(DebugImage().apply {
                type = "proguard"
                uuid = "your_generated_uuid" // using `sentry-cli upload-proguard`
            })

            event
        }

@0xVesion
Copy link

I also came across this issue and would really like to help. If you could give me some advice on how I should/could implement the solution into sentry-java or sentry-spring, I would be happy to do so.

Temporary Spring Boot Solution:
For now you can drop this class into a spring-boot application. After doing so you can set sentry.proguardUuids in your application.properties file to pass the uuids to every event that gets sent to sentry.

package XX;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import io.sentry.SentryEvent;
import io.sentry.SentryOptions.BeforeSendCallback;
import io.sentry.protocol.DebugImage;
import io.sentry.protocol.DebugMeta;

@Component
public class SentryProguardBeforeSendCallback implements BeforeSendCallback {
  private final String[] proguardUuids;

  public SentryProguardBeforeSendCallback(@Value("${sentry.proguardUuids}") String[] proguardUuids) {
    this.proguardUuids = proguardUuids;
  }

  @Override
  public SentryEvent execute(SentryEvent event, Object hint) {
    if (event.getDebugMeta() == null) {
      event.setDebugMeta(new DebugMeta());
    }

    if (event.getDebugMeta().getImages() == null) {
      event.getDebugMeta().setImages(new ArrayList<DebugImage>());
    }

    final var debugImages = Arrays
      .stream(proguardUuids)
      .map((uuid) -> {
        final var image = new DebugImage();

        image.setType("proguard");
        image.setUuid(uuid);

        return image;
      })
      .collect(Collectors.toList());
    
    event.getDebugMeta().getImages().addAll(debugImages);

    return event;
  }
}

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

Successfully merging a pull request may close this issue.

3 participants