Repository navigation
Export propagation tags in OTLP trace export #12985
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
Open
anna-git
wants to merge
9
commits into
master
Choose a base branch
from
anna.yafi/otlp-export-propagation-tags
base: master
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.
+672
−50
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8969456
Export propagation tags as OTLP span attributes
anna-git 900a307
Don't export _dd.p.tid as an OTLP attribute
anna-git 6dce281
Keep the _dd.p.tid key local to the OTLP writers
anna-git a0096d2
Don't let baggage duplicate directly emitted OTLP attributes
anna-git 6d518d3
Share the OTLP span attribute keys between the trace writers
anna-git ee1fa5b
Export propagation tags on partial flushes without the local root
anna-git 6dfd8ee
Don't let baggage duplicate direction-dependent OTLP attribute names
anna-git 7212905
Skip baggage only when a span tag is exported under the same OTLP key
anna-git 359e585
Keep the alias TableTest rows on one line for spotless
anna-git 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
94 changes: 94 additions & 0 deletions
94
dd-trace-core/src/main/java/datadog/trace/core/otlp/trace/OtlpTraceAttributes.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,94 @@ | ||
| package datadog.trace.core.otlp.trace; | ||
|
|
||
| import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.DD_MEASURED; | ||
| import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.DD_PARTIAL_VERSION; | ||
| import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.DD_TOP_LEVEL; | ||
| import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.DD_WAS_LONG_RUNNING; | ||
| import static datadog.trace.common.writer.ddagent.TraceMapper.ORIGIN_KEY; | ||
| import static datadog.trace.common.writer.ddagent.TraceMapper.PROCESS_TAGS_KEY; | ||
| import static datadog.trace.common.writer.ddagent.TraceMapper.SAMPLING_PRIORITY_KEY; | ||
| import static datadog.trace.common.writer.ddagent.TraceMapper.THREAD_ID; | ||
| import static datadog.trace.common.writer.ddagent.TraceMapper.THREAD_NAME; | ||
|
|
||
| import datadog.trace.api.KnownTagCodec; | ||
| import datadog.trace.api.KnownTags; | ||
| import datadog.trace.api.TagMap; | ||
| import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString; | ||
| import java.util.Arrays; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** Span attribute keys shared by the OTLP protobuf and JSON trace writers. */ | ||
| final class OtlpTraceAttributes { | ||
|
|
||
| static final UTF8BytesString RESOURCE_NAME = UTF8BytesString.create("resource.name"); | ||
| static final UTF8BytesString OPERATION_NAME = UTF8BytesString.create("operation.name"); | ||
| static final UTF8BytesString SPAN_TYPE = UTF8BytesString.create("span.type"); | ||
|
|
||
| /* | ||
| * Span fields and intercepted Metadata fields bypass TagMap entry projection. Resolve their | ||
| * keys through the registry here so OpenTelemetry names stay consistent with entry tags. | ||
| */ | ||
| static final UTF8BytesString SERVICE_NAME_KEY = otelKey(KnownTags.SERVICE_ID); | ||
|
|
||
| static final UTF8BytesString HTTP_STATUS_CODE_KEY = otelKey(KnownTags.HTTP_STATUS_CODE_ID); | ||
|
|
||
| static final UTF8BytesString HTTP_STATUS_CODE_KEY_DD = | ||
| UTF8BytesString.create(KnownTags.HTTP_STATUS_CODE_NAME); | ||
|
|
||
| /** | ||
| * Keys that baggage must not export as attributes: the attributes the writers emit directly from | ||
| * span fields and intercepted Metadata fields (the span's own value wins), plus _dd.p.tid, whose | ||
| * upper 64 bits the OTLP traceId already carries. | ||
| */ | ||
| static final Set<String> SKIPPED_BAGGAGE_KEYS = | ||
| new HashSet<>( | ||
| Arrays.asList( | ||
| "_dd.p.tid", | ||
| SERVICE_NAME_KEY.toString(), | ||
| RESOURCE_NAME.toString(), | ||
| OPERATION_NAME.toString(), | ||
| SPAN_TYPE.toString(), | ||
| SAMPLING_PRIORITY_KEY.toString(), | ||
| DD_MEASURED.toString(), | ||
| DD_TOP_LEVEL.toString(), | ||
| DD_PARTIAL_VERSION.toString(), | ||
| DD_WAS_LONG_RUNNING.toString(), | ||
| THREAD_ID.toString(), | ||
| THREAD_NAME.toString(), | ||
| HTTP_STATUS_CODE_KEY.toString(), | ||
| HTTP_STATUS_CODE_KEY_DD.toString(), | ||
| ORIGIN_KEY.toString(), | ||
| PROCESS_TAGS_KEY.toString())); | ||
|
|
||
| /** | ||
| * True if a span tag is exported under exactly {@code key}, so baggage under that key would | ||
| * duplicate it. TagMap lookups resolve aliases (http.request.method finds http.method), so the | ||
| * matching entry's exported name is compared with the key: it depends on OTel semantics and, for | ||
| * direction-scoped tags, on the span's direction (peer.port is server.port on a client). | ||
| */ | ||
| static boolean isExportedTagKey(TagMap tags, String key, int direction, boolean otelSemantics) { | ||
| if (exportsAs(tags.getEntry(key), key, direction, otelSemantics)) { | ||
| return true; | ||
| } | ||
| if (otelSemantics) { | ||
| long directionalTagId = KnownTagCodec.directionalKeyOf(key, direction); | ||
| return directionalTagId != 0 | ||
| && exportsAs(tags.getEntry(directionalTagId), key, direction, true); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean exportsAs( | ||
| TagMap.Entry entry, String key, int direction, boolean otelSemantics) { | ||
| return entry != null | ||
| && key.equals(otelSemantics ? entry.openTelemetryTag(direction) : entry.tag()); | ||
| } | ||
|
|
||
| /** The OpenTelemetry-namespace key for a known tag, as named by the registry. */ | ||
| private static UTF8BytesString otelKey(long tagId) { | ||
| return UTF8BytesString.create(KnownTagCodec.openTelemetryTagOf(tagId)); | ||
| } | ||
|
|
||
| private OtlpTraceAttributes() {} | ||
| } | ||
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.
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.
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.
nit:
OtlpSpanAttributessince this holds span attributes?