Skip to content

Commit a8edcf6

Browse files
authored
Make span attributes available to sampler in aiohttp_client (#1072)
1 parent 9e53939 commit a8edcf6

File tree

2 files changed

+13
-14
lines changed
  • instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client

2 files changed

+13
-14
lines changed

Diff for: 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))

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,24 @@ async def on_request_start(
180180

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

184194
trace_config_ctx.span = trace_config_ctx.tracer.start_span(
185-
request_span_name,
186-
kind=SpanKind.CLIENT,
195+
request_span_name, kind=SpanKind.CLIENT, attributes=span_attributes
187196
)
188197

189198
if callable(request_hook):
190199
request_hook(trace_config_ctx.span, params)
191200

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-
204201
trace_config_ctx.token = context_api.attach(
205202
trace.set_span_in_context(trace_config_ctx.span)
206203
)

0 commit comments

Comments
 (0)