-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add RPC semantic convention stable opt-in support #15932
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
Draft
zeitlinger
wants to merge
17
commits into
open-telemetry:main
Choose a base branch
from
zeitlinger:rpc-api-incubator
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.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8dc1398
Add RPC semantic convention stable opt-in support
zeitlinger e141120
check for well-known method
zeitlinger ca84944
deprecate getMethod
zeitlinger 1c26011
rename
zeitlinger 58ba056
fix
zeitlinger 68a1522
update descriptions
zeitlinger 7dff3a2
pr review
zeitlinger d3512c9
rename to old
zeitlinger 1a1cdba
pr review
zeitlinger ef9440e
add getErrorType
zeitlinger 5d51fbb
add getErrorType
zeitlinger 25fd8e6
system fallback for span name
zeitlinger 0a09fd5
system fallback for span name
zeitlinger 7690d20
add getErrorType
zeitlinger 735b2e5
Merge branch 'main' into rpc-api-incubator
zeitlinger 345ab82
Merge branch 'main' into rpc-api-incubator
zeitlinger 8213ba4
Use ContextCustomizer to pass old rpc.method to metrics in dup mode
zeitlinger 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,32 +6,84 @@ | |
| package io.opentelemetry.instrumentation.api.incubator.semconv.rpc; | ||
|
|
||
| import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; | ||
| import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.AttributesBuilder; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.ContextKey; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; | ||
| import io.opentelemetry.instrumentation.api.internal.SemconvStability; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| abstract class RpcCommonAttributesExtractor<REQUEST, RESPONSE> | ||
| public abstract class RpcCommonAttributesExtractor<REQUEST, RESPONSE> | ||
| implements AttributesExtractor<REQUEST, RESPONSE> { | ||
|
|
||
| // copied from RpcIncubatingAttributes | ||
| static final AttributeKey<String> RPC_METHOD = AttributeKey.stringKey("rpc.method"); | ||
|
|
||
| static final ContextKey<String> OLD_RPC_METHOD_CONTEXT_KEY = | ||
| ContextKey.named("otel-rpc-old-method"); | ||
|
|
||
| @SuppressWarnings("deprecation") // for getMethod() | ||
| public static <REQUEST> ContextCustomizer<REQUEST> oldMethodContextCustomizer( | ||
| RpcAttributesGetter<REQUEST, ?> getter) { | ||
| return (context, request, startAttributes) -> { | ||
| if (SemconvStability.emitOldRpcSemconv() && SemconvStability.emitStableRpcSemconv()) { | ||
| String oldMethod = getter.getMethod(request); | ||
| if (oldMethod != null) { | ||
| return context.with(OLD_RPC_METHOD_CONTEXT_KEY, oldMethod); | ||
| } | ||
| } | ||
| return context; | ||
| }; | ||
| } | ||
|
|
||
| // Stable semconv keys | ||
| static final AttributeKey<String> RPC_SYSTEM_NAME = AttributeKey.stringKey("rpc.system.name"); | ||
|
|
||
| // removed in stable semconv (merged into rpc.method) | ||
| static final AttributeKey<String> RPC_SERVICE = AttributeKey.stringKey("rpc.service"); | ||
|
|
||
| // use RPC_SYSTEM_NAME for stable semconv | ||
| static final AttributeKey<String> RPC_SYSTEM = AttributeKey.stringKey("rpc.system"); | ||
|
|
||
| private final RpcAttributesGetter<REQUEST> getter; | ||
| static final AttributeKey<String> RPC_METHOD_ORIGINAL = | ||
| AttributeKey.stringKey("rpc.method_original"); | ||
|
|
||
| private final RpcAttributesGetter<REQUEST, RESPONSE> getter; | ||
|
|
||
| RpcCommonAttributesExtractor(RpcAttributesGetter<REQUEST> getter) { | ||
| RpcCommonAttributesExtractor(RpcAttributesGetter<REQUEST, RESPONSE> getter) { | ||
| this.getter = getter; | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") // for getMethod() | ||
| @Override | ||
| public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { | ||
| internalSet(attributes, RPC_SYSTEM, getter.getSystem(request)); | ||
| internalSet(attributes, RPC_SERVICE, getter.getService(request)); | ||
| internalSet(attributes, RPC_METHOD, getter.getMethod(request)); | ||
| String system = getter.getSystem(request); | ||
|
|
||
| if (SemconvStability.emitStableRpcSemconv()) { | ||
| internalSet( | ||
| attributes, | ||
| RPC_SYSTEM_NAME, | ||
| system == null ? null : SemconvStability.stableRpcSystemName(system)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it would be better to handle
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the param would need to be nullable - which I'd like to avoid |
||
| String method = getter.getRpcMethod(request); | ||
| if (getter.isPredefined(request)) { | ||
| internalSet(attributes, RPC_METHOD, method); | ||
| } else { | ||
| internalSet(attributes, RPC_METHOD_ORIGINAL, method); | ||
| internalSet(attributes, RPC_METHOD, "_OTHER"); | ||
| } | ||
| } | ||
|
|
||
| if (SemconvStability.emitOldRpcSemconv()) { | ||
| internalSet(attributes, RPC_SYSTEM, system); | ||
| internalSet(attributes, RPC_SERVICE, getter.getService(request)); | ||
| if (!SemconvStability.emitStableRpcSemconv()) { | ||
| // only set old rpc.method on spans when there's no clash with stable rpc.method | ||
| internalSet(attributes, RPC_METHOD, getter.getMethod(request)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -41,6 +93,13 @@ public final void onEnd( | |
| REQUEST request, | ||
| @Nullable RESPONSE response, | ||
| @Nullable Throwable error) { | ||
| // No response attributes | ||
| if (SemconvStability.emitStableRpcSemconv()) { | ||
| String errorType = getter.getErrorType(request, response, error); | ||
| // fall back to exception class name & _OTHER | ||
| if (errorType == null && error != null) { | ||
| errorType = error.getClass().getName(); | ||
| } | ||
| internalSet(attributes, ERROR_TYPE, errorType); | ||
| } | ||
| } | ||
| } | ||
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.
by default fields are initialized to
null, is there anything to gain from explicitly assigning thenullhere?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.
this allows the field to be final