Skip to content

Commit 7292bee

Browse files
tammy-baylis-swisrikanthccvshalevr
authored
Request Flask attributes passed to Sampler (#1784)
* Request Flask attributes passed to Sampler * Update changelog * Lint * Fix botocore test keyerror * Revert "Fix botocore test keyerror" This reverts commit fd03c55. * botocore test does get_queue_url * Revert "botocore test does get_queue_url" This reverts commit 9530cd2. * Update changelog --------- Co-authored-by: Srikanth Chekuri <[email protected]> Co-authored-by: Shalev Roda <[email protected]>
1 parent f9f7b01 commit 7292bee

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- Make Flask request span attributes available for `start_span`.
13+
([#1784](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1784))
1014
- Fix falcon instrumentation's usage of Span Status to only set the description if the status code is ERROR.
1115
([#1840](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1840))
1216
- Instrument all httpx versions >= 0.18. ([#1748](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1748))

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -375,27 +375,26 @@ def _before_request():
375375
flask_request_environ = flask.request.environ
376376
span_name = get_default_span_name()
377377

378+
attributes = otel_wsgi.collect_request_attributes(
379+
flask_request_environ
380+
)
381+
if flask.request.url_rule:
382+
# For 404 that result from no route found, etc, we
383+
# don't have a url_rule.
384+
attributes[SpanAttributes.HTTP_ROUTE] = flask.request.url_rule.rule
378385
span, token = _start_internal_or_server_span(
379386
tracer=tracer,
380387
span_name=span_name,
381388
start_time=flask_request_environ.get(_ENVIRON_STARTTIME_KEY),
382389
context_carrier=flask_request_environ,
383390
context_getter=otel_wsgi.wsgi_getter,
391+
attributes=attributes,
384392
)
385393

386394
if request_hook:
387395
request_hook(span, flask_request_environ)
388396

389397
if span.is_recording():
390-
attributes = otel_wsgi.collect_request_attributes(
391-
flask_request_environ
392-
)
393-
if flask.request.url_rule:
394-
# For 404 that result from no route found, etc, we
395-
# don't have a url_rule.
396-
attributes[
397-
SpanAttributes.HTTP_ROUTE
398-
] = flask.request.url_rule.rule
399398
for key, value in attributes.items():
400399
span.set_attribute(key, value)
401400
if span.is_recording() and span.kind == trace.SpanKind.SERVER:

0 commit comments

Comments
 (0)