Search code examples
javasentry

How can I tag just one Sentry event?


I want to report Sentry event with some specified tag, however I do not want to include this tag in future events.

With the following code, I'm adding a tag and reporting event:

Sentry.getContext().addTag("my_tag", "yes");
Sentry.capture("event happened");

Then, after a while, another event occurs:

Sentry.capture("another event happened"); // tag is included, but I don't want it

I've tried removing tag by Sentry.clearContext() but it clears all information, including breadcrumbs.

I've also tried Sentry.getContext().getTags().remove("my_tag"); but, since tags are keept in UnmodifiableMap, this operation just throws an exception.


Solution

  • As of sentry-java 1.5.2 (just released to fix this) you can use new methods on the Context to clean up after temporary tags/extra data:

    Sentry.getContext().removeTag("my_tag");
    Sentry.getContext().clearTags();
    
    Sentry.getContext().removeExtra("my_extra");
    Sentry.getContext().clearExtra();