Skip to content

store the URL of instrumented requests/urllib3 spans in the correct place #394

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elasticapm/instrumentation/packages/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ def call(self, module, method, wrapped, instance, args, kwargs):
signature = request.method.upper()
signature += " " + get_host_from_url(request.url)

with capture_span(signature, "ext.http.requests", {"url": request.url}, leaf=True):
with capture_span(signature, "ext.http.requests", {"http": {"url": request.url}}, leaf=True):
return wrapped(*args, **kwargs)
2 changes: 1 addition & 1 deletion elasticapm/instrumentation/packages/urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def call(self, module, method, wrapped, instance, args, kwargs):
url = instance.scheme + "://" + host + url
transaction = execution_context.get_transaction()

with capture_span(signature, "ext.http.urllib3", {"url": url}, leaf=True) as span:
with capture_span(signature, "ext.http.urllib3", {"http": {"url": url}}, leaf=True) as span:
# if urllib3 has been called in a leaf span, this span might be a DroppedSpan.
leaf_span = span
while isinstance(leaf_span, DroppedSpan):
Expand Down
6 changes: 3 additions & 3 deletions tests/instrumentation/requests_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_requests_instrumentation(instrument, elasticapm_client, waiting_httpser
transactions = elasticapm_client.events[TRANSACTION]
spans = elasticapm_client.spans_for_transaction(transactions[0])
assert spans[0]["name"].startswith("GET 127.0.0.1:")
assert url == spans[0]["context"]["url"]
assert url == spans[0]["context"]["http"]["url"]

assert constants.TRACEPARENT_HEADER_NAME in waiting_httpserver.requests[0].headers
trace_parent = TraceParent.from_string(waiting_httpserver.requests[0].headers[constants.TRACEPARENT_HEADER_NAME])
Expand All @@ -47,7 +47,7 @@ def test_requests_instrumentation_via_session(instrument, elasticapm_client, wai
transactions = elasticapm_client.events[TRANSACTION]
spans = elasticapm_client.spans_for_transaction(transactions[0])
assert spans[0]["name"].startswith("GET 127.0.0.1:")
assert url == spans[0]["context"]["url"]
assert url == spans[0]["context"]["http"]["url"]

assert constants.TRACEPARENT_HEADER_NAME in waiting_httpserver.requests[0].headers
trace_parent = TraceParent.from_string(waiting_httpserver.requests[0].headers[constants.TRACEPARENT_HEADER_NAME])
Expand All @@ -72,7 +72,7 @@ def test_requests_instrumentation_via_prepared_request(instrument, elasticapm_cl
transactions = elasticapm_client.events[TRANSACTION]
spans = elasticapm_client.spans_for_transaction(transactions[0])
assert spans[0]["name"].startswith("GET 127.0.0.1:")
assert url == spans[0]["context"]["url"]
assert url == spans[0]["context"]["http"]["url"]

assert constants.TRACEPARENT_HEADER_NAME in waiting_httpserver.requests[0].headers
trace_parent = TraceParent.from_string(waiting_httpserver.requests[0].headers[constants.TRACEPARENT_HEADER_NAME])
Expand Down
2 changes: 1 addition & 1 deletion tests/instrumentation/urllib3_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_urllib3(instrument, elasticapm_client, waiting_httpserver):

assert spans[0]["name"] == expected_sig
assert spans[0]["type"] == "ext.http.urllib3"
assert spans[0]["context"]["url"] == url
assert spans[0]["context"]["http"]["url"] == url
assert spans[0]["parent_id"] == spans[1]["id"]

assert spans[1]["name"] == "test_name"
Expand Down