22
33import io .sentry .ISentryLifecycleToken ;
44import io .sentry .SentryIntegrationPackageStorage ;
5- import io .sentry .protocol .SentryPackage ;
65import io .sentry .util .AutoClosableReentrantLock ;
76import java .io .IOException ;
87import java .net .URL ;
9- import java .util .ArrayList ;
108import java .util .Enumeration ;
11- import java .util .List ;
129import java .util .jar .Attributes ;
1310import java .util .jar .Manifest ;
1411import org .jetbrains .annotations .ApiStatus ;
@@ -21,7 +18,7 @@ public final class ManifestVersionReader {
2118 private static final @ NotNull AutoClosableReentrantLock staticLock =
2219 new AutoClosableReentrantLock ();
2320 private volatile boolean hasManifestBeenRead = false ;
24- private volatile @ Nullable VersionInfoHolder versionInfo = null ;
21+ private final @ NotNull VersionInfoHolder versionInfo = new VersionInfoHolder () ;
2522 private @ NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock ();
2623
2724 public static @ NotNull ManifestVersionReader getInstance () {
@@ -40,6 +37,9 @@ private ManifestVersionReader() {}
4037
4138 public @ Nullable VersionInfoHolder readOpenTelemetryVersion () {
4239 readManifestFiles ();
40+ if (versionInfo .sdkVersion == null ) {
41+ return null ;
42+ }
4343 return versionInfo ;
4444 }
4545
@@ -48,7 +48,6 @@ public void readManifestFiles() {
4848 return ;
4949 }
5050
51- @ Nullable VersionInfoHolder infoHolder = null ;
5251 try (final @ NotNull ISentryLifecycleToken ignored = lock .acquire ()) {
5352 if (hasManifestBeenRead ) {
5453 return ;
@@ -66,28 +65,32 @@ public void readManifestFiles() {
6665 final @ Nullable String packageName = mainAttributes .getValue ("Sentry-SDK-Package-Name" );
6766
6867 if (name != null && version != null ) {
69- infoHolder = new VersionInfoHolder ();
70- infoHolder .sdkName = name ;
71- infoHolder .sdkVersion = version ;
72- infoHolder .packages .add (
73- new SentryPackage ("maven:io.sentry:sentry-opentelemetry-agent" , version ));
68+ versionInfo .sdkName = name ;
69+ versionInfo .sdkVersion = version ;
7470 final @ Nullable String otelVersion =
7571 mainAttributes .getValue ("Sentry-Opentelemetry-Version-Name" );
7672 if (otelVersion != null ) {
77- infoHolder . packages . add (
78- new SentryPackage ("maven:io.opentelemetry:opentelemetry-sdk" , otelVersion ) );
79- infoHolder . integrations . add ("OpenTelemetry" );
73+ SentryIntegrationPackageStorage . getInstance ()
74+ . addPackage ("maven:io.opentelemetry:opentelemetry-sdk" , otelVersion );
75+ SentryIntegrationPackageStorage . getInstance (). addIntegration ("OpenTelemetry" );
8076 }
8177 final @ Nullable String otelJavaagentVersion =
8278 mainAttributes .getValue ("Sentry-Opentelemetry-Javaagent-Version-Name" );
8379 if (otelJavaagentVersion != null ) {
84- infoHolder . packages . add (
85- new SentryPackage (
80+ SentryIntegrationPackageStorage . getInstance ()
81+ . addPackage (
8682 "maven:io.opentelemetry.javaagent:opentelemetry-javaagent" ,
87- otelJavaagentVersion ));
88- infoHolder .integrations .add ("OpenTelemetry-Agent" );
83+ otelJavaagentVersion );
84+ SentryIntegrationPackageStorage .getInstance ().addIntegration ("OpenTelemetry-Agent" );
85+ }
86+ if (name .equals ("sentry.java.opentelemetry.agentless" )) {
87+ SentryIntegrationPackageStorage .getInstance ()
88+ .addIntegration ("OpenTelemetry-Agentless" );
89+ }
90+ if (name .equals ("sentry.java.opentelemetry.agentless-spring" )) {
91+ SentryIntegrationPackageStorage .getInstance ()
92+ .addIntegration ("OpenTelemetry-Agentless-Spring" );
8993 }
90- break ;
9194 }
9295
9396 if (sdkName != null
@@ -105,15 +108,12 @@ public void readManifestFiles() {
105108 // ignore
106109 } finally {
107110 hasManifestBeenRead = true ;
108- versionInfo = infoHolder ;
109111 }
110112 }
111113
112114 public static final class VersionInfoHolder {
113- private @ Nullable String sdkName ;
114- private @ Nullable String sdkVersion ;
115- private List <SentryPackage > packages = new ArrayList <>();
116- private List <String > integrations = new ArrayList <>();
115+ private volatile @ Nullable String sdkName ;
116+ private volatile @ Nullable String sdkVersion ;
117117
118118 public @ Nullable String getSdkName () {
119119 return sdkName ;
@@ -122,13 +122,5 @@ public static final class VersionInfoHolder {
122122 public @ Nullable String getSdkVersion () {
123123 return sdkVersion ;
124124 }
125-
126- public List <SentryPackage > getPackages () {
127- return packages ;
128- }
129-
130- public List <String > getIntegrations () {
131- return integrations ;
132- }
133125 }
134126}
0 commit comments