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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### ⚠️ Breaking changes

- `@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
=== 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)
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
* <p>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.
* <p>This annotation can only be applied to methods. Constructor instrumentation is not supported.
*
* <p>Application developers can use this annotation to signal OpenTelemetry auto-instrumentation
* that attributes annotated with the {@link
Expand All @@ -34,6 +32,6 @@
* <p>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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
* This annotation marks that an execution of this method should result in a new {@link
* io.opentelemetry.api.trace.Span}.
*
* <p>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.
* <p>This annotation can only be applied to methods. Constructor instrumentation is not supported.
*
* <p>Application developers can use this annotation to signal OpenTelemetry auto-instrumentation
* that a new span should be created whenever the marked method is executed.
*
* <p>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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading