Skip to content

Commit f36d153

Browse files
authored
Update to OTel 1.5 (#74)
1 parent 6022d36 commit f36d153

File tree

4 files changed

+227
-266
lines changed

4 files changed

+227
-266
lines changed

dependencyManagement/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ data class DependencySet(val group: String, val version: String, val modules: Li
2626

2727
val TEST_SNAPSHOTS = rootProject.findProperty("testUpstreamSnapshots") == "true"
2828

29+
val otelVersion = "1.5.0"
30+
val otelSnapshotVersion = "1.6.0"
31+
2932
val DEPENDENCY_BOMS = listOf(
3033
"com.amazonaws:aws-java-sdk-bom:1.11.1020",
3134
"com.fasterxml.jackson:jackson-bom:2.12.3",
3235
"com.google.guava:guava-bom:30.1.1-jre",
3336
"com.google.protobuf:protobuf-bom:3.17.0",
3437
"com.linecorp.armeria:armeria-bom:1.7.2",
3538
"io.grpc:grpc-bom:1.37.1",
36-
"io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:${if (!TEST_SNAPSHOTS) "1.4.0-alpha" else "1.5.0-alpha-SNAPSHOT"}",
39+
"io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:${if (!TEST_SNAPSHOTS) "$otelVersion-alpha" else "$otelSnapshotVersion-alpha-SNAPSHOT"}",
3740
"org.apache.logging.log4j:log4j-bom:2.14.1",
3841
"org.junit:junit-bom:5.7.2",
3942
"org.springframework.boot:spring-boot-dependencies:2.4.5",
@@ -67,7 +70,7 @@ val DEPENDENCIES = listOf(
6770
"com.sparkjava:spark-core:2.9.3",
6871
"com.squareup.okhttp3:okhttp:4.9.1",
6972
"io.opentelemetry.contrib:opentelemetry-aws-xray:1.4.0",
70-
"io.opentelemetry.javaagent:opentelemetry-javaagent:${if (!TEST_SNAPSHOTS) "1.4.0" else "1.5.0-SNAPSHOT"}",
73+
"io.opentelemetry.javaagent:opentelemetry-javaagent:${if (!TEST_SNAPSHOTS) otelVersion else "$otelSnapshotVersion-SNAPSHOT"}",
7174
"net.bytebuddy:byte-buddy:1.11.0"
7275
)
7376

sample-apps/spark-awssdkv1/src/main/java/com/amazon/sampleapp/MetricEmitter.java

Lines changed: 74 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package com.amazon.sampleapp;
22

3+
import io.opentelemetry.api.common.AttributeKey;
4+
import io.opentelemetry.api.common.Attributes;
5+
import io.opentelemetry.api.metrics.DoubleHistogram;
36
import io.opentelemetry.api.metrics.GlobalMeterProvider;
47
import io.opentelemetry.api.metrics.LongCounter;
5-
import io.opentelemetry.api.metrics.LongSumObserver;
68
import io.opentelemetry.api.metrics.LongUpDownCounter;
7-
import io.opentelemetry.api.metrics.LongUpDownSumObserver;
8-
import io.opentelemetry.api.metrics.LongValueObserver;
9-
import io.opentelemetry.api.metrics.LongValueRecorder;
109
import io.opentelemetry.api.metrics.Meter;
11-
import io.opentelemetry.api.metrics.common.Labels;
1210

1311
public class MetricEmitter {
1412

15-
static final String DIMENSION_API_NAME = "apiName";
16-
static final String DIMENSION_STATUS_CODE = "statusCode";
13+
static final AttributeKey<String> DIMENSION_API_NAME = AttributeKey.stringKey("apiName");
14+
static final AttributeKey<String> DIMENSION_STATUS_CODE = AttributeKey.stringKey("statusCode");
1715

1816
static String API_COUNTER_METRIC = "apiBytesSent";
1917
static String API_LATENCY_METRIC = "latency";
@@ -23,11 +21,9 @@ public class MetricEmitter {
2321
static String API_UP_DOWN_SUM_METRIC = "actualQueueSize";
2422

2523
LongCounter apiBytesSentCounter;
26-
LongValueRecorder apiLatencyRecorder;
27-
LongSumObserver totalBytesSentObserver;
28-
LongValueObserver apiLastLatencyObserver;
24+
DoubleHistogram apiLatencyRecorder;
25+
LongCounter totalBytesSentObserver;
2926
LongUpDownCounter queueSizeCounter;
30-
LongUpDownSumObserver actualQueueSizeObserver;
3127

3228
long totalBytesSent;
3329
long apiLastLatency;
@@ -39,7 +35,8 @@ public class MetricEmitter {
3935
String statusCodeValue = "";
4036

4137
public MetricEmitter() {
42-
Meter meter = GlobalMeterProvider.getMeter("aws-otel", "1.0");
38+
Meter meter =
39+
GlobalMeterProvider.get().meterBuilder("aws-otel").setInstrumentationVersion("1.0").build();
4340

4441
// give a instanceId appending to the metricname so that we can check the metric for each round
4542
// of integ-test
@@ -65,95 +62,83 @@ public MetricEmitter() {
6562

6663
apiBytesSentCounter =
6764
meter
68-
.longCounterBuilder(apiBytesSentMetricName)
65+
.counterBuilder(apiBytesSentMetricName)
6966
.setDescription("API request load sent in bytes")
7067
.setUnit("one")
7168
.build();
7269

7370
apiLatencyRecorder =
7471
meter
75-
.longValueRecorderBuilder(latencyMetricName)
72+
.histogramBuilder(latencyMetricName)
7673
.setDescription("API latency time")
7774
.setUnit("ms")
7875
.build();
7976

8077
queueSizeCounter =
8178
meter
82-
.longUpDownCounterBuilder(queueSizeChangeMetricName)
79+
.upDownCounterBuilder(queueSizeChangeMetricName)
8380
.setDescription("Queue Size change")
8481
.setUnit("one")
8582
.build();
8683

87-
totalBytesSentObserver =
88-
meter
89-
.longSumObserverBuilder(totalApiBytesSentMetricName)
90-
.setDescription("Total API request load sent in bytes")
91-
.setUnit("one")
92-
.setUpdater(
93-
longResult -> {
94-
System.out.println(
95-
"emit total http request size "
96-
+ totalBytesSent
97-
+ " byte, "
98-
+ apiNameValue
99-
+ ","
100-
+ statusCodeValue);
101-
longResult.observe(
102-
totalBytesSent,
103-
Labels.of(
104-
DIMENSION_API_NAME,
105-
apiNameValue,
106-
DIMENSION_STATUS_CODE,
107-
statusCodeValue));
108-
})
109-
.build();
110-
111-
apiLastLatencyObserver =
112-
meter
113-
.longValueObserverBuilder(lastLatencyMetricName)
114-
.setDescription("The last API latency observed at collection interval")
115-
.setUnit("ms")
116-
.setUpdater(
117-
longResult -> {
118-
System.out.println(
119-
"emit last api latency "
120-
+ apiLastLatency
121-
+ ","
122-
+ apiNameValue
123-
+ ","
124-
+ statusCodeValue);
125-
longResult.observe(
126-
apiLastLatency,
127-
Labels.of(
128-
DIMENSION_API_NAME,
129-
apiNameValue,
130-
DIMENSION_STATUS_CODE,
131-
statusCodeValue));
132-
})
133-
.build();
134-
actualQueueSizeObserver =
135-
meter
136-
.longUpDownSumObserverBuilder(actualQueueSizeMetricName)
137-
.setDescription("The actual queue size observed at collection interval")
138-
.setUnit("one")
139-
.setUpdater(
140-
longResult -> {
141-
System.out.println(
142-
"emit actual queue size "
143-
+ actualQueueSize
144-
+ ","
145-
+ apiNameValue
146-
+ ","
147-
+ statusCodeValue);
148-
longResult.observe(
149-
actualQueueSize,
150-
Labels.of(
151-
DIMENSION_API_NAME,
152-
apiNameValue,
153-
DIMENSION_STATUS_CODE,
154-
statusCodeValue));
155-
})
156-
.build();
84+
meter
85+
.gaugeBuilder(totalApiBytesSentMetricName)
86+
.setDescription("Total API request load sent in bytes")
87+
.setUnit("one")
88+
.ofLongs()
89+
.buildWithCallback(
90+
measurement -> {
91+
System.out.println(
92+
"emit total http request size "
93+
+ totalBytesSent
94+
+ " byte, "
95+
+ apiNameValue
96+
+ ","
97+
+ statusCodeValue);
98+
measurement.observe(
99+
totalBytesSent,
100+
Attributes.of(
101+
DIMENSION_API_NAME, apiNameValue, DIMENSION_STATUS_CODE, statusCodeValue));
102+
});
103+
104+
meter
105+
.gaugeBuilder(lastLatencyMetricName)
106+
.setDescription("The last API latency observed at collection interval")
107+
.setUnit("ms")
108+
.ofLongs()
109+
.buildWithCallback(
110+
measurement -> {
111+
System.out.println(
112+
"emit last api latency "
113+
+ apiLastLatency
114+
+ ","
115+
+ apiNameValue
116+
+ ","
117+
+ statusCodeValue);
118+
measurement.observe(
119+
apiLastLatency,
120+
Attributes.of(
121+
DIMENSION_API_NAME, apiNameValue, DIMENSION_STATUS_CODE, statusCodeValue));
122+
});
123+
meter
124+
.gaugeBuilder(actualQueueSizeMetricName)
125+
.setDescription("The actual queue size observed at collection interval")
126+
.setUnit("one")
127+
.ofLongs()
128+
.buildWithCallback(
129+
measurement -> {
130+
System.out.println(
131+
"emit actual queue size "
132+
+ actualQueueSize
133+
+ ","
134+
+ apiNameValue
135+
+ ","
136+
+ statusCodeValue);
137+
measurement.observe(
138+
actualQueueSize,
139+
Attributes.of(
140+
DIMENSION_API_NAME, apiNameValue, DIMENSION_STATUS_CODE, statusCodeValue));
141+
});
157142
}
158143

159144
/**
@@ -167,7 +152,7 @@ public void emitReturnTimeMetric(Long returnTime, String apiName, String statusC
167152
System.out.println(
168153
"emit metric with return time " + returnTime + "," + apiName + "," + statusCode);
169154
apiLatencyRecorder.record(
170-
returnTime, Labels.of(DIMENSION_API_NAME, apiName, DIMENSION_STATUS_CODE, statusCode));
155+
returnTime, Attributes.of(DIMENSION_API_NAME, apiName, DIMENSION_STATUS_CODE, statusCode));
171156
}
172157

173158
/**
@@ -180,7 +165,7 @@ public void emitReturnTimeMetric(Long returnTime, String apiName, String statusC
180165
public void emitBytesSentMetric(int bytes, String apiName, String statusCode) {
181166
System.out.println("emit metric with http request size " + bytes + " byte, " + apiName);
182167
apiBytesSentCounter.add(
183-
bytes, Labels.of(DIMENSION_API_NAME, apiName, DIMENSION_STATUS_CODE, statusCode));
168+
bytes, Attributes.of(DIMENSION_API_NAME, apiName, DIMENSION_STATUS_CODE, statusCode));
184169
}
185170

186171
/**
@@ -194,7 +179,8 @@ public void emitQueueSizeChangeMetric(int queueSizeChange, String apiName, Strin
194179
System.out.println(
195180
"emit metric with queue size change " + queueSizeChange + "," + apiName + "," + statusCode);
196181
queueSizeCounter.add(
197-
queueSizeChange, Labels.of(DIMENSION_API_NAME, apiName, DIMENSION_STATUS_CODE, statusCode));
182+
queueSizeChange,
183+
Attributes.of(DIMENSION_API_NAME, apiName, DIMENSION_STATUS_CODE, statusCode));
198184
}
199185

200186
/**

0 commit comments

Comments
 (0)