From 86a5638887e316201b5bfde09a6855c6db388caa Mon Sep 17 00:00:00 2001 From: Leighton Date: Fri, 25 Sep 2020 11:06:20 -0400 Subject: [PATCH 1/7] flask --- .../instrumentation/flask/__init__.py | 15 +++++++++------ .../tests/test_programmatic.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 7 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 d1936b1cd36..90082dd850e 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -119,17 +119,20 @@ def _before_request(): tracer = trace.get_tracer(__name__, __version__) - attributes = otel_wsgi.collect_request_attributes(environ) - if flask.request.url_rule: - # For 404 that result from no route found, etc, we - # don't have a url_rule. - attributes["http.route"] = flask.request.url_rule.rule span = tracer.start_span( span_name, kind=trace.SpanKind.SERVER, - attributes=attributes, start_time=environ.get(_ENVIRON_STARTTIME_KEY), ) + if span.is_recording(): + attributes = otel_wsgi.collect_request_attributes(environ) + if flask.request.url_rule: + # For 404 that result from no route found, etc, we + # don't have a url_rule. + attributes["http.route"] = flask.request.url_rule.rule + for key, value in attributes.items(): + span.set_attribute(key, value) + activation = tracer.use_span(span, end_on_exit=True) activation.__enter__() environ[_ENVIRON_ACTIVATION_KEY] = activation diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index 181f4e1e61e..46861bd6812 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from unittest.mock import patch +from unittest.mock import Mock, patch from flask import Flask, request @@ -106,6 +106,21 @@ def test_simple(self): self.assertEqual(span_list[0].kind, trace.SpanKind.SERVER) self.assertEqual(span_list[0].attributes, expected_attrs) + def test_not_recording(self): + mock_tracer = Mock() + mock_span = Mock() + mock_span.is_recording.return_value = False + mock_tracer.start_span.return_value = mock_span + mock_tracer.use_span.return_value.__enter__ = mock_span + mock_tracer.use_span.return_value.__exit__ = mock_span + with patch("opentelemetry.trace.get_tracer") as tracer: + tracer.return_value = mock_tracer + self.client.get("/hello/123") + self.assertFalse(mock_span.is_recording()) + self.assertTrue(mock_span.is_recording.called) + self.assertFalse(mock_span.set_attribute.called) + self.assertFalse(mock_span.set_status.called) + def test_404(self): expected_attrs = expected_attributes( { From 31f03789ee62cb3d01763b62004bc91d78b00ae7 Mon Sep 17 00:00:00 2001 From: Leighton Date: Fri, 25 Sep 2020 11:21:59 -0400 Subject: [PATCH 2/7] falcon, django --- .../instrumentation/django/middleware.py | 8 +++++--- .../tests/test_middleware.py | 17 ++++++++++++++++- .../instrumentation/tornado/client.py | 14 +++++++++----- .../tests/test_instrumentation.py | 17 ++++++++++++++++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py index 59f7e6e6229..d3e7d7842c7 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py @@ -94,17 +94,19 @@ def process_request(self, request): tracer = get_tracer(__name__, __version__) - attributes = collect_request_attributes(environ) - span = tracer.start_span( self._get_span_name(request), kind=SpanKind.SERVER, - attributes=attributes, start_time=environ.get( "opentelemetry-instrumentor-django.starttime_key" ), ) + if span.is_recording(): + attributes = collect_request_attributes(environ) + for key, value in attributes.items(): + span.set_attribute(key, value) + activation = tracer.use_span(span, end_on_exit=True) activation.__enter__() diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py index ee82c5d7d9f..7764b1d400c 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py @@ -13,7 +13,7 @@ # limitations under the License. from sys import modules -from unittest.mock import patch +from unittest.mock import Mock, patch from django import VERSION from django.conf import settings @@ -89,6 +89,21 @@ def test_traced_get(self): self.assertEqual(span.attributes["http.status_code"], 200) self.assertEqual(span.attributes["http.status_text"], "OK") + def test_not_recording(self): + mock_tracer = Mock() + mock_span = Mock() + mock_span.is_recording.return_value = False + mock_tracer.start_span.return_value = mock_span + mock_tracer.use_span.return_value.__enter__ = mock_span + mock_tracer.use_span.return_value.__exit__ = mock_span + with patch("opentelemetry.trace.get_tracer") as tracer: + tracer.return_value = mock_tracer + Client().get("/traced/") + self.assertFalse(mock_span.is_recording()) + self.assertTrue(mock_span.is_recording.called) + self.assertFalse(mock_span.set_attribute.called) + self.assertFalse(mock_span.set_status.called) + def test_traced_post(self): Client().post("/traced/") diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py index 1fe8f58a2c7..3ef2c0f35ec 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py @@ -40,13 +40,17 @@ def fetch_async(tracer, func, _, args, kwargs): span = tracer.start_span( request.method, kind=trace.SpanKind.CLIENT, - attributes={ + start_time=start_time, + ) + + if span.is_recording(): + attributes = { "component": "tornado", "http.url": request.url, "http.method": request.method, - }, - start_time=start_time, - ) + } + for key, value in attributes.items(): + span.set_attribute(key, value) with tracer.use_span(span): propagators.inject(type(request.headers).__setitem__, request.headers) @@ -61,7 +65,7 @@ def _finish_tracing_callback(future, span): status_code = None description = None exc = future.exception() - if exc: + if span.is_recording() and exc: if isinstance(exc, HTTPError): status_code = exc.code description = "{}: {}".format(type(exc).__name__, exc) diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 2d5ffd00f78..d900b5d360e 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -13,7 +13,7 @@ # limitations under the License. -from unittest.mock import patch +from unittest.mock import Mock, patch from tornado.testing import AsyncHTTPTestCase @@ -132,6 +132,21 @@ def _test_http_method_call(self, method): self.memory_exporter.clear() + def test_not_recording(self): + mock_tracer = Mock() + mock_span = Mock() + mock_span.is_recording.return_value = False + mock_tracer.start_span.return_value = mock_span + mock_tracer.use_span.return_value.__enter__ = mock_span + mock_tracer.use_span.return_value.__exit__ = mock_span + with patch("opentelemetry.trace.get_tracer") as tracer: + tracer.return_value = mock_tracer + self.fetch("/") + self.assertFalse(mock_span.is_recording()) + self.assertTrue(mock_span.is_recording.called) + self.assertFalse(mock_span.set_attribute.called) + self.assertFalse(mock_span.set_status.called) + def test_async_handler(self): self._test_async_handler("/async", "AsyncHandler") From 42702021ad370ad3f8a34cdc5f231d6e9f7cd8bf Mon Sep 17 00:00:00 2001 From: Leighton Date: Fri, 25 Sep 2020 11:46:13 -0400 Subject: [PATCH 3/7] boto + botocore --- .../instrumentation/asgi/__init__.py | 2 + .../instrumentation/boto/__init__.py | 30 ++++++------- .../tests/test_boto_instrumentation.py | 19 +++++++++ .../instrumentation/botocore/__init__.py | 42 ++++++++++--------- .../tests/test_botocore_instrumentation.py | 32 ++++++++++++++ 5 files changed, 92 insertions(+), 33 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py index 71211907e08..879662ddcfb 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -91,6 +91,8 @@ def collect_request_attributes(scope): def set_status_code(span, status_code): """Adds HTTP response attributes to span using the status_code argument.""" + if not span.is_recording(): + return try: status_code = int(status_code) except ValueError: diff --git a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py index 8e03cd6e749..fe8ca0667d1 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py @@ -136,27 +136,29 @@ def _common_request( # pylint: disable=too-many-locals attributes={"endpoint": endpoint_name} ) + # Original func returns a boto.connection.HTTPResponse object + result = original_func(*args, **kwargs) + add_span_arg_tags( span, endpoint_name, args, args_name, traced_args, ) - # Obtaining region name - region_name = _get_instance_region_name(instance) + if span.is_recording(): + # Obtaining region name + region_name = _get_instance_region_name(instance) - meta = { - "aws.agent": "boto", - "aws.operation": operation_name, - } - if region_name: - meta["aws.region"] = region_name + meta = { + "aws.agent": "boto", + "aws.operation": operation_name, + } + if region_name: + meta["aws.region"] = region_name - for key, value in meta.items(): - span.set_attribute(key, value) + for key, value in meta.items(): + span.set_attribute(key, value) - # Original func returns a boto.connection.HTTPResponse object - result = original_func(*args, **kwargs) - span.set_attribute("http.status_code", getattr(result, "status")) - span.set_attribute("http.method", getattr(result, "_method")) + span.set_attribute("http.status_code", getattr(result, "status")) + span.set_attribute("http.method", getattr(result, "_method")) return result diff --git a/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py b/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py index 0a4a4b8869a..e5ede13961c 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py @@ -13,6 +13,7 @@ # limitations under the License. from unittest import skipUnless +from unittest.mock import Mock, patch import boto.awslambda import boto.ec2 @@ -80,6 +81,24 @@ def test_ec2_client(self): self.assertEqual(span.attributes["aws.region"], "us-west-2") self.assertEqual(span.name, "ec2.command") + @mock_ec2_deprecated + def test_not_recording(self): + mock_tracer = Mock() + mock_span = Mock() + mock_span.is_recording.return_value = False + mock_tracer.start_span.return_value = mock_span + mock_tracer.use_span.return_value.__enter__ = mock_span + mock_tracer.use_span.return_value.__exit__ = mock_span + with patch("opentelemetry.trace.get_tracer") as tracer: + tracer.return_value = mock_tracer + ec2 = boto.ec2.connect_to_region("us-west-2") + ec2.get_all_instances() + self.assertFalse(mock_span.is_recording()) + self.assertTrue(mock_span.is_recording.called) + self.assertFalse(mock_span.set_attribute.called) + self.assertFalse(mock_span.set_status.called) + + @mock_ec2_deprecated def test_analytics_enabled_with_rate(self): ec2 = boto.ec2.connect_to_region("us-west-2") diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index d716c90d684..1382ced7e4d 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -119,25 +119,26 @@ def _patched_api_call(self, original_func, instance, args, kwargs): {"params", "path", "verb"}, ) - region_name = deep_getattr(instance, "meta.region_name") - - meta = { - "aws.agent": "botocore", - "aws.operation": operation, - "aws.region": region_name, - } - for key, value in meta.items(): - span.set_attribute(key, value) - - result = original_func(*args, **kwargs) - - span.set_attribute( - "http.status_code", - result["ResponseMetadata"]["HTTPStatusCode"], - ) - span.set_attribute( - "retry_attempts", result["ResponseMetadata"]["RetryAttempts"], - ) + if span.is_recording(): + region_name = deep_getattr(instance, "meta.region_name") + + meta = { + "aws.agent": "botocore", + "aws.operation": operation, + "aws.region": region_name, + } + for key, value in meta.items(): + span.set_attribute(key, value) + + result = original_func(*args, **kwargs) + + span.set_attribute( + "http.status_code", + result["ResponseMetadata"]["HTTPStatusCode"], + ) + span.set_attribute( + "retry_attempts", result["ResponseMetadata"]["RetryAttempts"], + ) return result @@ -177,6 +178,9 @@ def flatten_dict(dict_, sep=".", prefix=""): else {prefix: dict_} ) + if not span.is_recording(): + return + if endpoint_name not in {"kms", "sts"}: tags = dict( (name, value) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index ea655c88306..79afa676f95 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -1,3 +1,17 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import botocore.session from botocore.exceptions import ParamValidationError from moto import ( # pylint: disable=import-error @@ -8,6 +22,7 @@ mock_s3, mock_sqs, ) +from unittest.mock import Mock, patch from opentelemetry.instrumentation.botocore import BotocoreInstrumentor from opentelemetry.sdk.resources import Resource @@ -61,6 +76,23 @@ def test_traced_client(self): ) self.assertEqual(span.name, "ec2.command") + @mock_ec2 + def test_not_recording(self): + mock_tracer = Mock() + mock_span = Mock() + mock_span.is_recording.return_value = False + mock_tracer.start_span.return_value = mock_span + mock_tracer.use_span.return_value.__enter__ = mock_span + mock_tracer.use_span.return_value.__exit__ = mock_span + with patch("opentelemetry.trace.get_tracer") as tracer: + tracer.return_value = mock_tracer + ec2 = self.session.create_client("ec2", region_name="us-west-2") + ec2.describe_instances() + self.assertFalse(mock_span.is_recording()) + self.assertTrue(mock_span.is_recording.called) + self.assertFalse(mock_span.set_attribute.called) + self.assertFalse(mock_span.set_status.called) + @mock_ec2 def test_traced_client_analytics(self): ec2 = self.session.create_client("ec2", region_name="us-west-2") From 0cc81eeb6423a857ae13da75c51a279b9b69b428 Mon Sep 17 00:00:00 2001 From: Leighton Date: Fri, 25 Sep 2020 12:09:10 -0400 Subject: [PATCH 4/7] lint --- .../src/opentelemetry/instrumentation/boto/__init__.py | 4 +++- .../tests/test_boto_instrumentation.py | 1 - .../src/opentelemetry/instrumentation/botocore/__init__.py | 3 ++- .../src/opentelemetry/instrumentation/tornado/client.py | 4 +--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py index fe8ca0667d1..8cff13556c6 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py @@ -157,7 +157,9 @@ def _common_request( # pylint: disable=too-many-locals for key, value in meta.items(): span.set_attribute(key, value) - span.set_attribute("http.status_code", getattr(result, "status")) + span.set_attribute( + "http.status_code", getattr(result, "status") + ) span.set_attribute("http.method", getattr(result, "_method")) return result diff --git a/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py b/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py index e5ede13961c..1a8cc2b387f 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py @@ -98,7 +98,6 @@ def test_not_recording(self): self.assertFalse(mock_span.set_attribute.called) self.assertFalse(mock_span.set_status.called) - @mock_ec2_deprecated def test_analytics_enabled_with_rate(self): ec2 = boto.ec2.connect_to_region("us-west-2") diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index 1382ced7e4d..faa2fee9806 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -137,7 +137,8 @@ def _patched_api_call(self, original_func, instance, args, kwargs): result["ResponseMetadata"]["HTTPStatusCode"], ) span.set_attribute( - "retry_attempts", result["ResponseMetadata"]["RetryAttempts"], + "retry_attempts", + result["ResponseMetadata"]["RetryAttempts"], ) return result diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py index 3ef2c0f35ec..12330c0919d 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py @@ -38,9 +38,7 @@ def fetch_async(tracer, func, _, args, kwargs): request = args[0] span = tracer.start_span( - request.method, - kind=trace.SpanKind.CLIENT, - start_time=start_time, + request.method, kind=trace.SpanKind.CLIENT, start_time=start_time, ) if span.is_recording(): From 8560f7130b35490954fe773c69303209aa333135 Mon Sep 17 00:00:00 2001 From: Leighton Date: Fri, 25 Sep 2020 13:18:46 -0400 Subject: [PATCH 5/7] Update test_botocore_instrumentation.py --- .../tests/test_botocore_instrumentation.py | 3 ++- 1 file changed, 2 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 79afa676f95..9bf691f6570 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from unittest.mock import Mock, patch + import botocore.session from botocore.exceptions import ParamValidationError from moto import ( # pylint: disable=import-error @@ -22,7 +24,6 @@ mock_s3, mock_sqs, ) -from unittest.mock import Mock, patch from opentelemetry.instrumentation.botocore import BotocoreInstrumentor from opentelemetry.sdk.resources import Resource From bf7f8a9560764d3bb4624fa4a6510d67539b091d Mon Sep 17 00:00:00 2001 From: Leighton Date: Tue, 29 Sep 2020 11:37:02 -0400 Subject: [PATCH 6/7] comments --- .../src/opentelemetry/instrumentation/boto/__init__.py | 8 ++++---- .../opentelemetry/instrumentation/botocore/__init__.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py index 8cff13556c6..3bef955d148 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py @@ -139,11 +139,11 @@ def _common_request( # pylint: disable=too-many-locals # Original func returns a boto.connection.HTTPResponse object result = original_func(*args, **kwargs) - add_span_arg_tags( - span, endpoint_name, args, args_name, traced_args, - ) - if span.is_recording(): + add_span_arg_tags( + span, endpoint_name, args, args_name, traced_args, + ) + # Obtaining region name region_name = _get_instance_region_name(instance) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index faa2fee9806..50f1d66aa9f 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -97,7 +97,7 @@ def _patched_api_call(self, original_func, instance, args, kwargs): ) as span: operation = None - if args: + if args and span.is_recording():: operation = args[0] span.resource = Resource( attributes={ @@ -130,8 +130,9 @@ def _patched_api_call(self, original_func, instance, args, kwargs): for key, value in meta.items(): span.set_attribute(key, value) - result = original_func(*args, **kwargs) + result = original_func(*args, **kwargs) + if span.is_recording(): span.set_attribute( "http.status_code", result["ResponseMetadata"]["HTTPStatusCode"], From 8cde2ceefcaf6a80fa3dba94bd65053aff177703 Mon Sep 17 00:00:00 2001 From: Leighton Date: Tue, 29 Sep 2020 11:52:46 -0400 Subject: [PATCH 7/7] Update __init__.py --- .../src/opentelemetry/instrumentation/botocore/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index 50f1d66aa9f..b574b86cfb2 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -97,7 +97,7 @@ def _patched_api_call(self, original_func, instance, args, kwargs): ) as span: operation = None - if args and span.is_recording():: + if args and span.is_recording(): operation = args[0] span.resource = Resource( attributes={