-
-
Notifications
You must be signed in to change notification settings - Fork 461
Initialize Sentry in OTEL Java Agent and allow configuring it #2386
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
Changes from all commits
06a4570
cca09cf
687d2fe
52d86a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -4,19 +4,87 @@ | |||
| import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; | ||||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||||
| import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; | ||||
| import io.sentry.Instrumenter; | ||||
| import io.sentry.Sentry; | ||||
| import io.sentry.SentryOptions; | ||||
| import io.sentry.protocol.SdkVersion; | ||||
| import java.io.IOException; | ||||
| import java.net.URL; | ||||
| import java.util.Enumeration; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.jar.Attributes; | ||||
| import java.util.jar.Manifest; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
|
|
||||
| public final class SentryAutoConfigurationCustomizerProvider | ||||
| implements AutoConfigurationCustomizerProvider { | ||||
|
|
||||
| @Override | ||||
| public void customize(AutoConfigurationCustomizer autoConfiguration) { | ||||
| final @Nullable String sentryPropertiesFile = System.getenv("SENTRY_PROPERTIES_FILE"); | ||||
| final @Nullable String sentryDsn = System.getenv("SENTRY_DSN"); | ||||
|
|
||||
| if (sentryPropertiesFile != null || sentryDsn != null) { | ||||
| Sentry.init( | ||||
| options -> { | ||||
| options.setEnableExternalConfiguration(true); | ||||
| options.setInstrumenter(Instrumenter.OTEL); | ||||
| final @Nullable SdkVersion sdkVersion = createSdkVersion(options); | ||||
| if (sdkVersion != null) { | ||||
| options.setSdkVersion(sdkVersion); | ||||
| } | ||||
| }); | ||||
| } | ||||
|
|
||||
| autoConfiguration | ||||
| .addTracerProviderCustomizer(this::configureSdkTracerProvider) | ||||
| .addPropertiesSupplier(this::getDefaultProperties); | ||||
| } | ||||
|
|
||||
| private @Nullable SdkVersion createSdkVersion(final @NotNull SentryOptions sentryOptions) { | ||||
| SdkVersion sdkVersion = sentryOptions.getSdkVersion(); | ||||
|
|
||||
| try { | ||||
| final @NotNull Enumeration<URL> resources = | ||||
| ClassLoader.getSystemClassLoader().getResources("META-INF/MANIFEST.MF"); | ||||
| while (resources.hasMoreElements()) { | ||||
| try { | ||||
| final @NotNull Manifest manifest = new Manifest(resources.nextElement().openStream()); | ||||
| final @Nullable Attributes mainAttributes = manifest.getMainAttributes(); | ||||
| if (mainAttributes != null) { | ||||
| final @Nullable String name = mainAttributes.getValue("Sentry-Opentelemetry-SDK-Name"); | ||||
| final @Nullable String version = mainAttributes.getValue("Sentry-Version-Name"); | ||||
|
|
||||
| if (name != null && version != null) { | ||||
| sdkVersion = SdkVersion.updateSdkVersion(sdkVersion, name, version); | ||||
| sdkVersion.addPackage("maven:io.sentry:sentry-opentelemetry-agent", version); | ||||
| final @Nullable String otelVersion = | ||||
| mainAttributes.getValue("Sentry-Opentelemetry-Version-Name"); | ||||
| if (otelVersion != null) { | ||||
| sdkVersion.addPackage("maven:io.opentelemetry:opentelemetry-sdk", otelVersion); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, discussed with someone from backend team. Should be fine. Is there a better place to put it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. packages/modules maybe? that's where we put the 3rd-party stuff
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean this:
That's for errors, not transactions unfortunately.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeah, then it's probably fine like that |
||||
| } | ||||
| final @Nullable String otelJavaagentVersion = | ||||
| mainAttributes.getValue("Sentry-Opentelemetry-Javaagent-Version-Name"); | ||||
| if (otelJavaagentVersion != null) { | ||||
| sdkVersion.addPackage( | ||||
| "maven:io.opentelemetry.javaagent:opentelemetry-javaagent", | ||||
| otelJavaagentVersion); | ||||
| } | ||||
| } | ||||
| } | ||||
| } catch (Exception e) { | ||||
| // ignore | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do |
||||
| } | ||||
| } | ||||
| } catch (IOException e) { | ||||
| // ignore | ||||
| } | ||||
|
|
||||
| return sdkVersion; | ||||
| } | ||||
|
|
||||
| private SdkTracerProviderBuilder configureSdkTracerProvider( | ||||
| SdkTracerProviderBuilder tracerProvider, ConfigProperties config) { | ||||
| return tracerProvider.addSpanProcessor(new SentrySpanProcessor()); | ||||
|
|
||||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.