-
Notifications
You must be signed in to change notification settings - Fork 1k
Update play mvc to use AdviceScope #13140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b802d15
1546f93
0450f64
a6220e8
f2315e3
f7d1652
ed566b9
760e04d
091d26e
a24f019
4fe2bdd
94ebe69
cb48f8f
9324fbc
e585f56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.play.v2_4; | ||
|
||
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter; | ||
import javax.annotation.Nullable; | ||
|
||
public class ActionCodeAttributesGetter implements CodeAttributesGetter<ActionData> { | ||
@Nullable | ||
@Override | ||
public Class<?> getCodeClass(ActionData actionData) { | ||
return actionData.codeClass(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getMethodName(ActionData actionData) { | ||
return actionData.methodName(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.play.v2_4; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
public class ActionData { | ||
private final Class<?> target; | ||
private final Method method; | ||
|
||
public ActionData(Class<?> target, Method method) { | ||
this.target = target; | ||
this.method = method; | ||
} | ||
|
||
public Class<?> codeClass() { | ||
return target; | ||
} | ||
|
||
public String methodName() { | ||
return method.getName(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.play.v2_4; | ||
|
||
import static io.opentelemetry.javaagent.instrumentation.play.v2_4.Play24Singletons.instrumenter; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
|
||
/** Container used to carry state between enter and exit advices */ | ||
public final class ActionScope { | ||
jaydeluca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
private final ActionData actionData; | ||
private final Context context; | ||
private final Scope scope; | ||
|
||
public ActionScope(Context context, Scope scope, ActionData actionData) { | ||
this.actionData = actionData; | ||
this.context = context; | ||
this.scope = scope; | ||
} | ||
|
||
public Context getContext() { | ||
return context; | ||
} | ||
|
||
public Scope getScope() { | ||
return scope; | ||
} | ||
|
||
public static ActionScope start(Context parentContext, ActionData actionData) { | ||
if (!instrumenter().shouldStart(parentContext, actionData)) { | ||
return null; | ||
} | ||
|
||
Context context = instrumenter().start(parentContext, actionData); | ||
return new ActionScope(context, context.makeCurrent(), actionData); | ||
} | ||
|
||
public void closeScope() { | ||
if (scope != null) { | ||
scope.close(); | ||
} | ||
} | ||
|
||
public void end(Throwable throwable) { | ||
closeScope(); | ||
instrumenter().end(context, actionData, null, throwable); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,10 @@ | |
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | ||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
import static io.opentelemetry.semconv.HttpAttributes.HTTP_ROUTE; | ||
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION; | ||
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
|
@@ -112,9 +115,15 @@ protected void configure(HttpServerTestOptions options) { | |
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") // uses deprecated semconv | ||
public SpanDataAssert assertHandlerSpan( | ||
SpanDataAssert span, String method, ServerEndpoint endpoint) { | ||
span.hasName("play.request").hasKind(INTERNAL); | ||
span.hasName("play.request") | ||
.hasKind(INTERNAL) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(CODE_NAMESPACE, "play.api.mvc.ActionBuilder$$anon$2"), | ||
equalTo(CODE_FUNCTION, "apply")); | ||
|
||
|
||
if (endpoint == EXCEPTION) { | ||
span.hasStatus(StatusData.error()); | ||
span.hasException(new IllegalArgumentException(EXCEPTION.getBody())); | ||
|
Uh oh!
There was an error while loading. Please reload this page.