Skip to content

Commit 3bc2067

Browse files
authored
[OTel plugin] Add new schema version (#34089)
Using the stable 1.23.1 semantic conventions version. Attribute names are also remapped. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 506bffb commit 3bc2067

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

sdk/core/azure-core-tracing-opentelemetry/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
### Breaking Changes
88

9+
- Remapped certain attributes to converge with OpenTelemetry semantic conventions version `1.23.1` ([#34089](https://github.com/Azure/azure-sdk-for-python/pull/34089)):
10+
- `http.method` -> `http.request.method`
11+
- `http.status_code` -> `http.response.status_code`
12+
- `net.peer.name` -> `server.address`
13+
- `net.peer.port` -> `server.port`
14+
- `http.url` -> `url.full`
15+
916
### Bugs Fixed
1017

1118
### Other Changes

sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/_schema.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ class OpenTelemetrySchemaVersion(
1313
): # pylint: disable=enum-must-inherit-case-insensitive-enum-meta
1414

1515
V1_19_0 = "1.19.0"
16+
V1_23_1 = "1.23.1"
1617

1718

1819
class OpenTelemetrySchema:
1920

20-
SUPPORTED_VERSIONS = (OpenTelemetrySchemaVersion.V1_19_0,)
21+
SUPPORTED_VERSIONS = (
22+
OpenTelemetrySchemaVersion.V1_19_0,
23+
OpenTelemetrySchemaVersion.V1_23_1,
24+
)
2125

2226
# Mappings of attributes potentially reported by Azure SDKs to corresponding ones that follow
2327
# OpenTelemetry semantic conventions.
@@ -28,7 +32,19 @@ class OpenTelemetrySchema:
2832
"http.user_agent": "user_agent.original",
2933
"message_bus.destination": "messaging.destination.name",
3034
"peer.address": "net.peer.name",
31-
}
35+
},
36+
OpenTelemetrySchemaVersion.V1_23_1: {
37+
"x-ms-client-request-id": "az.client_request_id",
38+
"x-ms-request-id": "az.service_request_id",
39+
"http.user_agent": "user_agent.original",
40+
"message_bus.destination": "messaging.destination.name",
41+
"peer.address": "server.address",
42+
"http.method": "http.request.method",
43+
"http.status_code": "http.response.status_code",
44+
"net.peer.name": "server.address",
45+
"net.peer.port": "server.port",
46+
"http.url": "url.full",
47+
},
3248
}
3349

3450
@classmethod

sdk/core/azure-core-tracing-opentelemetry/samples/sample_custom_span_processor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ def on_end(self, span: ReadableSpan) -> None:
5757
for regex in self.EXCLUDED_SPAN_NAMES:
5858
if re.match(regex, span.name):
5959
return
60+
if "url.full" in span.attributes:
61+
for regex in self.EXCLUDED_SPAN_URLS:
62+
if re.match(regex, span.attributes["url.full"]):
63+
return
64+
# Check for the older attribute name as well.
6065
if "http.url" in span.attributes:
6166
for regex in self.EXCLUDED_SPAN_URLS:
6267
if re.match(regex, span.attributes["http.url"]):

sdk/core/azure-core-tracing-opentelemetry/tests/test_tracing_implementations.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,23 @@ def test_set_http_attributes(self, tracer):
321321
setattr(response, "status_code", 200)
322322
wrapped_class.set_http_attributes(request)
323323
assert wrapped_class.span_instance.kind == OpenTelemetrySpanKind.CLIENT
324-
assert wrapped_class.span_instance.attributes.get("http.method") == request.method
324+
assert wrapped_class.span_instance.attributes.get("http.request.method") == request.method
325325
assert wrapped_class.span_instance.attributes.get("component") == "http"
326-
assert wrapped_class.span_instance.attributes.get("http.url") == request.url
327-
assert wrapped_class.span_instance.attributes.get("http.status_code") == 504
326+
assert wrapped_class.span_instance.attributes.get("url.full") == request.url
327+
assert wrapped_class.span_instance.attributes.get("http.response.status_code") == 504
328328
assert wrapped_class.span_instance.attributes.get("user_agent.original") is None
329329

330330
request.headers["User-Agent"] = "some user agent"
331331
request.url = "http://foo.bar:8080/path"
332332
wrapped_class.set_http_attributes(request, response)
333-
assert wrapped_class.span_instance.attributes.get("http.status_code") == response.status_code
333+
assert wrapped_class.span_instance.attributes.get("http.response.status_code") == response.status_code
334334
assert wrapped_class.span_instance.attributes.get("user_agent.original") == request.headers.get(
335335
"User-Agent"
336336
)
337337

338338
if wrapped_class.span_instance.attributes.get("net.peer.name"):
339-
assert wrapped_class.span_instance.attributes.get("net.peer.name") == "foo.bar"
340-
assert wrapped_class.span_instance.attributes.get("net.peer.port") == 8080
339+
assert wrapped_class.span_instance.attributes.get("server.address") == "foo.bar"
340+
assert wrapped_class.span_instance.attributes.get("server.port") == 8080
341341

342342
def test_span_kind(self, tracer):
343343
with tracer.start_as_current_span("Root") as parent:

0 commit comments

Comments
 (0)