-
Notifications
You must be signed in to change notification settings - Fork 330
Introduce shared OtelMetricRegistry to track metrics by instrumentation scope
#10854
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
gh-worker-dd-mergequeue-cf854d
merged 9 commits into
master
from
mcculls/otel-metric-registry
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4fe90d3
Reuse OtelInstrumentationScope
mcculls 066d459
Reuse OtelInstrumentBuilder/Descriptor/Type
mcculls 0d8ccd1
Refactor OtelMetricStorage so the same instance can aggregate metrics
mcculls 5c9c0b0
Reuse OtelMetricStorage
mcculls 6ee53ad
Reuse OtelInstrument
mcculls fbed4e4
Introduce shared OtelMetricRegistry to track metrics by instrumentati…
mcculls 2496111
Let muzzle know about the otel-bootstrap classes that will end up on …
mcculls c7bbdcc
Rebuild cached muzzle boot/tool classloaders if either class-path is …
mcculls 7148b82
Merge branch 'master' into mcculls/otel-metric-registry
mcculls 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
2 changes: 1 addition & 1 deletion
2
...emetry/shim/OtelInstrumentationScope.java → ...otel/common/OtelInstrumentationScope.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
10 changes: 5 additions & 5 deletions
10
...elemetry/shim/metrics/OtelInstrument.java → ...ootstrap/otel/metrics/OtelInstrument.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
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
2 changes: 1 addition & 1 deletion
2
...him/metrics/OtelInstrumentDescriptor.java → ...tel/metrics/OtelInstrumentDescriptor.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
2 changes: 1 addition & 1 deletion
2
...etry/shim/metrics/OtelInstrumentType.java → ...trap/otel/metrics/OtelInstrumentType.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
2 changes: 1 addition & 1 deletion
2
...try/shim/metrics/data/OtelAggregator.java → ...rap/otel/metrics/data/OtelAggregator.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
2 changes: 1 addition & 1 deletion
2
...ry/shim/metrics/data/OtelDoublePoint.java → ...ap/otel/metrics/data/OtelDoublePoint.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
2 changes: 1 addition & 1 deletion
2
...etry/shim/metrics/data/OtelDoubleSum.java → ...trap/otel/metrics/data/OtelDoubleSum.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
2 changes: 1 addition & 1 deletion
2
...ry/shim/metrics/data/OtelDoubleValue.java → ...ap/otel/metrics/data/OtelDoubleValue.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
2 changes: 1 addition & 1 deletion
2
...shim/metrics/data/OtelHistogramPoint.java → ...otel/metrics/data/OtelHistogramPoint.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
2 changes: 1 addition & 1 deletion
2
...him/metrics/data/OtelHistogramSketch.java → ...tel/metrics/data/OtelHistogramSketch.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
2 changes: 1 addition & 1 deletion
2
...etry/shim/metrics/data/OtelLongPoint.java → ...trap/otel/metrics/data/OtelLongPoint.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
2 changes: 1 addition & 1 deletion
2
...emetry/shim/metrics/data/OtelLongSum.java → ...tstrap/otel/metrics/data/OtelLongSum.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
2 changes: 1 addition & 1 deletion
2
...etry/shim/metrics/data/OtelLongValue.java → ...trap/otel/metrics/data/OtelLongValue.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
74 changes: 74 additions & 0 deletions
74
...bootstrap/src/main/java/datadog/trace/bootstrap/otel/metrics/data/OtelMetricRegistry.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,74 @@ | ||
| package datadog.trace.bootstrap.otel.metrics.data; | ||
|
|
||
| import datadog.trace.bootstrap.otel.common.OtelInstrumentationScope; | ||
| import datadog.trace.bootstrap.otel.metrics.OtelInstrumentDescriptor; | ||
| import datadog.trace.bootstrap.otel.metrics.export.OtelMetricsVisitor; | ||
| import datadog.trace.bootstrap.otel.metrics.export.OtelScopedMetricsVisitor; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.function.Function; | ||
|
|
||
| /** Tracks metric storage and observable callbacks by instrumentation scope. */ | ||
| public final class OtelMetricRegistry { | ||
| public static final OtelMetricRegistry INSTANCE = new OtelMetricRegistry(); | ||
|
|
||
| private final Map<OtelInstrumentationScope, Map<OtelInstrumentDescriptor, OtelMetricStorage>> | ||
| scopedStorage = new ConcurrentHashMap<>(); | ||
|
|
||
| private final Map<OtelInstrumentationScope, List<OtelObservable>> scopedObservables = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| public OtelMetricStorage registerStorage( | ||
| OtelInstrumentationScope instrumentationScope, | ||
| OtelInstrumentDescriptor descriptor, | ||
| Function<OtelInstrumentDescriptor, OtelMetricStorage> storageFactory) { | ||
| return scopedStorage | ||
| .computeIfAbsent(instrumentationScope, unused -> new ConcurrentHashMap<>()) | ||
| .computeIfAbsent(descriptor, storageFactory); | ||
| } | ||
|
|
||
| public void registerObservable( | ||
| OtelInstrumentationScope instrumentationScope, OtelObservable observable) { | ||
| List<OtelObservable> observables = | ||
| scopedObservables.computeIfAbsent(instrumentationScope, unused -> new ArrayList<>()); | ||
| synchronized (observables) { | ||
| observables.add(observable); | ||
| } | ||
| } | ||
|
|
||
| public boolean unregisterObservable( | ||
| OtelInstrumentationScope instrumentationScope, OtelObservable observable) { | ||
| List<OtelObservable> observables = scopedObservables.get(instrumentationScope); | ||
| if (observables == null) { | ||
| return false; | ||
| } | ||
| synchronized (observables) { | ||
| return observables.remove(observable); | ||
| } | ||
| } | ||
|
|
||
| public void collectMetrics(OtelMetricsVisitor visitor) { | ||
| scopedStorage.forEach( | ||
| (scope, storage) -> | ||
| collectScopedMetrics(scope, storage, visitor.visitScopedMetrics(scope))); | ||
| } | ||
|
|
||
| private void collectScopedMetrics( | ||
| OtelInstrumentationScope instrumentationScope, | ||
| Map<OtelInstrumentDescriptor, OtelMetricStorage> storage, | ||
| OtelScopedMetricsVisitor visitor) { | ||
| List<OtelObservable> observables = scopedObservables.get(instrumentationScope); | ||
| if (observables != null) { | ||
| // take local snapshot of current observables | ||
| List<OtelObservable> observablesCopy; | ||
| synchronized (observables) { | ||
| observablesCopy = new ArrayList<>(observables); | ||
| } | ||
| // must observe measurements outside of lock | ||
| observablesCopy.forEach(OtelObservable::observeMeasurements); | ||
| } | ||
| storage.forEach((descriptor, s) -> s.collectMetric(visitor.visitMetric(descriptor))); | ||
| } | ||
| } |
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
5 changes: 5 additions & 0 deletions
5
...tel-bootstrap/src/main/java/datadog/trace/bootstrap/otel/metrics/data/OtelObservable.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,5 @@ | ||
| package datadog.trace.bootstrap.otel.metrics.data; | ||
|
|
||
| public abstract class OtelObservable { | ||
| protected abstract void observeMeasurements(); | ||
| } |
3 changes: 3 additions & 0 deletions
3
...tel/otel-bootstrap/src/main/java/datadog/trace/bootstrap/otel/metrics/data/OtelPoint.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,3 @@ | ||
| package datadog.trace.bootstrap.otel.metrics.data; | ||
|
|
||
| public abstract class OtelPoint {} |
9 changes: 9 additions & 0 deletions
9
...ootstrap/src/main/java/datadog/trace/bootstrap/otel/metrics/export/OtelMetricVisitor.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,9 @@ | ||
| package datadog.trace.bootstrap.otel.metrics.export; | ||
|
|
||
| import datadog.trace.bootstrap.otel.metrics.data.OtelPoint; | ||
|
|
||
| /** A visitor to visit a metric in an instrumentation scope. */ | ||
| public interface OtelMetricVisitor { | ||
| /** Visits a data point in the metric. */ | ||
| void visitPoint(Object attributes, OtelPoint point); | ||
| } |
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.
❔ question: I guess the type was erased to not have OTel attributes into agent bootstrap.
How is that working with the
CARDINALITY_OVERFLOWconstant then?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.
Correct:
CARDINALITY_OVERFLOWis a shared internal constant, so both drop-in and the instrumentation will end up using the same key for that case.