-
Notifications
You must be signed in to change notification settings - Fork 333
Add baggage propagation telemetry #9289
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 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d243b6b
WIP: adding baggage propagation telemetry
rachelyangdog 74ae2af
suggestion of adding baggageMetrics as constant
rachelyangdog e112052
Merge branch 'master' into rachel.yang/baggage-telemetry
rachelyangdog 3e8108e
Merge branch 'master' into rachel.yang/baggage-telemetry
rachelyangdog 371565d
adding tests
rachelyangdog 1fa4baa
adding line at end of file
rachelyangdog 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
105 changes: 105 additions & 0 deletions
105
internal-api/src/main/java/datadog/trace/api/metrics/BaggageMetrics.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,105 @@ | ||
| package datadog.trace.api.metrics; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| /** Metrics for baggage propagation operations. */ | ||
| public class BaggageMetrics { | ||
| private static final BaggageMetrics INSTANCE = new BaggageMetrics(); | ||
| private final AtomicLong extractedCounter = new AtomicLong(0); | ||
| private final AtomicLong injectedCounter = new AtomicLong(0); | ||
| private final AtomicLong malformedCounter = new AtomicLong(0); | ||
| private final AtomicLong truncatedByteCounter = new AtomicLong(0); | ||
| private final AtomicLong truncatedItemCounter = new AtomicLong(0); | ||
| private final Collection<TaggedCounter> taggedCounters; | ||
|
|
||
| public static BaggageMetrics getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| private BaggageMetrics() { | ||
| List<TaggedCounter> counters = new ArrayList<>(5); | ||
| counters.add( | ||
| new TaggedCounter( | ||
| "context_header_style.extracted", this.extractedCounter, "header_style:baggage")); | ||
| counters.add( | ||
| new TaggedCounter( | ||
| "context_header_style.injected", this.injectedCounter, "header_style:baggage")); | ||
| counters.add( | ||
| new TaggedCounter( | ||
| "context_header_style.malformed", this.malformedCounter, "header_style:baggage")); | ||
| counters.add( | ||
| new TaggedCounter( | ||
| "context_header_style.truncated", | ||
| this.truncatedByteCounter, | ||
| "truncation_reason:baggage_byte_count_exceeded")); | ||
| counters.add( | ||
| new TaggedCounter( | ||
| "context_header_style.truncated", | ||
| this.truncatedItemCounter, | ||
| "truncation_reason:baggage_item_count_exceeded")); | ||
| this.taggedCounters = Collections.unmodifiableList(counters); | ||
| } | ||
|
|
||
| public void onBaggageExtracted() { | ||
| this.extractedCounter.incrementAndGet(); | ||
| } | ||
|
|
||
| public void onBaggageInjected() { | ||
| this.injectedCounter.incrementAndGet(); | ||
| } | ||
|
|
||
| public void onBaggageMalformed() { | ||
| this.malformedCounter.incrementAndGet(); | ||
| } | ||
|
|
||
| public void onBaggageTruncatedByByteLimit() { | ||
| this.truncatedByteCounter.incrementAndGet(); | ||
| } | ||
|
|
||
| public void onBaggageTruncatedByItemLimit() { | ||
| this.truncatedItemCounter.incrementAndGet(); | ||
| } | ||
|
|
||
| public Collection<TaggedCounter> getTaggedCounters() { | ||
| return this.taggedCounters; | ||
| } | ||
|
|
||
| public static class TaggedCounter implements CoreCounter { | ||
| private final String name; | ||
| private final AtomicLong counter; | ||
| private final String tag; | ||
| private long previousCount; | ||
|
|
||
| public TaggedCounter(String name, AtomicLong counter, String tag) { | ||
| this.name = name; | ||
| this.counter = counter; | ||
| this.tag = tag; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return this.name; | ||
| } | ||
|
|
||
| public String getTag() { | ||
| return this.tag; | ||
| } | ||
|
|
||
| @Override | ||
| public long getValue() { | ||
| return counter.get(); | ||
| } | ||
|
|
||
| @Override | ||
| public long getValueAndReset() { | ||
| long count = counter.get(); | ||
| long delta = count - previousCount; | ||
| previousCount = count; | ||
| return delta; | ||
| } | ||
| } | ||
| } |
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.
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.