Skip to content

Commit c9709d2

Browse files
author
alrex
authored
Span name updated to follow semantic conventions to reduce cardinality (#972)
1 parent 452be59 commit c9709d2

File tree

8 files changed

+25
-15
lines changed

8 files changed

+25
-15
lines changed

Diff for: docs/getting_started/tests/test_flask.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ def test_flask(self):
3838
server.terminate()
3939

4040
output = str(server.stdout.read())
41-
self.assertIn('"name": ""', output)
41+
self.assertIn('"name": "HTTP get"', output)
4242
self.assertIn('"name": "example-request"', output)
4343
self.assertIn('"name": "hello"', output)

Diff for: instrumentation/opentelemetry-instrumentation-aiohttp-client/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Updating span name to match semantic conventions
6+
([#972](https://github.com/open-telemetry/opentelemetry-python/pull/972))
7+
58
## Version 0.12b0
69

710
Released 2020-08-14

Diff for: instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async def on_request_start(
126126
):
127127
http_method = params.method.upper()
128128
if trace_config_ctx.span_name is None:
129-
request_span_name = http_method
129+
request_span_name = "HTTP {}".format(http_method)
130130
elif callable(trace_config_ctx.span_name):
131131
request_span_name = str(trace_config_ctx.span_name(params))
132132
else:

Diff for: instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_status_codes(self):
118118
self.assert_spans(
119119
[
120120
(
121-
"GET",
121+
"HTTP GET",
122122
(span_status, None),
123123
{
124124
"component": "http",
@@ -192,7 +192,7 @@ def strip_query_params(url: yarl.URL) -> str:
192192
self.assert_spans(
193193
[
194194
(
195-
"GET",
195+
"HTTP GET",
196196
(StatusCanonicalCode.OK, None),
197197
{
198198
"component": "http",
@@ -232,7 +232,7 @@ async def do_request(url):
232232
self.assert_spans(
233233
[
234234
(
235-
"GET",
235+
"HTTP GET",
236236
(expected_status, None),
237237
{
238238
"component": "http",
@@ -260,7 +260,7 @@ async def request_handler(request):
260260
self.assert_spans(
261261
[
262262
(
263-
"GET",
263+
"HTTP GET",
264264
(StatusCanonicalCode.DEADLINE_EXCEEDED, None),
265265
{
266266
"component": "http",
@@ -290,7 +290,7 @@ async def request_handler(request):
290290
self.assert_spans(
291291
[
292292
(
293-
"GET",
293+
"HTTP GET",
294294
(StatusCanonicalCode.DEADLINE_EXCEEDED, None),
295295
{
296296
"component": "http",

Diff for: instrumentation/opentelemetry-instrumentation-requests/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Released 2020-08-14
88

99
- Change package name to opentelemetry-instrumentation-requests
1010
([#961](https://github.com/open-telemetry/opentelemetry-python/pull/961))
11+
- Span name reported updated to follow semantic conventions to reduce
12+
cardinality ([#972](https://github.com/open-telemetry/opentelemetry-python/pull/972))
1113

1214
## 0.7b1
1315

Diff for: instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ def instrumented_request(self, method, url, *args, **kwargs):
8080

8181
# See
8282
# https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-client
83-
try:
84-
parsed_url = urlparse(url)
85-
span_name = parsed_url.path
86-
except ValueError as exc: # Invalid URL
87-
span_name = "<Unparsable URL: {}>".format(exc)
83+
span_name = "HTTP {}".format(method)
8884

8985
exception = None
9086

@@ -111,6 +107,7 @@ def instrumented_request(self, method, url, *args, **kwargs):
111107
span.set_status(
112108
Status(_exception_to_canonical_code(exception))
113109
)
110+
span.record_exception(exception)
114111

115112
if result is not None:
116113
span.set_attribute("http.status_code", result.status_code)

Diff for: instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_basic(self):
5151
span = span_list[0]
5252

5353
self.assertIs(span.kind, trace.SpanKind.CLIENT)
54-
self.assertEqual(span.name, "/status/200")
54+
self.assertEqual(span.name, "HTTP get")
5555

5656
self.assertEqual(
5757
span.attributes,
@@ -102,7 +102,7 @@ def test_invalid_url(self):
102102
self.assertEqual(len(span_list), 1)
103103
span = span_list[0]
104104

105-
self.assertTrue(span.name.startswith("<Unparsable URL"))
105+
self.assertEqual(span.name, "HTTP post")
106106
self.assertEqual(
107107
span.attributes,
108108
{"component": "http", "http.method": "POST", "http.url": url},

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,20 @@ def __exit__(
685685

686686
def record_exception(self, exception: Exception) -> None:
687687
"""Records an exception as a span event."""
688+
try:
689+
stacktrace = traceback.format_exc()
690+
except Exception: # pylint: disable=broad-except
691+
# workaround for python 3.4, format_exc can raise
692+
# an AttributeError if the __context__ on
693+
# an exception is None
694+
stacktrace = "Exception occurred on stacktrace formatting"
695+
688696
self.add_event(
689697
name="exception",
690698
attributes={
691699
"exception.type": exception.__class__.__name__,
692700
"exception.message": str(exception),
693-
"exception.stacktrace": traceback.format_exc(),
701+
"exception.stacktrace": stacktrace,
694702
},
695703
)
696704

0 commit comments

Comments
 (0)