Skip to content

Commit b57c1a0

Browse files
authored
Update semconv (#10272)
1 parent 0337158 commit b57c1a0

File tree

89 files changed

+858
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+858
-304
lines changed

dependencyManagement/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ val mockitoVersion = "4.11.0"
4747
val slf4jVersion = "2.0.11"
4848

4949
val CORE_DEPENDENCIES = listOf(
50-
"io.opentelemetry.semconv:opentelemetry-semconv:1.21.0-alpha",
50+
"io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha",
5151
"com.google.auto.service:auto-service:${autoServiceVersion}",
5252
"com.google.auto.service:auto-service-annotations:${autoServiceVersion}",
5353
"com.google.auto.value:auto-value:${autoValueVersion}",

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/http/HttpExperimentalMetricsAdvice.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.opentelemetry.api.metrics.LongUpDownCounterBuilder;
1212
import io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder;
1313
import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder;
14-
import io.opentelemetry.instrumentation.api.semconv.http.internal.HttpAttributes;
1514
import io.opentelemetry.semconv.SemanticAttributes;
1615

1716
final class HttpExperimentalMetricsAdvice {
@@ -25,7 +24,7 @@ static void applyClientRequestSizeAdvice(LongHistogramBuilder builder) {
2524
asList(
2625
SemanticAttributes.HTTP_REQUEST_METHOD,
2726
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
28-
HttpAttributes.ERROR_TYPE,
27+
SemanticAttributes.ERROR_TYPE,
2928
SemanticAttributes.NETWORK_PROTOCOL_NAME,
3029
SemanticAttributes.NETWORK_PROTOCOL_VERSION,
3130
SemanticAttributes.SERVER_ADDRESS,
@@ -43,7 +42,7 @@ static void applyServerRequestSizeAdvice(LongHistogramBuilder builder) {
4342
SemanticAttributes.HTTP_ROUTE,
4443
SemanticAttributes.HTTP_REQUEST_METHOD,
4544
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
46-
HttpAttributes.ERROR_TYPE,
45+
SemanticAttributes.ERROR_TYPE,
4746
SemanticAttributes.NETWORK_PROTOCOL_NAME,
4847
SemanticAttributes.NETWORK_PROTOCOL_VERSION,
4948
SemanticAttributes.URL_SCHEME));

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/messaging/MessagingAttributesExtractor.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,28 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
7272
attributes,
7373
SemanticAttributes.MESSAGING_DESTINATION_NAME,
7474
getter.getDestination(request));
75+
internalSet(
76+
attributes,
77+
SemanticAttributes.MESSAGING_DESTINATION_TEMPLATE,
78+
getter.getDestinationTemplate(request));
79+
}
80+
boolean isAnonymousDestination = getter.isAnonymousDestination(request);
81+
if (isAnonymousDestination) {
82+
internalSet(attributes, SemanticAttributes.MESSAGING_DESTINATION_ANONYMOUS, true);
7583
}
7684
internalSet(
7785
attributes,
7886
SemanticAttributes.MESSAGING_MESSAGE_CONVERSATION_ID,
7987
getter.getConversationId(request));
8088
internalSet(
8189
attributes,
82-
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES,
83-
getter.getMessagePayloadSize(request));
90+
SemanticAttributes.MESSAGING_MESSAGE_BODY_SIZE,
91+
getter.getMessageBodySize(request));
8492
internalSet(
8593
attributes,
86-
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES,
87-
getter.getMessagePayloadCompressedSize(request));
94+
SemanticAttributes.MESSAGING_MESSAGE_ENVELOPE_SIZE,
95+
getter.getMessageEnvelopeSize(request));
96+
internalSet(attributes, SemanticAttributes.MESSAGING_CLIENT_ID, getter.getClientId(request));
8897
if (operation != null) {
8998
internalSet(attributes, SemanticAttributes.MESSAGING_OPERATION, operation.operationName());
9099
}
@@ -101,6 +110,10 @@ public void onEnd(
101110
attributes,
102111
SemanticAttributes.MESSAGING_MESSAGE_ID,
103112
getter.getMessageId(request, response));
113+
internalSet(
114+
attributes,
115+
SemanticAttributes.MESSAGING_BATCH_MESSAGE_COUNT,
116+
getter.getBatchMessageCount(request, response));
104117

