diff --git a/docs/getting_started/tests/test_flask.py b/docs/getting_started/tests/test_flask.py index 4c0430d0a7e..321098ce97e 100644 --- a/docs/getting_started/tests/test_flask.py +++ b/docs/getting_started/tests/test_flask.py @@ -38,6 +38,6 @@ def test_flask(self): server.terminate() output = str(server.stdout.read()) - self.assertIn('"name": ""', output) + self.assertIn('"name": "HTTP get"', output) self.assertIn('"name": "example-request"', output) self.assertIn('"name": "hello"', output) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/CHANGELOG.md b/instrumentation/opentelemetry-instrumentation-aiohttp-client/CHANGELOG.md index cdbc621d31b..78b989563f3 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/CHANGELOG.md +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- Updating span name to match semantic conventions + ([#972](https://github.com/open-telemetry/opentelemetry-python/pull/972)) + ## Version 0.12b0 Released 2020-08-14 diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py index 2d9b8bd7a58..397d5dc80e9 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py @@ -126,7 +126,7 @@ async def on_request_start( ): http_method = params.method.upper() if trace_config_ctx.span_name is None: - request_span_name = http_method + request_span_name = "HTTP {}".format(http_method) elif callable(trace_config_ctx.span_name): request_span_name = str(trace_config_ctx.span_name(params)) else: diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py index f44e3df2da6..4a48c38ff70 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py @@ -118,7 +118,7 @@ def test_status_codes(self): self.assert_spans( [ ( - "GET", + "HTTP GET", (span_status, None), { "component": "http", @@ -192,7 +192,7 @@ def strip_query_params(url: yarl.URL) -> str: self.assert_spans( [ ( - "GET", + "HTTP GET", (StatusCanonicalCode.OK, None), { "component": "http", @@ -232,7 +232,7 @@ async def do_request(url): self.assert_spans( [ ( - "GET", + "HTTP GET", (expected_status, None), { "component": "http", @@ -260,7 +260,7 @@ async def request_handler(request): self.assert_spans( [ ( - "GET", + "HTTP GET", (StatusCanonicalCode.DEADLINE_EXCEEDED, None), { "component": "http", @@ -290,7 +290,7 @@ async def request_handler(request): self.assert_spans( [ ( - "GET", + "HTTP GET", (StatusCanonicalCode.DEADLINE_EXCEEDED, None), { "component": "http", diff --git a/instrumentation/opentelemetry-instrumentation-requests/CHANGELOG.md b/instrumentation/opentelemetry-instrumentation-requests/CHANGELOG.md index 179f0f68771..3f18f6101bc 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 a12f05999e1..e2c54b7f1b0 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 instrumented_request(self, method, url, *args, **kwargs): # 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 instrumented_request(self, method, url, *args, **kwargs): 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 afec0a88d0f..da09118e5bc 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 @@ def test_basic(self): 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 @@ def test_invalid_url(self): self.assertEqual(len(span_list), 1) span = span_list[0] - self.assertTrue(span.name.startswith(" None: """Records an exception as a span event.""" + try: + stacktrace = traceback.format_exc() + except Exception: # pylint: disable=broad-except + # workaround for python 3.4, format_exc can raise + # an AttributeError if the __context__ on + # an exception is None + stacktrace = "Exception occurred on stacktrace formatting" + self.add_event( name="exception", attributes={ "exception.type": exception.__class__.__name__, "exception.message": str(exception), - "exception.stacktrace": traceback.format_exc(), + "exception.stacktrace": stacktrace, }, )