Skip to content

Commit 9ef0cac

Browse files
Merge branch 'main' into HLS-3903
2 parents dcbd72f + 1dd17ed commit 9ef0cac

File tree

55 files changed

+667
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+667
-439
lines changed

CHANGELOG.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
11+
### Added
12+
13+
- Make Flask request span attributes available for `start_span`.
14+
([#1784](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1784))
15+
- Fix falcon instrumentation's usage of Span Status to only set the description if the status code is ERROR.
16+
([#1840](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1840))
17+
- Instrument all httpx versions >= 0.18. ([#1748](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1748))
18+
- Fix `Invalid type NoneType for attribute X (opentelemetry-instrumentation-aws-lambda)` error when some attributes do not exist
19+
([#1780](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1780))
20+
- Add metric instrumentation for celery
21+
([#1679](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1679))
22+
1023
## Version 1.18.0/0.39b0 (2023-05-10)
1124

1225
- `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735))
@@ -23,9 +36,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2336
([#1778](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1778))
2437
- Add `excluded_urls` functionality to `urllib` and `urllib3` instrumentations
2538
([#1733](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1733))
26-
- Make Django request span attributes available for `start_span`.
39+
- Make Django request span attributes available for `start_span`.
2740
([#1730](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1730))
28-
- Make ASGI request span attributes available for `start_span`.
41+
- Make ASGI request span attributes available for `start_span`.
2942
([#1762](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1762))
3043
- `opentelemetry-instrumentation-celery` Add support for anonymous tasks.
3144
([#1407](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1407))
@@ -40,12 +53,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4053

4154
### Fixed
4255

56+
- Fix redis db.statements to be sanitized by default
57+
([#1778](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1778))
4358
- Fix elasticsearch db.statement attribute to be sanitized by default
4459
([#1758](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1758))
4560
- Fix `AttributeError` when AWS Lambda handler receives a list event
4661
([#1738](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1738))
4762
- Fix `None does not implement middleware` error when there are no middlewares registered
4863
([#1766](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1766))
64+
- Fix Flask instrumentation to only close the span if it was created by the same request context.
65+
([#1692](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1692))
66+
67+
### Changed
68+
- Update HTTP server/client instrumentation span names to comply with spec
69+
([#1759](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1759)
4970

5071
## Version 1.17.0/0.38b0 (2023-03-22)
5172

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bleach==4.1.0 # transient dependency for readme-renderer
1414
grpcio-tools==1.29.0
1515
mypy-protobuf>=1.23
1616
protobuf~=3.13
17-
markupsafe==2.0.1
17+
markupsafe>=2.0.1
1818
codespell==2.1.0
1919
requests==2.28.1
2020
ruamel.yaml==0.17.21

instrumentation/opentelemetry-instrumentation-aiohttp-client/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ instruments = [
3838
]
3939
test = [
4040
"opentelemetry-instrumentation-aiohttp-client[instruments]",
41+
"http-server-mock"
4142
]
4243

4344
[project.entry-points.opentelemetry_instrumentor]

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async def on_request_start(
179179
return
180180

181181
http_method = params.method.upper()
182-
request_span_name = f"HTTP {http_method}"
182+
request_span_name = f"{http_method}"
183183
request_url = (
184184
remove_url_credentials(trace_config_ctx.url_filter(params.url))
185185
if callable(trace_config_ctx.url_filter)

instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import aiohttp
2424
import aiohttp.test_utils
2525
import yarl
26+
from http_server_mock import HttpServerMock
2627
from pkg_resources import iter_entry_points
2728

2829
from opentelemetry import context
@@ -118,7 +119,7 @@ def test_status_codes(self):
118119
self.assert_spans(
119120
[
120121
(
121-
"HTTP GET",
122+
"GET",
122123
(span_status, None),
123124
{
124125
SpanAttributes.HTTP_METHOD: "GET",
@@ -212,7 +213,7 @@ def strip_query_params(url: yarl.URL) -> str:
212213
self.assert_spans(
213214
[
214215
(
215-
"HTTP GET",
216+
"GET",
216217
(StatusCode.UNSET, None),
217218
{
218219
SpanAttributes.HTTP_METHOD: "GET",
@@ -246,7 +247,7 @@ async def do_request(url):
246247
self.assert_spans(
247248
[
248249
(
249-
"HTTP GET",
250+
"GET",
250251
(expected_status, None),
251252
{
252253
SpanAttributes.HTTP_METHOD: "GET",
@@ -273,7 +274,7 @@ async def request_handler(request):
273274
self.assert_spans(
274275
[
275276
(
276-
"HTTP GET",
277+
"GET",
277278
(StatusCode.ERROR, None),
278279
{
279280
SpanAttributes.HTTP_METHOD: "GET",
@@ -300,7 +301,7 @@ async def request_handler(request):
300301
self.assert_spans(
301302
[
302303
(
303-
"HTTP GET",
304+
"GET",
304305
(StatusCode.ERROR, None),
305306
{
306307
SpanAttributes.HTTP_METHOD: "GET",
@@ -313,27 +314,37 @@ async def request_handler(request):
313314
def test_credential_removal(self):
314315
trace_configs = [aiohttp_client.create_trace_config()]
315316

316-
url = "http://username:[email protected]/status/200"
317-
with self.subTest(url=url):
317+
app = HttpServerMock("test_credential_removal")
318318

319-
async def do_request(url):
320-
async with aiohttp.ClientSession(
321-
trace_configs=trace_configs,
322-
) as session:
323-
async with session.get(url):
324-
pass
319+
@app.route("/status/200")
320+
def index():
321+
return "hello"
325322

326-
loop = asyncio.get_event_loop()
327-
loop.run_until_complete(do_request(url))
323+
url = "http://username:password@localhost:5000/status/200"
324+
325+
with app.run("localhost", 5000):
326+
with self.subTest(url=url):
327+
328+
async def do_request(url):
329+
async with aiohttp.ClientSession(
330+
trace_configs=trace_configs,
331+
) as session:
332+
async with session.get(url):
333+
pass
334+
335+
loop = asyncio.get_event_loop()
336+
loop.run_until_complete(do_request(url))
328337

329338
self.assert_spans(
330339
[
331340
(
332-
"HTTP GET",
341+
"GET",
333342
(StatusCode.UNSET, None),
334343
{
335344
SpanAttributes.HTTP_METHOD: "GET",
336-
SpanAttributes.HTTP_URL: "http://httpbin.org/status/200",
345+
SpanAttributes.HTTP_URL: (
346+
"http://localhost:5000/status/200"
347+
),
337348
SpanAttributes.HTTP_STATUS_CODE: int(HTTPStatus.OK),
338349
},
339350
)
@@ -380,6 +391,7 @@ def test_instrument(self):
380391
self.get_default_request(), self.URL, self.default_handler
381392
)
382393
span = self.assert_spans(1)
394+
self.assertEqual("GET", span.name)
383395
self.assertEqual("GET", span.attributes[SpanAttributes.HTTP_METHOD])
384396
self.assertEqual(
385397
f"http://{host}:{port}/test-path",

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,18 +415,23 @@ def set_status_code(span, status_code):
415415

416416

417417
def get_default_span_details(scope: dict) -> Tuple[str, dict]:
418-
"""Default implementation for get_default_span_details
418+
"""
419+
Default span name is the HTTP method and URL path, or just the method.
420+
https://github.com/open-telemetry/opentelemetry-specification/pull/3165
421+
https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/#name
422+
419423
Args:
420424
scope: the ASGI scope dictionary
421425
Returns:
422426
a tuple of the span name, and any attributes to attach to the span.
423427
"""
424-
span_name = (
425-
scope.get("path", "").strip()
426-
or f"HTTP {scope.get('method', '').strip()}"
427-
)
428-
429-
return span_name, {}
428+
path = scope.get("path", "").strip()
429+
method = scope.get("method", "").strip()
430+
if method and path: # http
431+
return f"{method} {path}", {}
432+
if path: # websocket
433+
return path, {}
434+
return method, {} # http with no path
430435

431436

432437
def _collect_target_attribute(

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,25 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
142142
self.assertEqual(len(span_list), 4)
143143
expected = [
144144
{
145-
"name": "/ http receive",
145+
"name": "GET / http receive",
146146
"kind": trace_api.SpanKind.INTERNAL,
147147
"attributes": {"type": "http.request"},
148148
},
149149
{
150-
"name": "/ http send",
150+
"name": "GET / http send",
151151
"kind": trace_api.SpanKind.INTERNAL,
152152
"attributes": {
153153
SpanAttributes.HTTP_STATUS_CODE: 200,
154154
"type": "http.response.start",
155155
},
156156
},
157157
{
158-
"name": "/ http send",
158+
"name": "GET / http send",
159159
"kind": trace_api.SpanKind.INTERNAL,
160160
"attributes": {"type": "http.response.body"},
161161
},
162162
{
163-
"name": "/",
163+
"name": "GET /",
164164
"kind": trace_api.SpanKind.SERVER,
165165
"attributes": {
166166
SpanAttributes.HTTP_METHOD: "GET",
@@ -231,7 +231,7 @@ def update_expected_span_name(expected):
231231
entry["name"] = span_name
232232
else:
233233
entry["name"] = " ".join(
234-
[span_name] + entry["name"].split(" ")[1:]
234+
[span_name] + entry["name"].split(" ")[2:]
235235
)
236236
return expected
237237

@@ -493,9 +493,9 @@ def update_expected_hook_results(expected):
493493
for entry in expected:
494494
if entry["kind"] == trace_api.SpanKind.SERVER:
495495
entry["name"] = "name from server hook"
496-
elif entry["name"] == "/ http receive":
496+
elif entry["name"] == "GET / http receive":
497497
entry["name"] = "name from client request hook"
498-
elif entry["name"] == "/ http send":
498+
elif entry["name"] == "GET / http send":
499499
entry["attributes"].update({"attr-from-hook": "value"})
500500
return expected
501501

@@ -705,11 +705,11 @@ def test_response_attributes_invalid_status_code(self):
705705
self.assertEqual(self.span.set_status.call_count, 1)
706706

707707
def test_credential_removal(self):
708-
self.scope["server"] = ("username:password@httpbin.org", 80)
708+
self.scope["server"] = ("username:password@mock", 80)
709709
self.scope["path"] = "/status/200"
710710
attrs = otel_asgi.collect_request_attributes(self.scope)
711711
self.assertEqual(
712-
attrs[SpanAttributes.HTTP_URL], "http://httpbin.org/status/200"
712+
attrs[SpanAttributes.HTTP_URL], "http://mock/status/200"
713713
)
714714

715715
def test_collect_target_attribute_missing(self):

0 commit comments

Comments
 (0)