105118
for (String name : capturedHeaders) {
106119
List<String> values = getter.getMessageHeader(request, name);

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/messaging/MessagingAttributesGetter.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,43 @@ public interface MessagingAttributesGetter<REQUEST, RESPONSE> {
2525
@Nullable
2626
String getDestination(REQUEST request);
2727

28+
@Nullable
29+
String getDestinationTemplate(REQUEST request);
30+
2831
boolean isTemporaryDestination(REQUEST request);
2932

33+
boolean isAnonymousDestination(REQUEST request);
34+
3035
@Nullable
3136
String getConversationId(REQUEST request);
3237

3338
@Nullable
34-
Long getMessagePayloadSize(REQUEST request);
39+
@Deprecated
40+
default Long getMessagePayloadSize(REQUEST request) {
41+
return null;
42+
}
43+
44+
@Nullable
45+
@Deprecated
46+
default Long getMessagePayloadCompressedSize(REQUEST request) {
47+
return null;
48+
}
3549

3650
@Nullable
37-
Long getMessagePayloadCompressedSize(REQUEST request);
51+
Long getMessageBodySize(REQUEST request);
52+
53+
@Nullable
54+
Long getMessageEnvelopeSize(REQUEST request);
3855

3956
@Nullable
4057
String getMessageId(REQUEST request, @Nullable RESPONSE response);
4158

59+
@Nullable
60+
String getClientId(REQUEST request);
61+
62+
@Nullable
63+
Long getBatchMessageCount(REQUEST request, @Nullable RESPONSE response);
64+
4265
/**
4366
* Extracts all values of header named {@code name} from the request, or an empty list if there
4467
* were none.

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/http/HttpClientExperimentalMetricsTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.opentelemetry.api.trace.TraceState;
1616
import io.opentelemetry.context.Context;
1717
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
18-
import io.opentelemetry.instrumentation.api.semconv.http.internal.HttpAttributes;
1918
import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes;
2019
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
2120
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
@@ -47,7 +46,7 @@ void collectsMetrics() {
4746
Attributes responseAttributes =
4847
Attributes.builder()
4948
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
50-
.put(HttpAttributes.ERROR_TYPE, "400")
49+
.put(SemanticAttributes.ERROR_TYPE, "400")
5150
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
5251
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
5352
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
@@ -93,7 +92,7 @@ void collectsMetrics() {
9392
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
9493
equalTo(
9594
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
96-
equalTo(HttpAttributes.ERROR_TYPE, "400"),
95+
equalTo(SemanticAttributes.ERROR_TYPE, "400"),
9796
equalTo(
9897
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
9998
equalTo(
@@ -120,7 +119,7 @@ void collectsMetrics() {
120119
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
121120
equalTo(
122121
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
123-
equalTo(HttpAttributes.ERROR_TYPE, "400"),
122+
equalTo(SemanticAttributes.ERROR_TYPE, "400"),
124123
equalTo(
125124
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
126125
equalTo(

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/http/HttpServerExperimentalMetricsTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.opentelemetry.api.trace.TraceState;
1616
import io.opentelemetry.context.Context;
1717
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
18-
import io.opentelemetry.instrumentation.api.semconv.http.internal.HttpAttributes;
1918
import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes;
2019
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
2120
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
@@ -51,7 +50,7 @@ void collectsMetrics() {
5150
Attributes responseAttributes =
5251
Attributes.builder()
5352
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
54-
.put(HttpAttributes.ERROR_TYPE, "500")
53+
.put(SemanticAttributes.ERROR_TYPE, "500")
5554
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
5655
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
5756
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
@@ -157,7 +156,7 @@ void collectsMetrics() {
157156
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
158157
equalTo(
159158
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
160-
equalTo(HttpAttributes.ERROR_TYPE, "500"),
159+
equalTo(SemanticAttributes.ERROR_TYPE, "500"),
161160
equalTo(
162161
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
163162
equalTo(
@@ -183,7 +182,7 @@ void collectsMetrics() {
183182
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
184183
equalTo(
185184
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
186-
equalTo(HttpAttributes.ERROR_TYPE, "500"),
185+
equalTo(SemanticAttributes.ERROR_TYPE, "500"),
187186
equalTo(
188187
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
189188
equalTo(

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/messaging/MessagingAttributesExtractorTest.java

+54-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121
import java.util.Map;
2222
import java.util.stream.Stream;
23+
import javax.annotation.Nullable;
2324
import org.assertj.core.data.MapEntry;
2425
import org.junit.jupiter.api.Test;
2526
import org.junit.jupiter.params.ParameterizedTest;
@@ -32,6 +33,7 @@ class MessagingAttributesExtractorTest {
3233
@MethodSource("destinations")
3334
void shouldExtractAllAvailableAttributes(
3435
boolean temporary,
36+
boolean anonymous,
3537
String destination,
3638
MessageOperation operation,
3739
String expectedDestination) {
@@ -40,13 +42,19 @@ void shouldExtractAllAvailableAttributes(
4042
request.put("system", "myQueue");
4143
request.put("destinationKind", "topic");
4244
request.put("destination", destination);
45+
request.put("destinationTemplate", destination);
4346
if (temporary) {
4447
request.put("temporaryDestination", "y");
4548
}
49+
if (anonymous) {
50+
request.put("anonymousDestination", "y");
51+
}
4652
request.put("url", "http://broker/topic");
4753
request.put("conversationId", "42");
48-
request.put("payloadSize", "100");
49-
request.put("payloadCompressedSize", "10");
54+
request.put("bodySize", "100");
55+
request.put("envelopeSize", "120");
56+
request.put("clientId", "43");
57+
request.put("batchMessageCount", "2");
5058

5159
AttributesExtractor<Map<String, String>, String> underTest =
5260
MessagingAttributesExtractor.create(TestGetter.INSTANCE, operation);
@@ -66,11 +74,17 @@ void shouldExtractAllAvailableAttributes(
6674
expectedEntries.add(entry(SemanticAttributes.MESSAGING_DESTINATION_NAME, expectedDestination));
6775
if (temporary) {
6876
expectedEntries.add(entry(SemanticAttributes.MESSAGING_DESTINATION_TEMPORARY, true));
77+
} else {
78+
expectedEntries.add(
79+
entry(SemanticAttributes.MESSAGING_DESTINATION_TEMPLATE, expectedDestination));
80+
}
81+
if (anonymous) {
82+
expectedEntries.add(entry(SemanticAttributes.MESSAGING_DESTINATION_ANONYMOUS, true));
6983
}
7084
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_CONVERSATION_ID, "42"));
71-
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES, 100L));
72-
expectedEntries.add(
73-
entry(SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES, 10L));
85+
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_BODY_SIZE, 100L));
86+
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_ENVELOPE_SIZE, 120L));
87+
expectedEntries.add(entry(SemanticAttributes.MESSAGING_CLIENT_ID, "43"));
7488
expectedEntries.add(entry(SemanticAttributes.MESSAGING_OPERATION, operation.operationName()));
7589

7690
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -79,13 +93,15 @@ void shouldExtractAllAvailableAttributes(
7993
assertThat(startAttributes.build()).containsOnly(expectedEntriesArr);
8094

8195
assertThat(endAttributes.build())
82-
.containsOnly(entry(SemanticAttributes.MESSAGING_MESSAGE_ID, "42"));
96+
.containsOnly(
97+
entry(SemanticAttributes.MESSAGING_MESSAGE_ID, "42"),
98+
entry(SemanticAttributes.MESSAGING_BATCH_MESSAGE_COUNT, 2L));
8399
}
84100

85101
static Stream<Arguments> destinations() {
86102
return Stream.of(
87-
Arguments.of(false, "destination", MessageOperation.RECEIVE, "destination"),
88-
Arguments.of(true, null, MessageOperation.PROCESS, "(temporary)"));
103+
Arguments.of(false, false, "destination", MessageOperation.RECEIVE, "destination"),
104+
Arguments.of(true, true, null, MessageOperation.PROCESS, "(temporary)"));
89105
}
90106

91107
@Test
@@ -122,31 +138,57 @@ public String getDestination(Map<String, String> request) {
122138
return request.get("destination");
123139
}
124140

141+
@Nullable
142+
@Override
143+
public String getDestinationTemplate(Map<String, String> request) {
144+
return request.get("destinationTemplate");
145+
}
146+
125147
@Override
126148
public boolean isTemporaryDestination(Map<String, String> request) {
127149
return request.containsKey("temporaryDestination");
128150
}
129151

152+
@Override
153+
public boolean isAnonymousDestination(Map<String, String> request) {
154+
return request.containsKey("anonymousDestination");
155+
}
156+
130157
@Override
131158
public String getConversationId(Map<String, String> request) {
132159
return request.get("conversationId");
133160
}
134161

162+
@Nullable
135163
@Override
136-
public Long getMessagePayloadSize(Map<String, String> request) {
137-
String payloadSize = request.get("payloadSize");
164+
public Long getMessageBodySize(Map<String, String> request) {
165+
String payloadSize = request.get("bodySize");
138166
return payloadSize == null ? null : Long.valueOf(payloadSize);
139167
}
140168

169+
@Nullable
141170
@Override
142-
public Long getMessagePayloadCompressedSize(Map<String, String> request) {
143-
String payloadSize = request.get("payloadCompressedSize");
171+
public Long getMessageEnvelopeSize(Map<String, String> request) {
172+
String payloadSize = request.get("envelopeSize");
144173
return payloadSize == null ? null : Long.valueOf(payloadSize);
145174
}
146175

147176
@Override
148177
public String getMessageId(Map<String, String> request, String response) {
149178
return response;
150179
}
180+
181+
@Nullable
182+
@Override
183+
public String getClientId(Map<String, String> request) {
184+
return request.get("clientId");
185+
}
186+
187+
@Nullable
188+
@Override
189+
public Long getBatchMessageCount(Map<String, String> request, @Nullable String response) {
190+
String payloadSize = request.get("batchMessageCount");
191+
return payloadSize == null ? null : Long.valueOf(payloadSize);
192+
}
151193
}
152194
}

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/http/HttpClientAttributesExtractor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
1414
import io.opentelemetry.instrumentation.api.internal.SpanKey;
1515
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
16-
import io.opentelemetry.instrumentation.api.semconv.http.internal.HttpAttributes;
1716
import io.opentelemetry.instrumentation.api.semconv.network.internal.InternalNetworkAttributesExtractor;
1817
import io.opentelemetry.instrumentation.api.semconv.network.internal.InternalServerAttributesExtractor;
1918
import io.opentelemetry.semconv.SemanticAttributes;
@@ -78,7 +77,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
7877

7978
int resendCount = resendCountIncrementer.applyAsInt(parentContext);
8079
if (resendCount > 0) {
81-
attributes.put(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, resendCount);
80+
attributes.put(SemanticAttributes.HTTP_REQUEST_RESEND_COUNT, resendCount);
8281
}
8382
}
8483

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/http/HttpCommonAttributesExtractor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io.opentelemetry.api.common.AttributesBuilder;
1515
import io.opentelemetry.context.Context;
1616
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
17-
import io.opentelemetry.instrumentation.api.semconv.http.internal.HttpAttributes;
1817
import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter;
1918
import io.opentelemetry.semconv.SemanticAttributes;
2019
import java.util.HashSet;
@@ -111,7 +110,7 @@ public void onEnd(
111110
errorType = _OTHER;
112111
}
113112
}
114-
internalSet(attributes, HttpAttributes.ERROR_TYPE, errorType);
113+
internalSet(attributes, SemanticAttributes.ERROR_TYPE, errorType);
115114

116115
String protocolName = lowercaseStr(getter.getNetworkProtocolName(request, response));
117116
String protocolVersion = lowercaseStr(getter.getNetworkProtocolVersion(request, response));

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/http/HttpMetricsAdvice.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
1212
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder;
13-
import io.opentelemetry.instrumentation.api.semconv.http.internal.HttpAttributes;
1413
import io.opentelemetry.semconv.SemanticAttributes;
1514
import java.util.List;
1615

@@ -29,7 +28,7 @@ static void applyClientDurationAdvice(DoubleHistogramBuilder builder) {
2928
asList(
3029
SemanticAttributes.HTTP_REQUEST_METHOD,
3130
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
32-
HttpAttributes.ERROR_TYPE,
31+
SemanticAttributes.ERROR_TYPE,
3332
SemanticAttributes.NETWORK_PROTOCOL_NAME,
3433
SemanticAttributes.NETWORK_PROTOCOL_VERSION,
3534
SemanticAttributes.SERVER_ADDRESS,
@@ -46,7 +45,7 @@ static void applyServerDurationAdvice(DoubleHistogramBuilder builder) {
4645
SemanticAttributes.HTTP_ROUTE,
4746
SemanticAttributes.HTTP_REQUEST_METHOD,
4847
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
49-
HttpAttributes.ERROR_TYPE,
48+
SemanticAttributes.ERROR_TYPE,
5049
SemanticAttributes.NETWORK_PROTOCOL_NAME,
5150
SemanticAttributes.NETWORK_PROTOCOL_VERSION,
5251
SemanticAttributes.URL_SCHEME));

0 commit comments

Comments
 (0)