From e6573dfd623c6acbbc44fede4f10acd1f019ed45 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Oct 2026 21:25:30 +0000 Subject: [PATCH 1/5] Initial plan From 5bd9fd5c1f7df4c5e9fb94553e42a41ec2fda066 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Oct 2026 21:31:31 +0000 Subject: [PATCH 2/5] Restrict span annotations to methods Co-authored-by: trask <218610+trask@users.noreply.github.com> --- CHANGELOG.md | 2 + .../annotations/AddingSpanAttributes.java | 6 +-- .../instrumentation/annotations/WithSpan.java | 6 +-- ...dingSpanAttributesInstrumentationTest.java | 37 +++---------------- .../ConstructedWithAddingSpanAttributes.java | 22 ----------- .../ConstructorOnlyAddingSpanAttributes.java | 19 ---------- .../test/annotation/TracedWithSpan.java | 4 -- .../WithSpanInstrumentationTest.java | 10 ++--- 8 files changed, 17 insertions(+), 89 deletions(-) delete mode 100644 instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructedWithAddingSpanAttributes.java delete mode 100644 instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructorOnlyAddingSpanAttributes.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 65f62ec2ba66..c3218c38763d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### ⚠️ Breaking changes +- In `opentelemetry-instrumentation-annotations` 3.0, `@WithSpan` and + `@AddingSpanAttributes` target methods only. Remove them from constructors. - Kotlin suspend function `@WithSpan` instrumentation now uses only the `kotlinx-coroutines-annotations` selector and is disabled by default. Use `otel.instrumentation.kotlinx-coroutines-annotations.enabled=true` instead of the diff --git a/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/AddingSpanAttributes.java b/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/AddingSpanAttributes.java index 3914aa7b1b6c..372d451248cc 100644 --- a/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/AddingSpanAttributes.java +++ b/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/AddingSpanAttributes.java @@ -14,9 +14,7 @@ * This annotation marks that an execution of this method is able to add attributes to the current * span {@link io.opentelemetry.api.trace.Span}. * - *

