-
Notifications
You must be signed in to change notification settings - Fork 892
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
Add code attributes to play mvc controller spans #13140
Open
jaydeluca
wants to merge
1
commit into
open-telemetry:main
Choose a base branch
from
jaydeluca:add-code-attributes-play-mvc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions
23
...java/io/opentelemetry/javaagent/instrumentation/play/v2_4/ActionCodeAttributesGetter.java
This file contains 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 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 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
53 changes: 53 additions & 0 deletions
53
...agent/src/main/java/io/opentelemetry/javaagent/instrumentation/play/v2_4/ActionScope.java
This file contains 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,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 { | ||
|
||
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); | ||
} | ||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this is not useful. It points to framework code and is the same for all endpoints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree with Lauri here, if the value is the same for all spans then it does not provide much value for the end-user as with it they can't guess which part of the application code is related to the span.
We will very likely have exactly the same kind of issues with Webflux or other reactive frameworks where the application code is provided through nested lambdas and can't be described with a dedicated class/method. For those cases, the "span identity" should be provided through other attributes for example HTTP verb, path or span name which allows the end-user to understand the link with application code.
If we capture this technical and implementation-specific information, do we have a way to make any good use of it ?
One example I could think of is if we attempt to correlate those attributes with another source of information like inferred spans or profiling, however for those the correlation would be implemented through trace and span ID rather than on those code-level attributes.
I think this example is really interesting from the perspective of semconv attributes clarification as there are at least two distinct use-cases for those attributes: