Skip to content

Commit 295a6cb

Browse files
committed
Make span attributes available in aiohttp-client
Fixes opentelemetry-python-contrib#939
1 parent 9e53939 commit 295a6cb

File tree

2 files changed

+9
-12
lines changed
  • instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client

2 files changed

+9
-12
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD)
99

1010
### Fixed
11+
- `opentelemetry-instrumentation-aiohttp-client` make span attributes available to sampler
12+
([1072](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1072))
1113
- `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test)
1214
headers are set to None, breaking context propagators.
1315
([#1055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1055))

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

+7-12
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,22 @@ async def on_request_start(
180180

181181
http_method = params.method.upper()
182182
request_span_name = f"HTTP {http_method}"
183+
request_url = remove_url_credentials(trace_config_ctx.url_filter(params.url)) if callable(trace_config_ctx.url_filter) else remove_url_credentials(str(params.url)),
184+
185+
span_attributes = {
186+
SpanAttributes.HTTP_METHOD: http_method,
187+
SpanAttributes.HTTP_URL: request_url,
188+
}
183189

184190
trace_config_ctx.span = trace_config_ctx.tracer.start_span(
185191
request_span_name,
186192
kind=SpanKind.CLIENT,
193+
attributes=span_attributes
187194
)
188195

189196
if callable(request_hook):
190197
request_hook(trace_config_ctx.span, params)
191198

192-
if trace_config_ctx.span.is_recording():
193-
attributes = {
194-
SpanAttributes.HTTP_METHOD: http_method,
195-
SpanAttributes.HTTP_URL: remove_url_credentials(
196-
trace_config_ctx.url_filter(params.url)
197-
)
198-
if callable(trace_config_ctx.url_filter)
199-
else remove_url_credentials(str(params.url)),
200-
}
201-
for key, value in attributes.items():
202-
trace_config_ctx.span.set_attribute(key, value)
203-
204199
trace_config_ctx.token = context_api.attach(
205200
trace.set_span_in_context(trace_config_ctx.span)
206201
)

0 commit comments

Comments
 (0)