Skip to content

Commit

Permalink
[OTel plugin] Add new schema version (#34089)
Browse files Browse the repository at this point in the history
Using the stable 1.23.1 semantic conventions version. Attribute names
are also remapped.

Signed-off-by: Paul Van Eck <[email protected]>
  • Loading branch information
pvaneck authored Feb 12, 2024
1 parent 506bffb commit 3bc2067
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
7 changes: 7 additions & 0 deletions sdk/core/azure-core-tracing-opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

### Breaking Changes

- Remapped certain attributes to converge with OpenTelemetry semantic conventions version `1.23.1` ([#34089](https://github.com/Azure/azure-sdk-for-python/pull/34089)):
- `http.method` -> `http.request.method`
- `http.status_code` -> `http.response.status_code`
- `net.peer.name` -> `server.address`
- `net.peer.port` -> `server.port`
- `http.url` -> `url.full`

### Bugs Fixed

### Other Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class OpenTelemetrySchemaVersion(
): # pylint: disable=enum-must-inherit-case-insensitive-enum-meta

V1_19_0 = "1.19.0"
V1_23_1 = "1.23.1"


class OpenTelemetrySchema:

SUPPORTED_VERSIONS = (OpenTelemetrySchemaVersion.V1_19_0,)
SUPPORTED_VERSIONS = (
OpenTelemetrySchemaVersion.V1_19_0,
OpenTelemetrySchemaVersion.V1_23_1,
)

# Mappings of attributes potentially reported by Azure SDKs to corresponding ones that follow
# OpenTelemetry semantic conventions.
Expand All @@ -28,7 +32,19 @@ class OpenTelemetrySchema:
"http.user_agent": "user_agent.original",
"message_bus.destination": "messaging.destination.name",
"peer.address": "net.peer.name",
}
},
OpenTelemetrySchemaVersion.V1_23_1: {
"x-ms-client-request-id": "az.client_request_id",
"x-ms-request-id": "az.service_request_id",
"http.user_agent": "user_agent.original",
"message_bus.destination": "messaging.destination.name",
"peer.address": "server.address",
"http.method": "http.request.method",
"http.status_code": "http.response.status_code",
"net.peer.name": "server.address",
"net.peer.port": "server.port",
"http.url": "url.full",
},
}

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def on_end(self, span: ReadableSpan) -> None:
for regex in self.EXCLUDED_SPAN_NAMES:
if re.match(regex, span.name):
return
if "url.full" in span.attributes:
for regex in self.EXCLUDED_SPAN_URLS:
if re.match(regex, span.attributes["url.full"]):
return
# Check for the older attribute name as well.
if "http.url" in span.attributes:
for regex in self.EXCLUDED_SPAN_URLS:
if re.match(regex, span.attributes["http.url"]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,23 @@ def test_set_http_attributes(self, tracer):
setattr(response, "status_code", 200)
wrapped_class.set_http_attributes(request)
assert wrapped_class.span_instance.kind == OpenTelemetrySpanKind.CLIENT
assert wrapped_class.span_instance.attributes.get("http.method") == request.method
assert wrapped_class.span_instance.attributes.get("http.request.method") == request.method
assert wrapped_class.span_instance.attributes.get("component") == "http"
assert wrapped_class.span_instance.attributes.get("http.url") == request.url
assert wrapped_class.span_instance.attributes.get("http.status_code") == 504
assert wrapped_class.span_instance.attributes.get("url.full") == request.url
assert wrapped_class.span_instance.attributes.get("http.response.status_code") == 504
assert wrapped_class.span_instance.attributes.get("user_agent.original") is None

request.headers["User-Agent"] = "some user agent"
request.url = "http://foo.bar:8080/path"
wrapped_class.set_http_attributes(request, response)
assert wrapped_class.span_instance.attributes.get("http.status_code") == response.status_code
assert wrapped_class.span_instance.attributes.get("http.response.status_code") == response.status_code
assert wrapped_class.span_instance.attributes.get("user_agent.original") == request.headers.get(
"User-Agent"
)

if wrapped_class.span_instance.attributes.get("net.peer.name"):
assert wrapped_class.span_instance.attributes.get("net.peer.name") == "foo.bar"
assert wrapped_class.span_instance.attributes.get("net.peer.port") == 8080
assert wrapped_class.span_instance.attributes.get("server.address") == "foo.bar"
assert wrapped_class.span_instance.attributes.get("server.port") == 8080

def test_span_kind(self, tracer):
with tracer.start_as_current_span("Root") as parent:
Expand Down

0 comments on commit 3bc2067

Please sign in to comment.