-
Notifications
You must be signed in to change notification settings - Fork 324
Implement OpenTelemetry meter storage and aggregations #10534
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 14 commits into
master
from
mcculls/otel-meter-storage
Feb 6, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4525c09
Build instrument descriptors
mcculls 7c3a232
Fill in default arguments
mcculls 10d70b3
Disallow negative values in counters/histograms
mcculls 3c0341e
Validate and capture explicit bucket boundaries
mcculls f64d81e
Update OTel metrics helper list
mcculls 9cf99ae
Context is unused by our metric mapping
mcculls 806f7e4
Implement OTel metrics storage and aggregation
mcculls 0e362ed
Track metrics storage per-meter
mcculls ed5f068
Introduce visitor API for exporting metrics
mcculls 2dc0b03
Suppress warning about catching NPE in setExplicitBucketBoundariesAdv…
mcculls 082c358
Spotless
mcculls fb6ee6b
Cleanup
mcculls 492a33e
javadoc
mcculls 3f305b4
Review feedback
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,66 +2,135 @@ | |
|
|
||
| import static datadog.opentelemetry.shim.metrics.OtelInstrumentBuilder.ofDoubles; | ||
| import static datadog.opentelemetry.shim.metrics.OtelInstrumentType.HISTOGRAM; | ||
| import static datadog.opentelemetry.shim.metrics.data.OtelMetricStorage.newHistogramStorage; | ||
| import static java.util.Arrays.asList; | ||
| import static java.util.Collections.emptyList; | ||
|
|
||
| import datadog.opentelemetry.shim.metrics.data.OtelMetricStorage; | ||
| import datadog.trace.relocate.api.RatelimitedLogger; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.DoubleHistogram; | ||
| import io.opentelemetry.api.metrics.DoubleHistogramBuilder; | ||
| import io.opentelemetry.api.metrics.LongHistogramBuilder; | ||
| import io.opentelemetry.context.Context; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.TimeUnit; | ||
| import javax.annotation.ParametersAreNonnullByDefault; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @ParametersAreNonnullByDefault | ||
| final class OtelDoubleHistogram implements DoubleHistogram { | ||
| final class OtelDoubleHistogram extends OtelInstrument implements DoubleHistogram { | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(OtelDoubleHistogram.class); | ||
| private static final RatelimitedLogger RATELIMITED_LOGGER = | ||
| new RatelimitedLogger(LOGGER, 5, TimeUnit.MINUTES); | ||
|
|
||
| OtelDoubleHistogram(OtelMetricStorage storage) { | ||
| super(storage); | ||
| } | ||
|
|
||
| @Override | ||
| public void record(double value) { | ||
| // FIXME: implement recording | ||
| record(value, Attributes.empty()); | ||
| } | ||
|
|
||
| @Override | ||
| public void record(double value, Attributes attributes) { | ||
| // FIXME: implement recording | ||
| if (value < 0) { | ||
| RATELIMITED_LOGGER.warn( | ||
| "Histograms can only record non-negative values. Instrument {} has recorded a negative value.", | ||
| storage.getInstrumentName()); | ||
| } else { | ||
| storage.recordDouble(value, attributes); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void record(double value, Attributes attributes, Context context) { | ||
| // FIXME: implement recording | ||
| public void record(double value, Attributes attributes, Context unused) { | ||
| record(value, attributes); | ||
| } | ||
|
|
||
| static final class Builder implements DoubleHistogramBuilder { | ||
| private final OtelInstrumentBuilder instrumentBuilder; | ||
| private static final List<Double> DEFAULT_BOUNDARIES = | ||
| asList( | ||
| 0d, 5d, 10d, 25d, 50d, 75d, 100d, 250d, 500d, 750d, 1_000d, 2_500d, 5_000d, 7_500d, | ||
| 10_000d); | ||
|
Comment on lines
+59
to
+60
Contributor
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. 👏 praise: Thanks for making numeric literals easier to read with |
||
|
|
||
| private final OtelMeter meter; | ||
| private final OtelInstrumentBuilder builder; | ||
| private List<Double> bucketBoundaries; | ||
|
|
||
| Builder(OtelMeter meter, String instrumentName) { | ||
| this.instrumentBuilder = ofDoubles(meter, instrumentName, HISTOGRAM); | ||
| this.meter = meter; | ||
| this.builder = ofDoubles(instrumentName, HISTOGRAM); | ||
| this.bucketBoundaries = DEFAULT_BOUNDARIES; | ||
| } | ||
|
|
||
| @Override | ||
| public DoubleHistogramBuilder setDescription(String description) { | ||
| instrumentBuilder.setDescription(description); | ||
| builder.setDescription(description); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public DoubleHistogramBuilder setUnit(String unit) { | ||
| instrumentBuilder.setUnit(unit); | ||
| builder.setUnit(unit); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressFBWarnings("DCN") // match OTel in catching and logging NPE | ||
| public DoubleHistogramBuilder setExplicitBucketBoundariesAdvice(List<Double> bucketBoundaries) { | ||
| // FIXME: implement boundary advice | ||
| try { | ||
| Objects.requireNonNull(bucketBoundaries, "bucketBoundaries must not be null"); | ||
| this.bucketBoundaries = validateBoundaries(new ArrayList<>(bucketBoundaries)); | ||
| } catch (IllegalArgumentException | NullPointerException e) { | ||
| LOGGER.warn("Error setting explicit bucket boundaries advice: {}", e.getMessage()); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public LongHistogramBuilder ofLongs() { | ||
| return new OtelLongHistogram.Builder(instrumentBuilder); | ||
| return new OtelLongHistogram.Builder(meter, builder, bucketBoundaries); | ||
| } | ||
|
|
||
| @Override | ||
| public DoubleHistogram build() { | ||
| return new OtelDoubleHistogram(); | ||
| return new OtelDoubleHistogram( | ||
| meter.registerStorage( | ||
| builder.descriptor(), | ||
| descriptor -> newHistogramStorage(descriptor, bucketBoundaries))); | ||
| } | ||
|
|
||
| static List<Double> validateBoundaries(List<Double> boundaries) { | ||
| if (boundaries.isEmpty()) { | ||
| return emptyList(); | ||
| } | ||
| if (boundaries.get(0) == Double.NEGATIVE_INFINITY) { | ||
| throw new IllegalArgumentException("invalid bucket boundary: -Inf"); | ||
| } | ||
| if (boundaries.get(boundaries.size() - 1) == Double.POSITIVE_INFINITY) { | ||
| throw new IllegalArgumentException("invalid bucket boundary: +Inf"); | ||
| } | ||
| Double previousBoundary = null; | ||
| for (Double boundary : boundaries) { | ||
| if (boundary.isNaN()) { | ||
| throw new IllegalArgumentException("invalid bucket boundary: NaN"); | ||
| } | ||
| if (previousBoundary != null && previousBoundary >= boundary) { | ||
| throw new IllegalArgumentException( | ||
| "Bucket boundaries must be in increasing order: " | ||
| + previousBoundary | ||
| + " >= " | ||
| + boundary); | ||
| } | ||
| previousBoundary = boundary; | ||
| } | ||
| return boundaries; | ||
| } | ||
| } | ||
| } | ||
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.