-
Notifications
You must be signed in to change notification settings - Fork 346
Wire mergedTracerTags as a read-through parent at span build (level-split) (phase 1a) #11932
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
dougqh
wants to merge
1
commit into
dougqh/tagmap-read-through
Choose a base branch
from
dougqh/tagmap-read-through-consumer
base: dougqh/tagmap-read-through
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.
+227
−7
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
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
42 changes: 42 additions & 0 deletions
42
dd-trace-core/src/test/java/datadog/trace/core/WithTracerTagsVersionTest.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,42 @@ | ||
| package datadog.trace.core; | ||
|
|
||
| import static datadog.trace.api.config.TracerConfig.SPLIT_BY_TAGS; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import datadog.trace.api.Config; | ||
| import datadog.trace.api.TagMap; | ||
| import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
| import datadog.trace.test.junit.utils.config.WithConfig; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * {@code withTracerTags} keeps {@code version} OUT of the trace-level bundle so a per-span {@code | ||
| * removeTag(VERSION)} doesn't mint a read-through tombstone -- EXCEPT when {@code version} is a | ||
| * split-service tag, where the {@code TagInterceptor} must still see it to derive the service name | ||
| * (regression guard for the level-split consumer). | ||
| */ | ||
| class WithTracerTagsVersionTest extends DDCoreJavaSpecification { | ||
|
|
||
| private static TagMap tracerTagsWithVersion(Config config) { | ||
| TagMap userTags = TagMap.create(); | ||
| userTags.set(Tags.VERSION, "1.2.3"); | ||
| return CoreTracer.withTracerTags(userTags, config, null); | ||
| } | ||
|
|
||
| @Test | ||
| void versionStrippedFromBundleByDefault() { | ||
| assertNull( | ||
| tracerTagsWithVersion(Config.get()).getString(Tags.VERSION), | ||
| "version is kept out of the trace-level bundle by default (avoids per-span tombstone)"); | ||
| } | ||
|
|
||
| @Test | ||
| @WithConfig(key = SPLIT_BY_TAGS, value = "version") | ||
| void versionKeptInBundleWhenSplitByVersion() { | ||
| assertEquals( | ||
| "1.2.3", | ||
| tracerTagsWithVersion(Config.get()).getString(Tags.VERSION), | ||
| "version must stay in the bundle so split-by-tags can derive the service name"); | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
internal-api/src/jmh/java/datadog/trace/util/TagMapReadThroughBenchmark.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,84 @@ | ||
| package datadog.trace.util; | ||
|
|
||
| import datadog.trace.api.TagMap; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Threads; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
|
|
||
| /** | ||
| * Models span-build tag assembly with vs without read-through of the shared trace-level bundle. | ||
| * | ||
| * <ul> | ||
| * <li><b>copyDown</b> — today's path: {@code putAll} the (frozen) trace-level bundle into the | ||
| * fresh span map, then set the span-specific tags. {@code putAll}-into-empty shares the | ||
| * frozen entry references (bucket-clone), so this does NOT allocate new Entry objects for the | ||
| * trace tags — its cost is cloned {@code BucketGroup}s plus the collisions caused by the | ||
| * trace tags sharing the local buckets with the span tags. | ||
| * <li><b>readThrough</b> — attach the frozen bundle as a read-through parent; only the | ||
| * span-specific tags are stored locally. | ||
| * </ul> | ||
| * | ||
| * <p>Run with {@code -prof gc}; the B/op delta is the per-span allocation read-through saves. Both | ||
| * arms set the same span tags, so the delta isolates the trace-bundle handling. {@code | ||
| * traceTagCount} sweeps the bundle size — the win scales with it (more trace tags → more cloned | ||
| * BucketGroups and local collisions avoided). {@code traceTagCount = 7} ≈ a realistic | ||
| * mergedTracerTags (env, version, language, runtime-id, a propagation tag, a couple global tags). | ||
| */ | ||
| @State(Scope.Benchmark) | ||
| @BenchmarkMode(Mode.Throughput) | ||
| @OutputTimeUnit(TimeUnit.SECONDS) | ||
| @Warmup(iterations = 5, time = 2) | ||
| @Measurement(iterations = 5, time = 2) | ||
| @Fork(3) | ||
| @Threads(8) | ||
| public class TagMapReadThroughBenchmark { | ||
|
|
||
| @Param({"3", "7", "15"}) | ||
| int traceTagCount; | ||
|
|
||
| private TagMap traceTags; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void setup() { | ||
| TagMap m = TagMap.create(Math.max(16, traceTagCount * 2)); | ||
| for (int i = 0; i < traceTagCount; i++) { | ||
| m.set("_dd.trace.tag." + i, "trace-value-" + i); | ||
| } | ||
| this.traceTags = m.freeze(); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public TagMap copyDown() { | ||
| TagMap m = TagMap.create(16); | ||
| m.putAll(traceTags); // putAll-into-empty: shares frozen entries, clones BucketGroups | ||
| setSpanTags(m); | ||
| return m; | ||
| } | ||
|
|
||
| @Benchmark | ||
| public TagMap readThrough() { | ||
| // no copy; trace tags read through the shared frozen parent (fixed at construction) | ||
| TagMap m = TagMap.createFromParent(traceTags); | ||
| setSpanTags(m); | ||
| return m; | ||
| } | ||
|
|
||
| private static void setSpanTags(TagMap m) { | ||
| m.set("http.method", "GET"); | ||
| m.set("http.url", "/api/checkout/cart"); | ||
| m.set("component", "spring-web-controller"); | ||
| m.set("span.kind", "server"); | ||
| m.set("http.status_code", 200); | ||
| } | ||
| } |
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.