-
Notifications
You must be signed in to change notification settings - Fork 881
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 dropwizard views #12984
Closed
jaydeluca
wants to merge
1
commit into
open-telemetry:main
from
jaydeluca:dropwizard-code-attributes
Closed
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
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
25 changes: 25 additions & 0 deletions
25
.../io/opentelemetry/javaagent/instrumentation/dropwizardviews/ViewCodeAttributesGetter.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,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.dropwizardviews; | ||
|
||
import io.dropwizard.views.View; | ||
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter; | ||
import javax.annotation.Nullable; | ||
|
||
public class ViewCodeAttributesGetter implements CodeAttributesGetter<View> { | ||
|
||
@Nullable | ||
@Override | ||
public Class<?> getCodeClass(View view) { | ||
return view.getClass(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getMethodName(View view) { | ||
return "render"; | ||
} | ||
} |
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
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.
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'm not sure this is appropriate. While the language in https://opentelemetry.io/docs/specs/semconv/general/attributes/#source-code-attributes does not explicitly disallow such usage in my opinion it still suggests that code attributes should correspond to actual code that was executed for the given span. Since the
render
method does't exist in the view class with given usage these attributes do not represent actual code.render
method exists in theViewRenderer
class and this is where the span is created, but the question is would the code attribute be useful there? Would knowing whether view was rendered byMustacheViewRenderer
orFreemarkerViewRenderer
be helpful?To proceed with this PR in its current for a confirmation is needed that such usage is allowed by the semantic conventions. cc @trask
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 think that's a good point to add for clarification in open-telemetry/semantic-conventions#1677. In this context it seems to me that the view class (which is put in
code.namespace
) is enough for the end-user to identify what is being executed in this view, without needing to introduce an artificial value forcode.function
.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.
Although the definition of
code.namespace
usescode.function
in https://github.com/open-telemetry/semantic-conventions/blob/f0db7751ab3facf2bd1261bb24748fbdb7931c20/docs/attributes-registry/code.md?plain=1#L19 which sort of implies that the when namespace is set function should also be set I think leaving outcode.function
is fine. My concern is that https://opentelemetry.io/docs/specs/semconv/general/attributes/#source-code-attributes statesThe
View
class is not really responsible for creating the span, it isViewRenderer.render
instead. The view just provides inputs like template name and charset to the renderer. Since the view class is only loosely related to the span my concern is whether using it in thecode.namespace
attribute is appropriate.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 think that making the
code.namespace
andcode.function
definitions avoid referring to each-other could help remove the implicit dependency here:code.namespace
could be used to indicate a class name, for example here with the view classcode.function
could be used even whencode.namespace
is not set, which is already the case when a global function is used.On the fact that the
View
class here is not really responsible for creating the span, I don't have any strong opinion, do you have ideas how we could better store this information ? For example, if we had anmvc.view
ortemplate.name
in semantic conventions would that be a better choice than those code-related semconv attributes ?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.
@laurit good points
I think I'd prefer to stay conservative at this point until we have more semconv guidance, and stick to using
code.function
on spans which represent the execution of that function.yeah, this makes sense to me, since view names don't always correspond to classes / functions
@jaydeluca I've updated #7345 for now to exclude view spans (thanks for sending this though, I hadn't thought about these issues!)