Skip to content

Commit 0d8ccd1

Browse files
committed
Refactor OtelMetricStorage so the same instance can aggregate metrics
using OTel attributes from both bootstrap and application classpaths
1 parent 066d459 commit 0d8ccd1

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/metrics/data/OtelMetricStorage.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final class OtelMetricStorage {
3535

3636
private final OtelInstrumentDescriptor descriptor;
3737
private final boolean resetOnCollect;
38-
private final Function<Attributes, OtelAggregator> aggregatorSupplier;
38+
private final Function<Object, OtelAggregator> aggregatorSupplier;
3939
private volatile Recording currentRecording;
4040

4141
// only used with DELTA temporality
@@ -98,7 +98,7 @@ public OtelInstrumentDescriptor getDescriptor() {
9898
return descriptor;
9999
}
100100

101-
public void recordLong(long value, Attributes attributes) {
101+
public void recordLong(long value, Object attributes) {
102102
if (resetOnCollect) {
103103
Recording recording = acquireRecordingForWrite();
104104
try {
@@ -112,7 +112,7 @@ public void recordLong(long value, Attributes attributes) {
112112
}
113113
}
114114

115-
public void recordDouble(double value, Attributes attributes) {
115+
public void recordDouble(double value, Object attributes) {
116116
if (Double.isNaN(value)) {
117117
LOGGER.debug(
118118
"Instrument {} has recorded measurement Not-a-Number (NaN) value with attributes {}. Dropping measurement.",
@@ -133,8 +133,7 @@ public void recordDouble(double value, Attributes attributes) {
133133
}
134134
}
135135

136-
private OtelAggregator aggregator(
137-
Map<Attributes, OtelAggregator> aggregators, Attributes attributes) {
136+
private OtelAggregator aggregator(Map<Object, OtelAggregator> aggregators, Object attributes) {
138137
Objects.requireNonNull(attributes, "attributes");
139138
OtelAggregator aggregator = aggregators.get(attributes);
140139
if (null != aggregator) {
@@ -188,7 +187,7 @@ private void doCollectAndReset(OtelInstrumentVisitor visitor) {
188187
Thread.yield(); // other threads are still writing to this recording
189188
}
190189

191-
Map<Attributes, OtelAggregator> aggregators = recording.aggregators;
190+
Map<Object, OtelAggregator> aggregators = recording.aggregators;
192191

193192
// avoid churn: only remove empty aggregators if we're over cardinality
194193
if (aggregators.size() >= CARDINALITY_LIMIT) {
@@ -233,7 +232,7 @@ private void releaseRecordingAfterWrite(Recording recording) {
233232
private static final int WRITER = 2;
234233

235234
static final class Recording {
236-
final Map<Attributes, OtelAggregator> aggregators;
235+
final Map<Object, OtelAggregator> aggregators;
237236

238237
transient volatile int activity;
239238

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package datadog.opentelemetry.shim.metrics.export;
22

33
import datadog.opentelemetry.shim.metrics.data.OtelPoint;
4-
import io.opentelemetry.api.common.Attributes;
54

65
public interface OtelInstrumentVisitor {
76
/** Visits a data point collected by the instrument. */
8-
void visitPoint(Attributes attributes, OtelPoint point);
7+
void visitPoint(Object attributes, OtelPoint point);
98
}

dd-java-agent/instrumentation/opentelemetry/opentelemetry-1.47/src/test/groovy/opentelemetry147/metrics/MetricsTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class MetricsTest extends InstrumentationSpecification {
442442
}
443443

444444
@Override
445-
void visitPoint(Attributes attributes, OtelPoint point) {
445+
void visitPoint(Object attributes, OtelPoint point) {
446446
def key = scopeName + ':' + instrumentName
447447
if (!attributes.isEmpty()) {
448448
key = key + '@' + attributes.asMap()

0 commit comments

Comments
 (0)