From a8f0d06c599cd722c76b9ca123d8f304570b57b1 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 18 Aug 2023 15:31:37 +0200 Subject: [PATCH 1/4] Backported #317 to 1.0.x --- .../otel/bridge/OtelBaggageInScope.java | 28 +++++++++++-------- .../tracing/otel/bridge/BaggageTests.java | 25 +++++++++++------ .../otel/bridge/OtelTracingApiTests.java | 10 ++++--- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/main/java/io/micrometer/tracing/otel/bridge/OtelBaggageInScope.java b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/main/java/io/micrometer/tracing/otel/bridge/OtelBaggageInScope.java index f2c295f7..d3ff60e2 100644 --- a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/main/java/io/micrometer/tracing/otel/bridge/OtelBaggageInScope.java +++ b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/main/java/io/micrometer/tracing/otel/bridge/OtelBaggageInScope.java @@ -43,6 +43,8 @@ class OtelBaggageInScope implements io.micrometer.tracing.Baggage, BaggageInScop private final AtomicReference entry = new AtomicReference<>(); + private final AtomicReference contextWithBaggage = new AtomicReference<>(null); + private final AtomicReference scope = new AtomicReference<>(); OtelBaggageInScope(OtelBaggageManager otelBaggageManager, CurrentTraceContext currentTraceContext, @@ -73,17 +75,18 @@ public String get(TraceContext traceContext) { } @Override + @Deprecated public io.micrometer.tracing.Baggage set(String value) { return doSet(this.currentTraceContext.context(), value); } private io.micrometer.tracing.Baggage doSet(TraceContext context, String value) { - Context current = Context.current(); - Span currentSpan = Span.current(); - io.opentelemetry.api.baggage.Baggage baggage; if (context == null) { return this; } + Context current = Context.current(); + Span currentSpan = Span.current(); + io.opentelemetry.api.baggage.Baggage baggage; OtelTraceContext ctx = (OtelTraceContext) context; Context storedCtx = ctx.context(); Baggage fromContext = Baggage.fromContext(storedCtx); @@ -97,7 +100,7 @@ private io.micrometer.tracing.Baggage doSet(TraceContext context, String value) current = current.with(baggage); Context withBaggage = current.with(baggage); ctx.updateContext(withBaggage); - this.scope.set(withBaggage.makeCurrent()); + contextWithBaggage.set(withBaggage); if (this.tagFields.stream().map(String::toLowerCase).anyMatch(s -> s.equals(entry().getKey()))) { currentSpan.setAttribute(entry().getKey(), value); } @@ -111,21 +114,24 @@ private Entry entry() { } @Override + @Deprecated public io.micrometer.tracing.Baggage set(TraceContext traceContext, String value) { return doSet(traceContext, value); } @Override public BaggageInScope makeCurrent() { - if (this.scope.get() == null) { - return this; - } - close(); Entry entry = entry(); - Scope scope = Baggage.builder() + Context context = contextWithBaggage.get(); + if (context == null) { + context = Context.current(); + } + Baggage baggage = Baggage.fromContext(context) + .toBuilder() .put(entry.getKey(), entry.getValue(), entry.getMetadata()) - .build() - .makeCurrent(); + .build(); + Context updated = context.with(baggage); + Scope scope = updated.makeCurrent(); this.scope.set(scope); return this; } diff --git a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/BaggageTests.java b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/BaggageTests.java index 6f88941a..55d71c6a 100644 --- a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/BaggageTests.java +++ b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/BaggageTests.java @@ -48,6 +48,10 @@ class BaggageTests { public static final String VALUE_1 = "value1"; + public static final String KEY_2 = "key2"; + + public static final String VALUE_2 = "value2"; + SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .setSampler(io.opentelemetry.sdk.trace.samplers.Sampler.alwaysOn()) .build(); @@ -79,10 +83,12 @@ void canSetAndGetBaggage() { Span span = tracer.nextSpan().start(); try (Tracer.SpanInScope spanInScope = tracer.withSpan(span)) { // WHEN - this.tracer.getBaggage(KEY_1).set(VALUE_1); - - // THEN - then(tracer.getBaggage(KEY_1).get()).isEqualTo(VALUE_1); + try (BaggageInScope bs1 = this.tracer.createBaggage(KEY_1, VALUE_1).makeCurrent(); + BaggageInScope bs2 = this.tracer.createBaggage(KEY_2, VALUE_2).makeCurrent()) { + // THEN + then(tracer.getBaggage(KEY_1).get()).isEqualTo(VALUE_1); + then(tracer.getBaggage(KEY_2).get()).isEqualTo(VALUE_2); + } } } @@ -93,13 +99,14 @@ void injectAndExtractKeepsTheBaggage() { Span span = tracer.nextSpan().start(); try (Tracer.SpanInScope spanInScope = tracer.withSpan(span)) { - this.tracer.createBaggage(KEY_1, VALUE_1); + try (BaggageInScope scope = this.tracer.createBaggage(KEY_1, VALUE_1).makeCurrent()) { + // WHEN + this.propagator.inject(tracer.currentTraceContext().context(), carrier, Map::put); - // WHEN - this.propagator.inject(tracer.currentTraceContext().context(), carrier, Map::put); + // THEN + then(carrier.get(KEY_1)).isEqualTo(VALUE_1); + } - // THEN - then(carrier.get(KEY_1)).isEqualTo(VALUE_1); } // WHEN diff --git a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/OtelTracingApiTests.java b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/OtelTracingApiTests.java index 27135f8a..23c11190 100644 --- a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/OtelTracingApiTests.java +++ b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/test/java/io/micrometer/tracing/otel/bridge/OtelTracingApiTests.java @@ -206,11 +206,13 @@ void should_work_with_baggage() { // Assuming that there's no span in scope Baggage baggageFour = tracer.createBaggage("from_span_in_scope 1", "value 1"); - // When there's no span in scope, there will never be any baggage - even if you - // make it current + then(tracer.currentSpan()).isNull(); + + // When there's no span in scope, baggage can still be there (that's incosistent + // with Brave) try (BaggageInScope baggage = baggageFour.makeCurrent()) { - then(baggageFour.get()).as("[Out of span scope] Baggage 1").isNull(); - then(tracer.getBaggage("from_span_in_scope 1").get()).as("[Out of span scope] Baggage 1").isNull(); + then(baggage.get()).as("[Out of span scope] Baggage 1").isNotNull(); + then(tracer.getBaggage("from_span_in_scope 1").get()).as("[Out of span scope] Baggage 1").isNotNull(); } then(tracer.getBaggage("from_span_in_scope 1").get()).as("[Out of scope] Baggage 1").isNull(); then(tracer.getBaggage("from_span_in_scope 2").get()).as("[Out of scope] Baggage 2").isNull(); From 11aee38607ecb504b9cee55979eea38ad0c6c64e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 15:42:27 -0400 Subject: [PATCH 2/4] Bump actions/checkout from 3.5.3 to 3.6.0 (#338) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.3 to 3.6.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.5.3...v3.6.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/gradle-wrapper-validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 9b268f21..fc0bbec9 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -6,5 +6,5 @@ jobs: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.5.3 + - uses: actions/checkout@v3.6.0 - uses: gradle/wrapper-validation-action@v1 From 6bd92971bb454df2c0a5bf94bc0d0a136ff084a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 12:02:45 -0400 Subject: [PATCH 3/4] Bump actions/checkout from 3.6.0 to 4.0.0 (#339) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.0.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.6.0...v4.0.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/gradle-wrapper-validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index fc0bbec9..48f83f60 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -6,5 +6,5 @@ jobs: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.6.0 + - uses: actions/checkout@v4.0.0 - uses: gradle/wrapper-validation-action@v1 From b08b4d7dd1ce9e04cfa2fff090e7f7fa3d08154b Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Thu, 7 Sep 2023 12:34:14 -0700 Subject: [PATCH 4/4] Match OTel semconv version to the SDK version We were depending on io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.24.0-alpha which brings in io.opentelemetry:opentelemetry-semconv:1.24.0-alpha and the same time we were also depending on io.opentelemetry:opentelemetry-sdk-trace:jar:1.25.0 which brings in io.opentelemetry:opentelemetry-semconv:1.25.0-alpha So basically we had 1.24.0-alpha and 1.25.0-alpha as well for io.opentelemetry:opentelemetry-semconv. Closes gh-340 --- benchmarks/gradle.lockfile | 4 ++-- dependencies.gradle | 2 +- .../micrometer-tracing-bridge-otel/gradle.lockfile | 4 ++-- .../micrometer-tracing-reporter-wavefront/gradle.lockfile | 4 ++-- .../micrometer-tracing-integration-test/gradle.lockfile | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/gradle.lockfile b/benchmarks/gradle.lockfile index ca0ca6d6..773b88b3 100644 --- a/benchmarks/gradle.lockfile +++ b/benchmarks/gradle.lockfile @@ -27,8 +27,8 @@ io.micrometer:context-propagation:1.0.5-SNAPSHOT=jmh,jmhCompileClasspath,jmhRunt io.micrometer:micrometer-bom:1.11.3-SNAPSHOT=jmh,jmhCompileClasspath,jmhRuntimeClasspath io.micrometer:micrometer-commons:1.11.3-SNAPSHOT=jmh,jmhCompileClasspath,jmhRuntimeClasspath io.micrometer:micrometer-observation:1.11.3-SNAPSHOT=jmh,jmhCompileClasspath,jmhRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.24.0-alpha=jmh,jmhCompileClasspath,jmhRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.24.0=jmh,jmhCompileClasspath,jmhRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.25.1-alpha=jmh,jmhCompileClasspath,jmhRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.25.1=jmh,jmhCompileClasspath,jmhRuntimeClasspath io.opentelemetry:opentelemetry-api-events:1.25.0-alpha=jmh,jmhRuntimeClasspath io.opentelemetry:opentelemetry-api-logs:1.25.0-alpha=jmh,jmhRuntimeClasspath io.opentelemetry:opentelemetry-api:1.25.0=jmh,jmhCompileClasspath,jmhRuntimeClasspath diff --git a/dependencies.gradle b/dependencies.gradle index 12dcd352..802d6652 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -14,7 +14,7 @@ def VERSIONS = [ 'org.apache.logging.log4j:log4j-core:2.+', 'org.slf4j:slf4j-api:1.7.+', // otel - 'io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.24.+', + 'io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.25.+', // zipkin 'io.zipkin.aws:brave-propagation-aws:latest.release', // wavefront diff --git a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/gradle.lockfile b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/gradle.lockfile index b71b4729..e3f1ae43 100644 --- a/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/gradle.lockfile +++ b/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/gradle.lockfile @@ -29,8 +29,8 @@ io.micrometer:micrometer-commons:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClas io.micrometer:micrometer-core:1.11.3-SNAPSHOT=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath io.micrometer:micrometer-observation-test:1.11.3-SNAPSHOT=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath io.micrometer:micrometer-observation:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.24.0-alpha=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.24.0=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.25.1-alpha=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.25.1=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api-events:1.25.0-alpha=compileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api-logs:1.25.0-alpha=compileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api:1.25.0=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath diff --git a/micrometer-tracing-reporters/micrometer-tracing-reporter-wavefront/gradle.lockfile b/micrometer-tracing-reporters/micrometer-tracing-reporter-wavefront/gradle.lockfile index 6cbe8b72..a6de60e9 100644 --- a/micrometer-tracing-reporters/micrometer-tracing-reporter-wavefront/gradle.lockfile +++ b/micrometer-tracing-reporters/micrometer-tracing-reporter-wavefront/gradle.lockfile @@ -37,8 +37,8 @@ io.micrometer:context-propagation:1.0.5-SNAPSHOT=compileClasspath,jmhCompileClas io.micrometer:micrometer-bom:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.micrometer:micrometer-commons:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.micrometer:micrometer-observation:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.24.0-alpha=compileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.24.0=compileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.25.1-alpha=compileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.25.1=compileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api-events:1.25.0-alpha=jmhRuntimeClasspath,runtimeClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api-logs:1.25.0-alpha=jmhRuntimeClasspath,runtimeClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api:1.25.0=compileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath diff --git a/micrometer-tracing-tests/micrometer-tracing-integration-test/gradle.lockfile b/micrometer-tracing-tests/micrometer-tracing-integration-test/gradle.lockfile index 65c698f4..4dcb322e 100644 --- a/micrometer-tracing-tests/micrometer-tracing-integration-test/gradle.lockfile +++ b/micrometer-tracing-tests/micrometer-tracing-integration-test/gradle.lockfile @@ -46,8 +46,8 @@ io.micrometer:micrometer-core:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspa io.micrometer:micrometer-observation-test:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.micrometer:micrometer-observation:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.micrometer:micrometer-test:1.11.3-SNAPSHOT=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.24.0-alpha=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.24.0=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.25.1-alpha=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.25.1=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api-events:1.25.0-alpha=jmhRuntimeClasspath,runtimeClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api-logs:1.25.0-alpha=jmhRuntimeClasspath,runtimeClasspath,testRuntimeClasspath io.opentelemetry:opentelemetry-api:1.25.0=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath