Skip to content

Commit 6b25bfe

Browse files
committed
Update semconv
1 parent cb5ade3 commit 6b25bfe

File tree

12 files changed

+93
-75
lines changed

12 files changed

+93
-75
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/exporter/AgentLogExporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import io.opentelemetry.sdk.common.CompletableResultCode;
2222
import io.opentelemetry.sdk.logs.data.LogRecordData;
2323
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
24-
import io.opentelemetry.semconv.SemanticAttributes;
24+
import io.opentelemetry.semconv.ExceptionAttributes;
2525
import java.util.Collection;
2626
import java.util.List;
2727
import java.util.function.Consumer;
@@ -102,7 +102,7 @@ private CompletableResultCode internalExport(Collection<LogRecordData> logs) {
102102
continue;
103103
}
104104

105-
String stack = log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE);
105+
String stack = log.getAttributes().get(ExceptionAttributes.EXCEPTION_STACKTRACE);
106106

107107
SamplingOverrides samplingOverrides =
108108
stack != null ? exceptionSamplingOverrides : logSamplingOverrides;

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiContextCustomizer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import io.opentelemetry.api.trace.Span;
1111
import io.opentelemetry.context.Context;
1212
import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer;
13-
import io.opentelemetry.semconv.SemanticAttributes;
13+
import io.opentelemetry.semconv.UrlAttributes;
14+
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
1415
import java.util.List;
1516
import javax.annotation.Nullable;
1617

@@ -42,7 +43,7 @@ public Context onStart(Context context, R request, Attributes startAttributes) {
4243

4344
String path =
4445
getStableAttribute(
45-
startAttributes, SemanticAttributes.URL_PATH, SemanticAttributes.HTTP_TARGET);
46+
startAttributes, UrlAttributes.URL_PATH, HttpIncubatingAttributes.HTTP_TARGET);
4647