Using this annotation on constructors is not supported by OpenTelemetry instrumentation. The - * {@link ElementType#CONSTRUCTOR} target exists only for backward compatibility and is planned to - * be removed in the 3.0 release. + *

This annotation can only be applied to methods. Constructor instrumentation is not supported. * *

Application developers can use this annotation to signal OpenTelemetry auto-instrumentation * that attributes annotated with the {@link @@ -34,6 +32,6 @@ *

If you are a library developer, then probably you should NOT use this annotation, because it * is non-functional without some form of auto-instrumentation. */ -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) // CONSTRUCTOR target to be removed in 3.0 +@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface AddingSpanAttributes {} diff --git a/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/WithSpan.java b/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/WithSpan.java index ef6785f6c4cc..15f4e38964ac 100644 --- a/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/WithSpan.java +++ b/instrumentation-annotations/src/main/java/io/opentelemetry/instrumentation/annotations/WithSpan.java @@ -16,9 +16,7 @@ * This annotation marks that an execution of this method should result in a new {@link * io.opentelemetry.api.trace.Span}. * - *

Using this annotation on constructors is not supported by OpenTelemetry instrumentation. The - * {@link ElementType#CONSTRUCTOR} target exists only for backward compatibility and is planned to - * be removed in the 3.0 release. + *

This annotation can only be applied to methods. Constructor instrumentation is not supported. * *

Application developers can use this annotation to signal OpenTelemetry auto-instrumentation * that a new span should be created whenever the marked method is executed. @@ -26,7 +24,7 @@ *

If you are a library developer, then probably you should NOT use this annotation, because it * is non-functional without some form of auto-instrumentation. */ -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) // CONSTRUCTOR target to be removed in 3.0 +@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface WithSpan { /** diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/AddingSpanAttributesInstrumentationTest.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/AddingSpanAttributesInstrumentationTest.java index 5b6dad3fc7dd..f6dfad84f15c 100644 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/AddingSpanAttributesInstrumentationTest.java +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/AddingSpanAttributesInstrumentationTest.java @@ -12,7 +12,10 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.annotations.AddingSpanAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -77,37 +80,9 @@ void noExistingSpan() { } @Test - void constructorOnlyAddingSpanAttributesDoesNotTransformType() { - testing.runWithSpan( - "root", () -> new ConstructorOnlyAddingSpanAttributes("foo", "bar", null, "baz")); - - testing.waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("root") - .hasKind(SpanKind.INTERNAL) - .hasNoParent() - .hasTotalAttributeCount(0))); - } - - @Test - void constructorAndMethodAddingSpanAttributesIgnoresConstructor() { - testing.runWithSpan( - "root", - () -> - new ConstructedWithAddingSpanAttributes("foo", "bar", null, "baz") - .addAttributes("method")); - - testing.waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("root") - .hasKind(SpanKind.INTERNAL) - .hasNoParent() - .hasAttributesSatisfyingExactly( - equalTo(stringKey("methodAttribute"), "method")))); + void annotationTargetsMethodsOnly() { + assertThat(AddingSpanAttributes.class.getAnnotation(Target.class).value()) + .containsExactly(ElementType.METHOD); } @Test diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructedWithAddingSpanAttributes.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructedWithAddingSpanAttributes.java deleted file mode 100644 index 55e08433d566..000000000000 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructedWithAddingSpanAttributes.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.test.annotation; - -import io.opentelemetry.instrumentation.annotations.AddingSpanAttributes; -import io.opentelemetry.instrumentation.annotations.SpanAttribute; - -class ConstructedWithAddingSpanAttributes { - - @AddingSpanAttributes - ConstructedWithAddingSpanAttributes( - @SpanAttribute String implicitName, - @SpanAttribute("explicitName") String parameter, - @SpanAttribute("nullAttribute") String nullAttribute, - String notTraced) {} - - @AddingSpanAttributes - void addAttributes(@SpanAttribute("methodAttribute") String methodAttribute) {} -} diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructorOnlyAddingSpanAttributes.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructorOnlyAddingSpanAttributes.java deleted file mode 100644 index 45eda9e12887..000000000000 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/ConstructorOnlyAddingSpanAttributes.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.test.annotation; - -import io.opentelemetry.instrumentation.annotations.AddingSpanAttributes; -import io.opentelemetry.instrumentation.annotations.SpanAttribute; - -class ConstructorOnlyAddingSpanAttributes { - - @AddingSpanAttributes - ConstructorOnlyAddingSpanAttributes( - @SpanAttribute String implicitName, - @SpanAttribute("explicitName") String parameter, - @SpanAttribute("nullAttribute") String nullAttribute, - String notTraced) {} -} diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/TracedWithSpan.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/TracedWithSpan.java index cb17cf9376b3..9d3f9ee343b1 100644 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/TracedWithSpan.java +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/TracedWithSpan.java @@ -15,10 +15,6 @@ class TracedWithSpan { TracedWithSpan() {} - // used to verify that constructor with @WithSpan annotation doesn't break instrumentation - @WithSpan - TracedWithSpan(String unused) {} - @WithSpan String otel() { return "hello!"; diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java index da5890d8876e..b5f033b0dd15 100644 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java @@ -19,6 +19,8 @@ import io.opentelemetry.instrumentation.annotations.WithSpan; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.sdk.trace.data.StatusData; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; import java.lang.reflect.Modifier; import java.util.concurrent.CompletableFuture; import net.bytebuddy.ByteBuddy; @@ -146,11 +148,9 @@ void excludedMethod() throws InterruptedException { } @Test - void annotatedConstructorDoesNotCreateSpan() throws InterruptedException { - new TracedWithSpan("unused"); - - Thread.sleep(500); // sleep a bit just to make sure no span is captured - assertThat(testing.waitForTraces(0)).isEmpty(); + void annotationTargetsMethodsOnly() { + assertThat(WithSpan.class.getAnnotation(Target.class).value()) + .containsExactly(ElementType.METHOD); } @Test From 009e6bf247d2a2a15e0c3998e6f8beec210df27a Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 20 Oct 2026 14:53:24 -0700 Subject: [PATCH 3/5] Update breaking changes section in CHANGELOG Clarify breaking changes in opentelemetry-instrumentation-annotations. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3218c38763d..4411d89d9c04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### ⚠️ Breaking changes - In `opentelemetry-instrumentation-annotations` 3.0, `@WithSpan` and - `@AddingSpanAttributes` target methods only. Remove them from constructors. + `@AddingSpanAttributes` target methods only. - Kotlin suspend function `@WithSpan` instrumentation now uses only the `kotlinx-coroutines-annotations` selector and is disabled by default. Use `otel.instrumentation.kotlinx-coroutines-annotations.enabled=true` instead of the From f40160730d985e35cf6fd66dfb1be77bdc22e077 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 20 Oct 2026 14:54:21 -0700 Subject: [PATCH 4/5] Apply suggestion from @trask --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4411d89d9c04..3e067ebf13e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ ### ⚠️ Breaking changes -- In `opentelemetry-instrumentation-annotations` 3.0, `@WithSpan` and - `@AddingSpanAttributes` target methods only. +- `@WithSpan` and `@AddingSpanAttributes` no longer allow targeting constructors + (which didn't work properly anyways). - Kotlin suspend function `@WithSpan` instrumentation now uses only the `kotlinx-coroutines-annotations` selector and is disabled by default. Use `otel.instrumentation.kotlinx-coroutines-annotations.enabled=true` instead of the From 412c562df0c301146896f62cd627fd086619b42d Mon Sep 17 00:00:00 2001 From: Trask Stalnaker <218610+trask@users.noreply.github.com> Date: Wed, 21 Oct 2026 02:00:38 +0000 Subject: [PATCH 5/5] Regenerate annotation API compatibility report Record the method-only annotation targets in the generated API comparison so the build's committed-report check stays current. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../opentelemetry-instrumentation-annotations.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-annotations.txt b/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-annotations.txt index 394c0034b027..87b2c1b286af 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-annotations.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-annotations.txt @@ -1,2 +1,9 @@ Comparing source compatibility of opentelemetry-instrumentation-annotations-3.0.0-SNAPSHOT.jar against opentelemetry-instrumentation-annotations-2.32.0.jar -No changes. \ No newline at end of file +=== UNCHANGED ANNOTATION: PUBLIC ABSTRACT io.opentelemetry.instrumentation.annotations.AddingSpanAttributes (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + *** MODIFIED ANNOTATION: java.lang.annotation.Target + *** MODIFIED ELEMENT: value=java.lang.annotation.ElementType.METHOD (<- java.lang.annotation.ElementType.METHOD,java.lang.annotation.ElementType.CONSTRUCTOR) +=== UNCHANGED ANNOTATION: PUBLIC ABSTRACT io.opentelemetry.instrumentation.annotations.WithSpan (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + *** MODIFIED ANNOTATION: java.lang.annotation.Target + *** MODIFIED ELEMENT: value=java.lang.annotation.ElementType.METHOD (<- java.lang.annotation.ElementType.METHOD,java.lang.annotation.ElementType.CONSTRUCTOR)