From ff3a2fba573a08e81999cbbb2958e6d86aa681da Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 4 May 2023 13:51:46 -0700 Subject: [PATCH 1/8] Request Flask attributes passed to Sampler --- .../instrumentation/flask/__init__.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index fd3c40aab3..cd0f162a38 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -364,27 +364,28 @@ def _before_request(): flask_request_environ = flask.request.environ span_name = get_default_span_name() + attributes = otel_wsgi.collect_request_attributes( + flask_request_environ + ) + if flask.request.url_rule: + # For 404 that result from no route found, etc, we + # don't have a url_rule. + attributes[ + SpanAttributes.HTTP_ROUTE + ] = flask.request.url_rule.rule span, token = _start_internal_or_server_span( tracer=tracer, span_name=span_name, start_time=flask_request_environ.get(_ENVIRON_STARTTIME_KEY), context_carrier=flask_request_environ, context_getter=otel_wsgi.wsgi_getter, + attributes=attributes, ) if request_hook: request_hook(span, flask_request_environ) if span.is_recording(): - attributes = otel_wsgi.collect_request_attributes( - flask_request_environ - ) - if flask.request.url_rule: - # For 404 that result from no route found, etc, we - # don't have a url_rule. - attributes[ - SpanAttributes.HTTP_ROUTE - ] = flask.request.url_rule.rule for key, value in attributes.items(): span.set_attribute(key, value) if span.is_recording() and span.kind == trace.SpanKind.SERVER: From a7839be8dfe07227230b5e43b8b514c61b30ebf0 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 4 May 2023 13:58:14 -0700 Subject: [PATCH 2/8] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ead8d5c134..6bcb4cf5a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1407](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1407)) - `opentelemetry-instrumentation-logging` Add `otelTraceSampled` to instrumetation-logging ([#1773](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1773)) +- Make Flask request span attributes available for `start_span`. + ([#1784](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1784)) ### Fixed From f73199943bec04e175553ba307ee21576173d6a1 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 4 May 2023 14:54:47 -0700 Subject: [PATCH 3/8] Lint --- .../src/opentelemetry/instrumentation/flask/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index cd0f162a38..b30fa81273 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -370,9 +370,7 @@ def _before_request(): if flask.request.url_rule: # For 404 that result from no route found, etc, we # don't have a url_rule. - attributes[ - SpanAttributes.HTTP_ROUTE - ] = flask.request.url_rule.rule + attributes[SpanAttributes.HTTP_ROUTE] = flask.request.url_rule.rule span, token = _start_internal_or_server_span( tracer=tracer, span_name=span_name, From fd03c55a3902b3456afd6a2ecf429afba11b0691 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 4 May 2023 15:11:03 -0700 Subject: [PATCH 4/8] Fix botocore test keyerror --- .../tests/test_botocore_instrumentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 9a5d8429b5..012f0a4846 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -196,7 +196,7 @@ def test_sqs_send_message(self): ) self.memory_exporter.clear() - queue_url = response["QueueUrl"] + queue_url = response.get("QueueUrl") sqs.send_message(QueueUrl=queue_url, MessageBody="Test SQS MESSAGE!") self.assert_span( From 09c3c1f74efb1fd0e74d55224e29ba38a6f499d8 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 4 May 2023 15:34:18 -0700 Subject: [PATCH 5/8] Revert "Fix botocore test keyerror" This reverts commit fd03c55a3902b3456afd6a2ecf429afba11b0691. --- .../tests/test_botocore_instrumentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 012f0a4846..9a5d8429b5 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -196,7 +196,7 @@ def test_sqs_send_message(self): ) self.memory_exporter.clear() - queue_url = response.get("QueueUrl") + queue_url = response["QueueUrl"] sqs.send_message(QueueUrl=queue_url, MessageBody="Test SQS MESSAGE!") self.assert_span( From 9530cd250dd836b3181a9361decb130e2aae1202 Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 4 May 2023 15:49:38 -0700 Subject: [PATCH 6/8] botocore test does get_queue_url --- .../tests/test_botocore_instrumentation.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 9a5d8429b5..da97075b82 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -190,13 +190,18 @@ def test_sqs_send_message(self): sqs = self._make_client("sqs") test_queue_name = "test_queue_name" - response = sqs.create_queue(QueueName=test_queue_name) + sqs.create_queue(QueueName=test_queue_name) self.assert_span( "SQS", "CreateQueue", request_id=_REQUEST_ID_REGEX_MATCH ) self.memory_exporter.clear() + response = sqs.get_queue_url( + QueueName=test_queue_name, + ) queue_url = response["QueueUrl"] + self.memory_exporter.clear() + sqs.send_message(QueueUrl=queue_url, MessageBody="Test SQS MESSAGE!") self.assert_span( From 64130631600fcc640a7964a83271eebe0067734a Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 4 May 2023 16:01:49 -0700 Subject: [PATCH 7/8] Revert "botocore test does get_queue_url" This reverts commit 9530cd250dd836b3181a9361decb130e2aae1202. --- .../tests/test_botocore_instrumentation.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index da97075b82..9a5d8429b5 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -190,18 +190,13 @@ def test_sqs_send_message(self): sqs = self._make_client("sqs") test_queue_name = "test_queue_name" - sqs.create_queue(QueueName=test_queue_name) + response = sqs.create_queue(QueueName=test_queue_name) self.assert_span( "SQS", "CreateQueue", request_id=_REQUEST_ID_REGEX_MATCH ) self.memory_exporter.clear() - response = sqs.get_queue_url( - QueueName=test_queue_name, - ) queue_url = response["QueueUrl"] - self.memory_exporter.clear() - sqs.send_message(QueueUrl=queue_url, MessageBody="Test SQS MESSAGE!") self.assert_span( From 96bf758a8005d90b06b3b63980f4b7b0a2d461dc Mon Sep 17 00:00:00 2001 From: tammy-baylis-swi Date: Thu, 18 May 2023 09:49:47 -0700 Subject: [PATCH 8/8] Update changelog --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e1c66786b..eeb93e1b51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Make Flask request span attributes available for `start_span`. + ([#1784](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1784)) + ## Version 1.18.0/0.39b0 (2023-05-10) - `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735)) @@ -29,8 +34,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1407](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1407)) - `opentelemetry-instrumentation-logging` Add `otelTraceSampled` to instrumetation-logging ([#1773](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1773)) -- Make Flask request span attributes available for `start_span`. - ([#1784](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1784)) ### Fixed