4748
String connectionStringOverride = getConnectionStringOverride(path);
4849
if (connectionStringOverride != null) {

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AzureMonitorLogProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import com.azure.core.util.logging.ClientLogger;
77
import com.azure.monitor.opentelemetry.autoconfigure.implementation.AiSemanticAttributes;
88
import com.azure.monitor.opentelemetry.autoconfigure.implementation.OperationNames;
9-
import com.azure.monitor.opentelemetry.autoconfigure.implementation.SemanticAttributes;
109
import io.opentelemetry.api.trace.Span;
1110
import io.opentelemetry.context.Context;
1211
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
1312
import io.opentelemetry.sdk.internal.AttributesMap;
1413
import io.opentelemetry.sdk.logs.LogRecordProcessor;
1514
import io.opentelemetry.sdk.logs.ReadWriteLogRecord;
1615
import io.opentelemetry.sdk.trace.ReadableSpan;
16+
import io.opentelemetry.semconv.ExceptionAttributes;
1717
import java.lang.reflect.Field;
1818
import javax.annotation.Nullable;
1919

@@ -93,7 +93,7 @@ private static void setAttributeExceptionLogged(Span span, ReadWriteLogRecord lo
9393
// TODO add `getAttribute()` to `ReadWriteLogRecord` upstream
9494
stacktrace =
9595
((AttributesMap) attributesMapField.get(logRecord))
96-
.get(SemanticAttributes.EXCEPTION_STACKTRACE);
96+
.get(ExceptionAttributes.EXCEPTION_STACKTRACE);
9797
}
9898
} catch (Exception e) {
9999
logger.error(e.getMessage(), e);

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import io.opentelemetry.api.common.AttributeKey;
1111
import io.opentelemetry.api.common.Attributes;
1212
import io.opentelemetry.sdk.trace.samplers.Sampler;
13-
import io.opentelemetry.semconv.SemanticAttributes;
13+
import io.opentelemetry.semconv.UrlAttributes;
14+
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
15+
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
1416
import java.util.ArrayList;
1517
import java.util.List;
1618
import java.util.regex.Pattern;
@@ -95,7 +97,7 @@ private boolean matches(
9597

9698
static String getValueIncludingThreadName(
9799
Attributes attributes, AttributeKey<String> attributeKey) {
98-
if (attributeKey.getKey().equals(SemanticAttributes.THREAD_NAME.getKey())) {
100+
if (attributeKey.getKey().equals(ThreadIncubatingAttributes.THREAD_NAME.getKey())) {
99101
return Thread.currentThread().getName();
100102
} else {
101103
return attributes.get(attributeKey);
@@ -143,7 +145,7 @@ private StrictMatcher(String key, String value) {
143145
public boolean test(
144146
Attributes attributes, LazyHttpUrl lazyHttpUrl, LazyHttpTarget lazyHttpTarget) {
145147
String val = MatcherGroup.getValueIncludingThreadName(attributes, key);
146-
if (key.getKey().equals(SemanticAttributes.HTTP_TARGET.getKey())) {
148+
if (key.getKey().equals(HttpIncubatingAttributes.HTTP_TARGET.getKey())) {
147149
val = lazyHttpTarget.get();
148150
}
149151
if (val == null && getHttpUrlKeyOldOrStableSemconv(key)) {
@@ -185,7 +187,7 @@ public boolean test(
185187
@Nullable LazyHttpUrl lazyHttpUrl,
186188
@Nullable LazyHttpTarget lazyHttpTarget) {
187189
String val = MatcherGroup.getValueIncludingThreadName(attributes, key);
188-
if (key.getKey().equals(SemanticAttributes.URL_PATH.getKey())) {
190+
if (key.getKey().equals(UrlAttributes.URL_PATH.getKey())) {
189191
val = lazyHttpTarget.get();
190192
}
191193
if (val == null && getHttpUrlKeyOldOrStableSemconv(key) && lazyHttpUrl != null) {
@@ -236,7 +238,7 @@ public boolean test(
236238
@Nullable LazyHttpUrl lazyHttpUrl,
237239
@Nullable LazyHttpTarget lazyHttpTarget) {
238240
String val = MatcherGroup.getValueIncludingThreadName(attributes, key);
239-
if (key.getKey().equals(SemanticAttributes.HTTP_TARGET.getKey())) {
241+
if (key.getKey().equals(HttpIncubatingAttributes.HTTP_TARGET.getKey())) {
240242
val = lazyHttpTarget.get();
241243
}
242244
if (val == null && getHttpUrlKeyOldOrStableSemconv(key) && lazyHttpUrl != null) {
@@ -267,8 +269,8 @@ private String get() {
267269

268270
private static boolean getHttpUrlKeyOldOrStableSemconv(AttributeKey<String> key) {
269271
String keyString = key.getKey();
270-
return keyString.equals(SemanticAttributes.HTTP_URL.getKey())
271-
|| keyString.equals(SemanticAttributes.URL_FULL.getKey());
272+
return keyString.equals(HttpIncubatingAttributes.HTTP_URL.getKey())
273+
|| keyString.equals(UrlAttributes.URL_FULL.getKey());
272274
}
273275

274276
// this is temporary until semantic attributes stabilize and we make breaking change
@@ -293,9 +295,9 @@ private LazyHttpTarget(Attributes attributes) {
293295

294296
private String get() {
295297
if (!initialized) {
296-
String urlQuery = attributes.get(SemanticAttributes.URL_QUERY);
298+
String urlQuery = attributes.get(UrlAttributes.URL_QUERY);
297299
value =
298-
attributes.get(SemanticAttributes.URL_PATH) + (urlQuery != null ? "?" + urlQuery : "");
300+
attributes.get(UrlAttributes.URL_PATH) + (urlQuery != null ? "?" + urlQuery : "");
299301
initialized = true;
300302
}
301303
return value;

agent/agent-tooling/src/main/java/io/opentelemetry/sdk/metrics/internal/view/MetricView.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package io.opentelemetry.sdk.metrics.internal.view;
55

66
import io.opentelemetry.api.common.AttributeKey;
7-
import io.opentelemetry.semconv.SemanticAttributes;
7+
import io.opentelemetry.semconv.HttpAttributes;
8+
import io.opentelemetry.semconv.ServerAttributes;
9+
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
810
import java.util.HashSet;
911
import java.util.Set;
1012

@@ -41,29 +43,29 @@ boolean isCaptureSynthetic() {
4143

4244
private static Set<AttributeKey<?>> httpClientDurationAttributeKeys() {
4345
Set<AttributeKey<?>> view = new HashSet<>(3);
44-
view.add(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE);
45-
view.add(SemanticAttributes.SERVER_ADDRESS);
46-
view.add(SemanticAttributes.SERVER_PORT);
46+
view.add(HttpAttributes.HTTP_RESPONSE_STATUS_CODE);
47+
view.add(ServerAttributes.SERVER_ADDRESS);
48+
view.add(ServerAttributes.SERVER_PORT);
4749
return view;
4850
}
4951

5052
private static Set<AttributeKey<?>> httpServerDurationAttributeKeys() {
5153
Set<AttributeKey<?>> view = new HashSet<>(1);
52-
view.add(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE);
54+
view.add(HttpAttributes.HTTP_RESPONSE_STATUS_CODE);
5355
return view;
5456
}
5557

5658
private static Set<AttributeKey<?>> rpcClientDurationAttributeKeys() {
5759
Set<AttributeKey<?>> view = new HashSet<>(3);
58-
view.add(SemanticAttributes.RPC_SYSTEM);
59-
view.add(SemanticAttributes.SERVER_ADDRESS);
60-
view.add(SemanticAttributes.SERVER_PORT);
60+
view.add(RpcIncubatingAttributes.RPC_SYSTEM);
61+
view.add(ServerAttributes.SERVER_ADDRESS);
62+
view.add(ServerAttributes.SERVER_PORT);
6163
return view;
6264
}
6365

6466
private static Set<AttributeKey<?>> rpcServerDurationAttributeKeys() {
6567
Set<AttributeKey<?>> view = new HashSet<>(1);
66-
view.add(SemanticAttributes.RPC_SYSTEM);
68+
view.add(RpcIncubatingAttributes.RPC_SYSTEM);
6769
return view;
6870
}
6971
}

agent/agent-tooling/src/main/java/io/opentelemetry/sdk/metrics/internal/view/UserAgents.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
package io.opentelemetry.sdk.metrics.internal.view;
55

66
import io.opentelemetry.api.common.Attributes;
7-
import io.opentelemetry.semconv.SemanticAttributes;
7+
import io.opentelemetry.semconv.UserAgentAttributes;
88

99
final class UserAgents {
1010

1111
static boolean isBot(Attributes attributes) {
12-
String userAgent = attributes.get(SemanticAttributes.USER_AGENT_ORIGINAL);
12+
String userAgent = attributes.get(UserAgentAttributes.USER_AGENT_ORIGINAL);
1313
return userAgent != null && userAgent.contains("AlwaysOn");
1414
}
1515

agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/PreAggregatedMetricsTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
import io.opentelemetry.sdk.metrics.data.MetricData;
4040
import io.opentelemetry.sdk.metrics.internal.view.AiViewRegistry;
4141
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
42-
import io.opentelemetry.semconv.SemanticAttributes;
42+
import io.opentelemetry.semconv.HttpAttributes;
43+
import io.opentelemetry.semconv.ServerAttributes;
44+
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
4345
import java.util.Collection;
4446
import java.util.Comparator;
4547
import java.util.HashMap;
@@ -122,10 +124,10 @@ void generateHttpClientMetrics() {
122124
point
123125
.hasSum(0.15 /* seconds */)
124126
.hasAttributesSatisfying(
125-
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
126-
equalTo(SemanticAttributes.SERVER_PORT, 1234),
127+
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
128+
equalTo(ServerAttributes.SERVER_PORT, 1234),
127129
equalTo(
128-
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200))
130+
HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200))
129131
.hasExemplarsSatisfying(
130132
exemplar ->
131133
exemplar
@@ -151,15 +153,15 @@ void generateRpcClientMetrics() {
151153

152154
Attributes requestAttributes =
153155
Attributes.builder()
154-
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
155-
.put(SemanticAttributes.RPC_SERVICE, "myservice.EchoService")
156-
.put(SemanticAttributes.RPC_METHOD, "exampleMethod")
156+
.put(RpcIncubatingAttributes.RPC_SYSTEM, "grpc")
157+
.put(RpcIncubatingAttributes.RPC_SERVICE, "myservice.EchoService")
158+
.put(RpcIncubatingAttributes.RPC_METHOD, "exampleMethod")
157159
.build();
158160

159161
Attributes responseAttributes1 =
160162
Attributes.builder()
161-
.put(SemanticAttributes.SERVER_ADDRESS, "example.com")
162-
.put(SemanticAttributes.SERVER_PORT, 8080)
163+
.put(ServerAttributes.SERVER_ADDRESS, "example.com")
164+
.put(ServerAttributes.SERVER_PORT, 8080)
163165
.build();
164166

165167
Context parent =
@@ -198,10 +200,10 @@ void generateRpcClientMetrics() {
198200
point
199201
.hasSum(150 /* millis */)
200202
.hasAttributesSatisfying(
201-
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
203+
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "grpc"),
202204
equalTo(
203-
SemanticAttributes.SERVER_ADDRESS, "example.com"),
204-
equalTo(SemanticAttributes.SERVER_PORT, 8080))
205+
ServerAttributes.SERVER_ADDRESS, "example.com"),
206+
equalTo(ServerAttributes.SERVER_PORT, 8080))
205207
.hasExemplarsSatisfying(
206208
exemplar ->
207209
exemplar
@@ -277,7 +279,7 @@ void generateHttpServerMetrics() {
277279
.hasSum(0.15 /* seconds */)
278280
.hasAttributesSatisfying(
279281
equalTo(
280-
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
282+
HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
281283
equalTo(
282284
AttributeKey.booleanKey(
283285
"applicationinsights.internal.is_synthetic"),

agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/TelemetryProcessorMaskingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import io.opentelemetry.sdk.trace.data.LinkData;
2222
import io.opentelemetry.sdk.trace.data.SpanData;
2323
import io.opentelemetry.sdk.trace.data.StatusData;
24-
import io.opentelemetry.semconv.SemanticAttributes;
24+
import io.opentelemetry.semconv.UrlAttributes;
2525
import java.time.Instant;
2626
import java.util.ArrayList;
2727
import java.util.Collections;
@@ -46,7 +46,7 @@ void shouldMaskAttribute() {
4646
.processActions(new RequestSpanData(httpUrl));
4747

4848
Attributes newAttributes = newSpanData.getAttributes();
49-
String newHttpUrlAttributeValue = newAttributes.get(SemanticAttributes.URL_FULL);
49+
String newHttpUrlAttributeValue = newAttributes.get(UrlAttributes.URL_FULL);
5050
assertThat(newHttpUrlAttributeValue)
5151
.isEqualTo("http://localhost:8080/TelemetryProcessors/user/" + mask);
5252
}
@@ -72,7 +72,7 @@ void shouldMaskAttributeWithGroupName() {
7272
.processActions(new RequestSpanData(httpUrl));
7373

7474
Attributes newAttributes = newSpanData.getAttributes();
75-
String newHttpUrlAttributeValue = newAttributes.get(SemanticAttributes.URL_FULL);
75+
String newHttpUrlAttributeValue = newAttributes.get(UrlAttributes.URL_FULL);
7676
assertThat(newHttpUrlAttributeValue).isEqualTo("https://user/" + mask);
7777
}
7878

agent/instrumentation/applicationinsights-web-2.3/src/main/java/io/opentelemetry/javaagent/instrumentation/applicationinsightsweb/UserContextInstrumentation.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package io.opentelemetry.javaagent.instrumentation.applicationinsightsweb;
55

6+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
67
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
78
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
89
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
@@ -11,16 +12,19 @@
1112
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
1213

1314
import com.microsoft.applicationinsights.extensibility.context.UserContext;
15+
import io.opentelemetry.api.common.AttributeKey;
1416
import io.opentelemetry.api.trace.Span;
1517
import io.opentelemetry.instrumentation.api.util.VirtualField;
1618
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1719
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
18-
import io.opentelemetry.semconv.SemanticAttributes;
1920
import net.bytebuddy.asm.Advice;
2021
import net.bytebuddy.description.type.TypeDescription;
2122
import net.bytebuddy.matcher.ElementMatcher;
2223

2324
public class UserContextInstrumentation implements TypeInstrumentation {
25+
26+
public static final AttributeKey<String> ENDUSER_ID = stringKey("enduser.id");
27+
2428
@Override
2529
public ElementMatcher<TypeDescription> typeMatcher() {
2630
return named("com.microsoft.applicationinsights.extensibility.context.UserContext");
@@ -43,7 +47,7 @@ public static void methodEnter(
4347
@Advice.This UserContext userContext, @Advice.Argument(0) String name) {
4448
Span span = VirtualField.find(UserContext.class, Span.class).get(userContext);
4549
if (span != null) {
46-
span.setAttribute(SemanticAttributes.ENDUSER_ID, name);
50+
span.setAttribute(ENDUSER_ID, name);
4751
}
4852
}
4953
}

0 commit comments

Comments
 (0)