Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Aug 18, 2020
2 changes: 1 addition & 1 deletion docs/getting_started/tests/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_status_codes(self):
self.assert_spans(
[
(
"GET",
"HTTP GET",
(span_status, None),
{
"component": "http",
Expand Down Expand Up @@ -192,7 +192,7 @@ def strip_query_params(url: yarl.URL) -> str:
self.assert_spans(
[
(
"GET",
"HTTP GET",
(StatusCanonicalCode.OK, None),
{
"component": "http",
Expand Down Expand Up @@ -232,7 +232,7 @@ async def do_request(url):
self.assert_spans(
[
(
"GET",
"HTTP GET",
(expected_status, None),
{
"component": "http",
Expand Down Expand Up @@ -260,7 +260,7 @@ async def request_handler(request):
self.assert_spans(
[
(
"GET",
"HTTP GET",
(StatusCanonicalCode.DEADLINE_EXCEEDED, None),
{
"component": "http",
Expand Down Expand Up @@ -290,7 +290,7 @@ async def request_handler(request):
self.assert_spans(
[
(
"GET",
"HTTP GET",
(StatusCanonicalCode.DEADLINE_EXCEEDED, None),
{
"component": "http",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<Unparsable URL: {}>".format(exc)
span_name = "HTTP {}".format(method)

exception = None

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_invalid_url(self):
self.assertEqual(len(span_list), 1)
span = span_list[0]

self.assertTrue(span.name.startswith("<Unparsable URL"))
self.assertEqual(span.name, "HTTP post")
self.assertEqual(
span.attributes,
{"component": "http", "http.method": "POST", "http.url": url},
Expand Down
10 changes: 9 additions & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,20 @@ def __exit__(

def record_exception(self, exception: Exception) -> 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,
},
)

Expand Down