diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bcd1ecf2a..7e64c650ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD) ### Fixed +- `opentelemetry-instrumentation-aiohttp-client` make span attributes available to sampler - `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test) headers are set to None, breaking context propagators. ([#1055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1055)) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py index 515bd126c4..ec720b5700 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py @@ -180,27 +180,22 @@ async def on_request_start( http_method = params.method.upper() request_span_name = f"HTTP {http_method}" + 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)), + + span_attributes = { + SpanAttributes.HTTP_METHOD: http_method, + SpanAttributes.HTTP_URL: request_url, + } trace_config_ctx.span = trace_config_ctx.tracer.start_span( request_span_name, kind=SpanKind.CLIENT, + attributes=span_attributes ) if callable(request_hook): request_hook(trace_config_ctx.span, params) - if trace_config_ctx.span.is_recording(): - attributes = { - SpanAttributes.HTTP_METHOD: http_method, - SpanAttributes.HTTP_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)), - } - for key, value in attributes.items(): - trace_config_ctx.span.set_attribute(key, value) - trace_config_ctx.token = context_api.attach( trace.set_span_in_context(trace_config_ctx.span) )