-
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
Merged
trask
merged 15 commits into
open-telemetry:main
from
jaydeluca:add-code-attributes-play-mvc
Jul 18, 2025
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b802d15
add code attributes to play mvc
jaydeluca 1546f93
Merge branch 'main' of github.com:jaydeluca/opentelemetry-java-instru…
jaydeluca 0450f64
make AdviceScope class consistent, update test and remove deprecated …
jaydeluca a6220e8
code review notes
jaydeluca f2315e3
finish moving logic into advicescope class
jaydeluca f7d1652
remove code attributes
jaydeluca ed566b9
no longer need actiondata
jaydeluca 760e04d
revert instrumenter changes, move advicescope into advice class
jaydeluca 091d26e
inline scope within advicescope
jaydeluca a24f019
fix nesting and cast
jaydeluca 4fe2bdd
migrate 2.6 too
jaydeluca 94ebe69
remove cast
jaydeluca cb48f8f
move updateSpan into future wrapper
jaydeluca 9324fbc
Merge branch 'main' into add-code-attributes-play-mvc
laurit e585f56
fix indy convertsion
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...java/io/opentelemetry/javaagent/instrumentation/play/v2_4/ActionCodeAttributesGetter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...aagent/src/main/java/io/opentelemetry/javaagent/instrumentation/play/v2_4/ActionData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...agent/src/main/java/io/opentelemetry/javaagent/instrumentation/play/v2_4/AdviceScope.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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; | ||
import javax.annotation.Nullable; | ||
import play.api.mvc.Action; | ||
import play.api.mvc.Result; | ||
import scala.concurrent.Future; | ||
|
||
/** Container used to carry state between enter and exit advices */ | ||
public final class AdviceScope { | ||
SylvainJuge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
private final ActionData actionData; | ||
private final Context context; | ||
private final Scope scope; | ||
|
||
public AdviceScope(Context context, Scope scope, ActionData actionData) { | ||
this.actionData = actionData; | ||
this.context = context; | ||
this.scope = scope; | ||
} | ||
|
||
public Context getContext() { | ||
jaydeluca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return context; | ||
} | ||
|
||
@Nullable | ||
public static AdviceScope start(Context parentContext, ActionData actionData) { | ||
jaydeluca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (!instrumenter().shouldStart(parentContext, actionData)) { | ||
return null; | ||
} | ||
|
||
Context context = instrumenter().start(parentContext, actionData); | ||
return new AdviceScope(context, context.makeCurrent(), actionData); | ||
} | ||
|
||
public void closeScope() { | ||
if (scope != null) { | ||
scope.close(); | ||
} | ||
} | ||
|
||
public void end(Throwable throwable, Future<Result> responseFuture, Action<?> thisAction) { | ||
closeScope(); | ||
|
||
if (throwable == null) { | ||
responseFuture.onComplete( | ||
jaydeluca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
new RequestCompleteCallback(getContext()), thisAction.executionContext()); | ||
} else { | ||
instrumenter().end(context, actionData, null, throwable); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.