-
Notifications
You must be signed in to change notification settings - Fork 311
Migrate context extraction calls to context-first APIs #8368
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0f3da32
feat(core): Remove core propagation injection API
PerfectSlayer 8a67813
feat(context): Improve composite propagator order
PerfectSlayer 3f491cb
chore(api): Simplify span link test
PerfectSlayer 9f13521
feat(core): Move DSM extractor to its own propagator
PerfectSlayer 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
83 changes: 83 additions & 0 deletions
83
dd-trace-core/src/main/java/datadog/trace/core/datastreams/DataStreamPropagator.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,83 @@ | ||
package datadog.trace.core.datastreams; | ||
|
||
import datadog.context.Context; | ||
import datadog.context.propagation.CarrierSetter; | ||
import datadog.context.propagation.CarrierVisitor; | ||
import datadog.context.propagation.Propagator; | ||
import datadog.trace.api.TraceConfig; | ||
import datadog.trace.api.time.TimeSource; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext; | ||
import datadog.trace.bootstrap.instrumentation.api.PathwayContext; | ||
import datadog.trace.bootstrap.instrumentation.api.TagContext; | ||
import java.util.function.Supplier; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
// TODO Javadoc | ||
@ParametersAreNonnullByDefault | ||
public class DataStreamPropagator implements Propagator { | ||
private final Supplier<TraceConfig> traceConfigSupplier; | ||
private final TimeSource timeSource; | ||
private final long hashOfKnownTags; | ||
private final String serviceNameOverride; | ||
|
||
public DataStreamPropagator( | ||
Supplier<TraceConfig> traceConfigSupplier, | ||
TimeSource timeSource, | ||
long hashOfKnownTags, | ||
String serviceNameOverride) { | ||
this.traceConfigSupplier = traceConfigSupplier; | ||
this.timeSource = timeSource; | ||
this.hashOfKnownTags = hashOfKnownTags; | ||
this.serviceNameOverride = serviceNameOverride; | ||
} | ||
|
||
@Override | ||
public <C> void inject(Context context, C carrier, CarrierSetter<C> setter) { | ||
// TODO Still in CorePropagation, not migrated yet | ||
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. Similarly, this will be completed in the next PR |
||
} | ||
|
||
@Override | ||
public <C> Context extract(Context context, C carrier, CarrierVisitor<C> visitor) { | ||
// TODO Pathway context needs to be stored into its own context element | ||
// Get span context to store pathway context into | ||
TagContext spanContext = getSpanContextOrNull(context); | ||
PathwayContext pathwayContext; | ||
// Ensure if DSM is enabled and look for pathway context | ||
if (isDsmEnabled(spanContext) | ||
&& (pathwayContext = extractDsmPathwayContext(carrier, visitor)) != null) { | ||
// Store pathway context into span context | ||
if (spanContext == null) { | ||
spanContext = new TagContext(); | ||
AgentSpan span = AgentSpan.fromSpanContext(spanContext); | ||
context = Context.root().with(span); | ||
} | ||
spanContext.withPathwayContext(pathwayContext); | ||
} | ||
return context; | ||
} | ||
|
||
private TagContext getSpanContextOrNull(Context context) { | ||
AgentSpan extractedSpan = AgentSpan.fromContext(context); | ||
AgentSpanContext extractedSpanContext; | ||
if (extractedSpan != null | ||
&& (extractedSpanContext = extractedSpan.context()) instanceof TagContext) { | ||
return (TagContext) extractedSpanContext; | ||
} | ||
return null; | ||
} | ||
|
||
private boolean isDsmEnabled(@Nullable TagContext tagContext) { | ||
TraceConfig traceConfig = tagContext == null ? null : tagContext.getTraceConfig(); | ||
if (traceConfig == null) { | ||
traceConfig = this.traceConfigSupplier.get(); | ||
} | ||
return traceConfig.isDataStreamsEnabled(); | ||
} | ||
|
||
private <C> PathwayContext extractDsmPathwayContext(C carrier, CarrierVisitor<C> visitor) { | ||
return DefaultPathwayContext.extract( | ||
carrier, visitor, this.timeSource, this.hashOfKnownTags, this.serviceNameOverride); | ||
} | ||
} |
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
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.
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 will be documented as part of the next PR, which will be dedicated to DSM migration.