mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 02:52:18 +08:00
Ensure resources are not mutated (#310)
This commit is contained in:
@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
([#308](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/308))
|
([#308](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/308))
|
||||||
- Remove metrics from all instrumentations
|
- Remove metrics from all instrumentations
|
||||||
([#312](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/312))
|
([#312](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/312))
|
||||||
|
- `opentelemetry-instrumentation-boto` updated to set span attributes instead of overriding the resource.
|
||||||
|
([#310](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/310))
|
||||||
|
|
||||||
## [0.17b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.17b0) - 2021-01-20
|
## [0.17b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.17b0) - 2021-01-20
|
||||||
|
|
||||||
|
@ -120,18 +120,10 @@ class BotoInstrumentor(BaseInstrumentor):
|
|||||||
with self._tracer.start_as_current_span(
|
with self._tracer.start_as_current_span(
|
||||||
"{}.command".format(endpoint_name), kind=SpanKind.CONSUMER,
|
"{}.command".format(endpoint_name), kind=SpanKind.CONSUMER,
|
||||||
) as span:
|
) as span:
|
||||||
|
span.set_attribute("endpoint", endpoint_name)
|
||||||
if args:
|
if args:
|
||||||
http_method = args[0]
|
http_method = args[0]
|
||||||
span.resource = Resource(
|
span.set_attribute("http_method", http_method.lower())
|
||||||
attributes={
|
|
||||||
"endpoint": endpoint_name,
|
|
||||||
"http_method": http_method.lower(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
span.resource = Resource(
|
|
||||||
attributes={"endpoint": endpoint_name}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Original func returns a boto.connection.HTTPResponse object
|
# Original func returns a boto.connection.HTTPResponse object
|
||||||
result = original_func(*args, **kwargs)
|
result = original_func(*args, **kwargs)
|
||||||
|
@ -28,7 +28,6 @@ from moto import ( # pylint: disable=import-error
|
|||||||
)
|
)
|
||||||
|
|
||||||
from opentelemetry.instrumentation.boto import BotoInstrumentor
|
from opentelemetry.instrumentation.boto import BotoInstrumentor
|
||||||
from opentelemetry.sdk.resources import Resource
|
|
||||||
from opentelemetry.test.test_base import TestBase
|
from opentelemetry.test.test_base import TestBase
|
||||||
|
|
||||||
|
|
||||||
@ -71,12 +70,8 @@ class TestBotoInstrumentor(TestBase):
|
|||||||
span = spans[1]
|
span = spans[1]
|
||||||
self.assertEqual(span.attributes["aws.operation"], "RunInstances")
|
self.assertEqual(span.attributes["aws.operation"], "RunInstances")
|
||||||
assert_span_http_status_code(span, 200)
|
assert_span_http_status_code(span, 200)
|
||||||
self.assertEqual(
|
self.assertEqual(span.attributes["endpoint"], "ec2")
|
||||||
span.resource,
|
self.assertEqual(span.attributes["http_method"], "runinstances")
|
||||||
Resource(
|
|
||||||
attributes={"endpoint": "ec2", "http_method": "runinstances"}
|
|
||||||
),
|
|
||||||
)
|
|
||||||
self.assertEqual(span.attributes["http.method"], "POST")
|
self.assertEqual(span.attributes["http.method"], "POST")
|
||||||
self.assertEqual(span.attributes["aws.region"], "us-west-2")
|
self.assertEqual(span.attributes["aws.region"], "us-west-2")
|
||||||
self.assertEqual(span.name, "ec2.command")
|
self.assertEqual(span.name, "ec2.command")
|
||||||
@ -147,10 +142,8 @@ class TestBotoInstrumentor(TestBase):
|
|||||||
self.assertEqual(len(spans), 3)
|
self.assertEqual(len(spans), 3)
|
||||||
span = spans[2]
|
span = spans[2]
|
||||||
assert_span_http_status_code(span, 200)
|
assert_span_http_status_code(span, 200)
|
||||||
self.assertEqual(
|
self.assertEqual(span.attributes["endpoint"], "s3")
|
||||||
span.resource,
|
self.assertEqual(span.attributes["http_method"], "head")
|
||||||
Resource(attributes={"endpoint": "s3", "http_method": "head"}),
|
|
||||||
)
|
|
||||||
self.assertEqual(span.attributes["http.method"], "HEAD")
|
self.assertEqual(span.attributes["http.method"], "HEAD")
|
||||||
self.assertEqual(span.attributes["aws.operation"], "head_bucket")
|
self.assertEqual(span.attributes["aws.operation"], "head_bucket")
|
||||||
self.assertEqual(span.name, "s3.command")
|
self.assertEqual(span.name, "s3.command")
|
||||||
@ -162,10 +155,8 @@ class TestBotoInstrumentor(TestBase):
|
|||||||
spans = self.memory_exporter.get_finished_spans()
|
spans = self.memory_exporter.get_finished_spans()
|
||||||
assert spans
|
assert spans
|
||||||
span = spans[2]
|
span = spans[2]
|
||||||
self.assertEqual(
|
self.assertEqual(spans[2].attributes["endpoint"], "s3")
|
||||||
span.resource,
|
self.assertEqual(spans[2].attributes["http_method"], "head")
|
||||||
Resource(attributes={"endpoint": "s3", "http_method": "head"}),
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock_s3_deprecated
|
@mock_s3_deprecated
|
||||||
def test_s3_put(self):
|
def test_s3_put(self):
|
||||||
@ -182,24 +173,18 @@ class TestBotoInstrumentor(TestBase):
|
|||||||
self.assertEqual(len(spans), 3)
|
self.assertEqual(len(spans), 3)
|
||||||
self.assertEqual(spans[0].attributes["aws.operation"], "create_bucket")
|
self.assertEqual(spans[0].attributes["aws.operation"], "create_bucket")
|
||||||
assert_span_http_status_code(spans[0], 200)
|
assert_span_http_status_code(spans[0], 200)
|
||||||
self.assertEqual(
|
self.assertEqual(spans[0].attributes["endpoint"], "s3")
|
||||||
spans[0].resource,
|
self.assertEqual(spans[0].attributes["http_method"], "put")
|
||||||
Resource(attributes={"endpoint": "s3", "http_method": "put"}),
|
|
||||||
)
|
|
||||||
# get bucket
|
# get bucket
|
||||||
self.assertEqual(spans[1].attributes["aws.operation"], "head_bucket")
|
self.assertEqual(spans[1].attributes["aws.operation"], "head_bucket")
|
||||||
self.assertEqual(
|
self.assertEqual(spans[1].attributes["endpoint"], "s3")
|
||||||
spans[1].resource,
|
self.assertEqual(spans[1].attributes["http_method"], "head")
|
||||||
Resource(attributes={"endpoint": "s3", "http_method": "head"}),
|
|
||||||
)
|
|
||||||
# put object
|
# put object
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
spans[2].attributes["aws.operation"], "_send_file_internal"
|
spans[2].attributes["aws.operation"], "_send_file_internal"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(spans[2].attributes["endpoint"], "s3")
|
||||||
spans[2].resource,
|
self.assertEqual(spans[2].attributes["http_method"], "put")
|
||||||
Resource(attributes={"endpoint": "s3", "http_method": "put"}),
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock_lambda_deprecated
|
@mock_lambda_deprecated
|
||||||
def test_unpatch(self):
|
def test_unpatch(self):
|
||||||
@ -239,10 +224,8 @@ class TestBotoInstrumentor(TestBase):
|
|||||||
self.assertEqual(len(spans), 2)
|
self.assertEqual(len(spans), 2)
|
||||||
span = spans[0]
|
span = spans[0]
|
||||||
assert_span_http_status_code(span, 200)
|
assert_span_http_status_code(span, 200)
|
||||||
self.assertEqual(
|
self.assertEqual(span.attributes["endpoint"], "lambda")
|
||||||
span.resource,
|
self.assertEqual(span.attributes["http_method"], "get")
|
||||||
Resource(attributes={"endpoint": "lambda", "http_method": "get"}),
|
|
||||||
)
|
|
||||||
self.assertEqual(span.attributes["http.method"], "GET")
|
self.assertEqual(span.attributes["http.method"], "GET")
|
||||||
self.assertEqual(span.attributes["aws.region"], "us-east-2")
|
self.assertEqual(span.attributes["aws.region"], "us-east-2")
|
||||||
self.assertEqual(span.attributes["aws.operation"], "list_functions")
|
self.assertEqual(span.attributes["aws.operation"], "list_functions")
|
||||||
@ -256,15 +239,8 @@ class TestBotoInstrumentor(TestBase):
|
|||||||
spans = self.memory_exporter.get_finished_spans()
|
spans = self.memory_exporter.get_finished_spans()
|
||||||
assert spans
|
assert spans
|
||||||
span = spans[0]
|
span = spans[0]
|
||||||
self.assertEqual(
|
self.assertEqual(span.attributes["endpoint"], "sts")
|
||||||
span.resource,
|
self.assertEqual(span.attributes["http_method"], "getfederationtoken")
|
||||||
Resource(
|
|
||||||
attributes={
|
|
||||||
"endpoint": "sts",
|
|
||||||
"http_method": "getfederationtoken",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
|
||||||
self.assertEqual(span.attributes["aws.region"], "us-west-2")
|
self.assertEqual(span.attributes["aws.region"], "us-west-2")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes["aws.operation"], "GetFederationToken"
|
span.attributes["aws.operation"], "GetFederationToken"
|
||||||
@ -288,7 +264,5 @@ class TestBotoInstrumentor(TestBase):
|
|||||||
spans = self.memory_exporter.get_finished_spans()
|
spans = self.memory_exporter.get_finished_spans()
|
||||||
assert spans
|
assert spans
|
||||||
span = spans[0]
|
span = spans[0]
|
||||||
self.assertEqual(
|
self.assertEqual(span.attributes["endpoint"], "elasticcache")
|
||||||
span.resource, Resource(attributes={"endpoint": "elasticcache"})
|
|
||||||
)
|
|
||||||
self.assertEqual(span.attributes["aws.region"], "us-west-2")
|
self.assertEqual(span.attributes["aws.region"], "us-west-2")
|
||||||
|
Reference in New Issue
Block a user