Span name updated to follow semantic conventions to reduce cardinality (#972)

This commit is contained in:
alrex 2020-08-17 23:50:09 -05:00 committed by GitHub
parent 4586624567
commit 8d061a079f
3 changed files with 6 additions and 7 deletions

View File

@ -8,6 +8,8 @@ Released 2020-08-14
- Change package name to opentelemetry-instrumentation-requests - Change package name to opentelemetry-instrumentation-requests
([#961](https://github.com/open-telemetry/opentelemetry-python/pull/961)) ([#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 ## 0.7b1

View File

@ -80,11 +80,7 @@ def _instrument(tracer_provider=None, span_callback=None):
# See # See
# https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-client # https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-client
try: span_name = "HTTP {}".format(method)
parsed_url = urlparse(url)
span_name = parsed_url.path
except ValueError as exc: # Invalid URL
span_name = "<Unparsable URL: {}>".format(exc)
exception = None exception = None
@ -111,6 +107,7 @@ def _instrument(tracer_provider=None, span_callback=None):
span.set_status( span.set_status(
Status(_exception_to_canonical_code(exception)) Status(_exception_to_canonical_code(exception))
) )
span.record_exception(exception)
if result is not None: if result is not None:
span.set_attribute("http.status_code", result.status_code) span.set_attribute("http.status_code", result.status_code)

View File

@ -51,7 +51,7 @@ class TestRequestsIntegration(TestBase):
span = span_list[0] span = span_list[0]
self.assertIs(span.kind, trace.SpanKind.CLIENT) self.assertIs(span.kind, trace.SpanKind.CLIENT)
self.assertEqual(span.name, "/status/200") self.assertEqual(span.name, "HTTP get")
self.assertEqual( self.assertEqual(
span.attributes, span.attributes,
@ -102,7 +102,7 @@ class TestRequestsIntegration(TestBase):
self.assertEqual(len(span_list), 1) self.assertEqual(len(span_list), 1)
span = span_list[0] span = span_list[0]
self.assertTrue(span.name.startswith("<Unparsable URL")) self.assertEqual(span.name, "HTTP post")
self.assertEqual( self.assertEqual(
span.attributes, span.attributes,
{"component": "http", "http.method": "POST", "http.url": url}, {"component": "http", "http.method": "POST", "http.url": url},