Skip to content

Commit 740e692

Browse files
otelbot[bot]trask
andauthored
Code review sweep (run 25215835467) (open-telemetry#18484)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 87ec23c commit 740e692

6 files changed

Lines changed: 27 additions & 16 deletions

File tree

instrumentation/opentelemetry-api/opentelemetry-api-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/v1_4/trace/ApplicationTracerBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ApplicationTracerBuilder implements application.io.opentelemetry.api.trace
1414
private final ApplicationTracerFactory tracerFactory;
1515
private final TracerBuilder agentTracerBuilder;
1616

17-
public ApplicationTracerBuilder(
17+
ApplicationTracerBuilder(
1818
ApplicationTracerFactory tracerFactory, TracerBuilder agentTracerBuilder) {
1919
this.tracerFactory = tracerFactory;
2020
this.agentTracerBuilder = agentTracerBuilder;

instrumentation/opentelemetry-api/opentelemetry-api-1.56/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/v1_56/incubator/OpenTelemetryIncubatorInstrumentation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ public void transform(TypeTransformer transformer) {
2626
transformer.applyAdviceToMethod(none(), getClass().getName() + "$InitAdvice");
2727
}
2828

29-
@SuppressWarnings({"ReturnValueIgnored", "unused"})
29+
@SuppressWarnings("unused")
3030
public static class InitAdvice {
3131
@Advice.OnMethodEnter(inline = false)
32+
@SuppressWarnings("ReturnValueIgnored")
3233
public static void init() {
3334
// the sole purpose of this advice is to ensure that the class is
3435
// recognized as a helper class and injected into the class loader

instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/v1_0/WithSpanInstrumentation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public static WithSpanAdviceScope start(Method method) {
138138
return new WithSpanAdviceScope(method, context, context.makeCurrent());
139139
}
140140

141+
@Nullable
141142
public Object end(@Nullable Object returnValue, @Nullable Throwable throwable) {
142143
scope.close();
143144
AsyncOperationEndSupport<Method, Object> operationEndSupport =
@@ -156,8 +157,9 @@ public static WithSpanAdviceScope onEnter(@Advice.Origin Method originMethod) {
156157

157158
@AssignReturned.ToReturned
158159
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
160+
@Nullable
159161
public static Object stopSpan(
160-
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object returnValue,
162+
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object returnValue,
161163
@Advice.Thrown @Nullable Throwable throwable,
162164
@Advice.Enter @Nullable WithSpanAdviceScope adviceScope) {
163165
if (adviceScope != null) {
@@ -195,6 +197,7 @@ public static WithSpanAttributesAdviceScope start(Method method, Object[] args)
195197
return new WithSpanAttributesAdviceScope(method, request, context, context.makeCurrent());
196198
}
197199

200+
@Nullable
198201
public Object end(@Nullable Object returnValue, @Nullable Throwable throwable) {
199202
scope.close();
200203
AsyncOperationEndSupport<MethodRequest, Object> operationEndSupport =
@@ -216,6 +219,7 @@ public static WithSpanAttributesAdviceScope onEnter(
216219

217220
@AssignReturned.ToReturned
218221
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
222+
@Nullable
219223
public static Object stopSpan(
220224
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object returnValue,
221225
@Advice.Thrown @Nullable Throwable throwable,

instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/v1_16/WithSpanInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class WithSpanInstrumentation implements TypeInstrumentation {
4848
isAnnotatedWith(
4949
named(
5050
"application.io.opentelemetry.instrumentation.annotations.SpanAttribute"))));
51-
// exclude all kotlin suspend methods, these are handle in kotlinx-coroutines instrumentation
51+
// exclude all kotlin suspend methods, these are handled in kotlinx-coroutines instrumentation
5252
excludedMethodsMatcher =
5353
AnnotationExcludedMethods.configureExcludedMethods().or(isKotlinSuspendMethod());
5454
}
@@ -122,7 +122,7 @@ public static WithSpanAdviceScope onEnter(@Advice.Origin Method originMethod) {
122122
@AssignReturned.ToReturned
123123
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
124124
public static Object stopSpan(
125-
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object returnValue,
125+
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object returnValue,
126126
@Advice.Thrown @Nullable Throwable throwable,
127127
@Advice.Enter @Nullable WithSpanAdviceScope adviceScope) {
128128
if (adviceScope != null) {

instrumentation/opentelemetry-instrumentation-api/javaagent/src/testOldServerSpan/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/LegacyServerSpanContextBridgeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void shouldBridgeLegacyServerSpanClass() {
2727
AgentSpanTesting.runWithHttpServerSpan(
2828
"server",
2929
() -> {
30-
assertThat(Span.current()).isNotNull();
30+
assertThat(Span.fromContextOrNull(Context.current())).isNotNull();
3131
assertThat(ServerSpan.fromContextOrNull(Context.current())).isNotNull();
3232

3333
Span internalSpan = tracer.spanBuilder("internal").startSpan();

instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumentation.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ public void transform(TypeTransformer transformer) {
3131
named("runWithAllSpanKeys"), getClass().getName() + "$RunWithAllSpanKeysAdvice");
3232
}
3333

34-
private static class AdviceScope {
34+
public static class AdviceScope {
3535
private final Context context;
3636
private final Scope scope;
3737

38-
private AdviceScope(Context context, Scope scope) {
38+
public AdviceScope(Context context, Scope scope) {
3939
this.context = context;
4040
this.scope = scope;
4141
}
4242

43-
private Context getContext() {
43+
public Context getContext() {
4444
return context;
4545
}
4646

47-
private void end() {
47+
public void end() {
4848
scope.close();
4949
}
5050
}
@@ -60,9 +60,12 @@ public static AdviceScope onEnter(@Advice.Argument(0) String spanName) {
6060

6161
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
6262
public static void onExit(
63-
@Advice.Thrown @Nullable Throwable throwable, @Advice.Enter AdviceScope adviceScope) {
64-
adviceScope.end();
65-
AgentSpanTestingInstrumenter.endHttpServer(adviceScope.getContext(), throwable);
63+
@Advice.Thrown @Nullable Throwable throwable,
64+
@Advice.Enter @Nullable AdviceScope adviceScope) {
65+
if (adviceScope != null) {
66+
adviceScope.end();
67+
AgentSpanTestingInstrumenter.endHttpServer(adviceScope.getContext(), throwable);
68+
}
6669
}
6770
}
6871

@@ -77,9 +80,12 @@ public static AdviceScope onEnter(@Advice.Argument(0) String spanName) {
7780

7881
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
7982
public static void onExit(
80-
@Advice.Thrown @Nullable Throwable throwable, @Advice.Enter AdviceScope adviceScope) {
81-
adviceScope.end();
82-
AgentSpanTestingInstrumenter.end(adviceScope.getContext(), throwable);
83+
@Advice.Thrown @Nullable Throwable throwable,
84+
@Advice.Enter @Nullable AdviceScope adviceScope) {
85+
if (adviceScope != null) {
86+
adviceScope.end();
87+
AgentSpanTestingInstrumenter.end(adviceScope.getContext(), throwable);
88+
}
8389
}
8490
}
8591
}

0 commit comments

Comments
 (0)