From 8d061a079ff4bb950286ef40551613170b952009 Mon Sep 17 00:00:00 2001 From: alrex Date: Mon, 17 Aug 2020 23:50:09 -0500 Subject: [PATCH] Span name updated to follow semantic conventions to reduce cardinality (#972) --- .../opentelemetry-instrumentation-requests/CHANGELOG.md | 2 ++ .../src/opentelemetry/instrumentation/requests/__init__.py | 7 ++----- .../tests/test_requests_integration.py | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-requests/CHANGELOG.md b/instrumentation/opentelemetry-instrumentation-requests/CHANGELOG.md index 179f0f687..3f18f6101 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/CHANGELOG.md +++ b/instrumentation/opentelemetry-instrumentation-requests/CHANGELOG.md @@ -8,6 +8,8 @@ Released 2020-08-14 - Change package name to opentelemetry-instrumentation-requests ([#961](https://github.com/open-telemetry/opentelemetry-python/pull/961)) +- Span name reported updated to follow semantic conventions to reduce + cardinality ([#972](https://github.com/open-telemetry/opentelemetry-python/pull/972)) ## 0.7b1 diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index a12f05999..e2c54b7f1 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -80,11 +80,7 @@ def _instrument(tracer_provider=None, span_callback=None): # See # https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-client - try: - parsed_url = urlparse(url) - span_name = parsed_url.path - except ValueError as exc: # Invalid URL - span_name = "".format(exc) + span_name = "HTTP {}".format(method) exception = None @@ -111,6 +107,7 @@ def _instrument(tracer_provider=None, span_callback=None): span.set_status( Status(_exception_to_canonical_code(exception)) ) + span.record_exception(exception) if result is not None: span.set_attribute("http.status_code", result.status_code) diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index afec0a88d..da09118e5 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py @@ -51,7 +51,7 @@ class TestRequestsIntegration(TestBase): span = span_list[0] self.assertIs(span.kind, trace.SpanKind.CLIENT) - self.assertEqual(span.name, "/status/200") + self.assertEqual(span.name, "HTTP get") self.assertEqual( span.attributes, @@ -102,7 +102,7 @@ class TestRequestsIntegration(TestBase): self.assertEqual(len(span_list), 1) span = span_list[0] - self.assertTrue(span.name.startswith("