Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ buildConfig {
tasks.jar {
manifest {
attributes(
"Sentry-Opentelemetry-SDK-Name" to
Config.Sentry.SENTRY_OPENTELEMETRY_AGENTLESS_SPRING_SDK_NAME,
"Sentry-Version-Name" to project.version,
"Sentry-SDK-Name" to Config.Sentry.SENTRY_OPENTELEMETRY_AGENTLESS_SPRING_SDK_NAME,
"Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-opentelemetry-agentless-spring",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ buildConfig {
tasks.jar {
manifest {
attributes(
"Sentry-Opentelemetry-SDK-Name" to Config.Sentry.SENTRY_OPENTELEMETRY_AGENTLESS_SDK_NAME,
"Sentry-Version-Name" to project.version,
"Sentry-SDK-Name" to Config.Sentry.SENTRY_OPENTELEMETRY_AGENTLESS_SDK_NAME,
"Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-opentelemetry-agentless",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class ManifestVersionReader {
private static final @NotNull AutoClosableReentrantLock staticLock =
new AutoClosableReentrantLock();
private volatile boolean hasManifestBeenRead = false;
private volatile @Nullable VersionInfoHolder versionInfo = null;
private final @NotNull VersionInfoHolder versionInfo = new VersionInfoHolder();
private @NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock();

public static @NotNull ManifestVersionReader getInstance() {
Expand All @@ -40,6 +40,9 @@ private ManifestVersionReader() {}

public @Nullable VersionInfoHolder readOpenTelemetryVersion() {
readManifestFiles();
if (versionInfo.sdkVersion == null) {
return null;
}
return versionInfo;
}

Expand All @@ -48,7 +51,6 @@ public void readManifestFiles() {
return;
}

@Nullable VersionInfoHolder infoHolder = null;
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
if (hasManifestBeenRead) {
return;
Expand All @@ -66,28 +68,32 @@ public void readManifestFiles() {
final @Nullable String packageName = mainAttributes.getValue("Sentry-SDK-Package-Name");

if (name != null && version != null) {
infoHolder = new VersionInfoHolder();
infoHolder.sdkName = name;
infoHolder.sdkVersion = version;
infoHolder.packages.add(
new SentryPackage("maven:io.sentry:sentry-opentelemetry-agent", version));
versionInfo.sdkName = name;
versionInfo.sdkVersion = version;
final @Nullable String otelVersion =
mainAttributes.getValue("Sentry-Opentelemetry-Version-Name");
if (otelVersion != null) {
infoHolder.packages.add(
versionInfo.packages.add(
new SentryPackage("maven:io.opentelemetry:opentelemetry-sdk", otelVersion));
infoHolder.integrations.add("OpenTelemetry");
versionInfo.integrations.add("OpenTelemetry");
}
final @Nullable String otelJavaagentVersion =
mainAttributes.getValue("Sentry-Opentelemetry-Javaagent-Version-Name");
if (otelJavaagentVersion != null) {
infoHolder.packages.add(
versionInfo.packages.add(
new SentryPackage(
"maven:io.opentelemetry.javaagent:opentelemetry-javaagent",
otelJavaagentVersion));
infoHolder.integrations.add("OpenTelemetry-Agent");
versionInfo.integrations.add("OpenTelemetry-Agent");
}
if (name.equals("sentry.java.opentelemetry.agentless")) {
SentryIntegrationPackageStorage.getInstance()
.addIntegration("OpenTelemetry-Agentless");
}
if (name.equals("sentry.java.opentelemetry.agentless-spring")) {
SentryIntegrationPackageStorage.getInstance()
.addIntegration("OpenTelemetry-Agentless-Spring");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Manifest Loop Issue Causes SDK Version Overwrite

The removal of the break statement from the manifest processing loop causes versionInfo.sdkName and versionInfo.sdkVersion to be overwritten by each subsequent OpenTelemetry manifest found. This leads to non-deterministic and potentially incorrect SDK version reporting, as only the last processed manifest's details are retained. Furthermore, the maven:io.sentry:sentry-opentelemetry-agent package is no longer added, resulting in incomplete package information.

Locations (1)
Fix in Cursor Fix in Web

Comment on lines +90 to +95
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add to versionInfo here, not to SentryIntegrationPackageStorage directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels much cleaner to just remove integrations and packages from VersionInfoHolder and add them directly.
That's also what ManifestVersionDetector expects.

}
break;
}

if (sdkName != null
Expand All @@ -105,13 +111,12 @@ public void readManifestFiles() {
// ignore
} finally {
hasManifestBeenRead = true;
versionInfo = infoHolder;
}
}

public static final class VersionInfoHolder {
private @Nullable String sdkName;
private @Nullable String sdkVersion;
private volatile @Nullable String sdkName;
private volatile @Nullable String sdkVersion;
private List<SentryPackage> packages = new ArrayList<>();
private List<String> integrations = new ArrayList<>();

Expand Down
Loading