Skip to content

Commit a695af9

Browse files
alrexlzchen
alrex
authored andcommitted
Ensure resources are not mutated
1 parent ade29f6 commit a695af9

File tree

3 files changed

+21
-53
lines changed

3 files changed

+21
-53
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
([#301](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/301))
1313
- `opentelemetry-instrumentation-asgi` Return header values using case insensitive keys
1414
([#308](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/308))
15+
- `opentelemetry-instrumentation-boto` updated to set span attributes instead of overriding the resource.
16+
([#310](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/310))
1517

1618
## [0.17b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.17b0) - 2021-01-20
1719

Diff for: instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,10 @@ def _common_request( # pylint: disable=too-many-locals
120120
with self._tracer.start_as_current_span(
121121
"{}.command".format(endpoint_name), kind=SpanKind.CONSUMER,
122122
) as span:
123+
span.set_attribute("endpoint", endpoint_name)
123124
if args:
124125
http_method = args[0]
125-
span.resource = Resource(
126-
attributes={
127-
"endpoint": endpoint_name,
128-
"http_method": http_method.lower(),
129-
}
130-
)
131-
else:
132-
span.resource = Resource(
133-
attributes={"endpoint": endpoint_name}
134-
)
126+
span.set_attribute("http_method", http_method.lower())
135127

136128
# Original func returns a boto.connection.HTTPResponse object
137129
result = original_func(*args, **kwargs)

Diff for: instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py

+17-43
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
)
2929

3030
from opentelemetry.instrumentation.boto import BotoInstrumentor
31-
from opentelemetry.sdk.resources import Resource
3231
from opentelemetry.test.test_base import TestBase
3332

3433

@@ -71,12 +70,8 @@ def test_ec2_client(self):
7170
span = spans[1]
7271
self.assertEqual(span.attributes["aws.operation"], "RunInstances")
7372
assert_span_http_status_code(span, 200)
74-
self.assertEqual(
75-
span.resource,
76-
Resource(
77-
attributes={"endpoint": "ec2", "http_method": "runinstances"}
78-
),
79-
)
73+
self.assertEqual(span.attributes["endpoint"], "ec2")
74+
self.assertEqual(span.attributes["http_method"], "runinstances")
8075
self.assertEqual(span.attributes["http.method"], "POST")
8176
self.assertEqual(span.attributes["aws.region"], "us-west-2")
8277
self.assertEqual(span.name, "ec2.command")
@@ -147,10 +142,8 @@ def test_s3_client(self):
147142
self.assertEqual(len(spans), 3)
148143
span = spans[2]
149144
assert_span_http_status_code(span, 200)
150-
self.assertEqual(
151-
span.resource,
152-
Resource(attributes={"endpoint": "s3", "http_method": "head"}),
153-
)
145+
self.assertEqual(span.attributes["endpoint"], "s3")
146+
self.assertEqual(span.attributes["http_method"], "head")
154147
self.assertEqual(span.attributes["http.method"], "HEAD")
155148
self.assertEqual(span.attributes["aws.operation"], "head_bucket")
156149
self.assertEqual(span.name, "s3.command")
@@ -162,10 +155,8 @@ def test_s3_client(self):
162155
spans = self.memory_exporter.get_finished_spans()
163156
assert spans
164157
span = spans[2]
165-
self.assertEqual(
166-
span.resource,
167-
Resource(attributes={"endpoint": "s3", "http_method": "head"}),
168-
)
158+
self.assertEqual(spans[2].attributes["endpoint"], "s3")
159+
self.assertEqual(spans[2].attributes["http_method"], "head")
169160

170161
@mock_s3_deprecated
171162
def test_s3_put(self):
@@ -182,24 +173,18 @@ def test_s3_put(self):
182173
self.assertEqual(len(spans), 3)
183174
self.assertEqual(spans[0].attributes["aws.operation"], "create_bucket")
184175
assert_span_http_status_code(spans[0], 200)
185-
self.assertEqual(
186-
spans[0].resource,
187-
Resource(attributes={"endpoint": "s3", "http_method": "put"}),
188-
)
176+
self.assertEqual(spans[0].attributes["endpoint"], "s3")
177+
self.assertEqual(spans[0].attributes["http_method"], "put")
189178
# get bucket
190179
self.assertEqual(spans[1].attributes["aws.operation"], "head_bucket")
191-
self.assertEqual(
192-
spans[1].resource,
193-
Resource(attributes={"endpoint": "s3", "http_method": "head"}),
194-
)
180+
self.assertEqual(spans[1].attributes["endpoint"], "s3")
181+
self.assertEqual(spans[1].attributes["http_method"], "head")
195182
# put object
196183
self.assertEqual(
197184
spans[2].attributes["aws.operation"], "_send_file_internal"
198185
)
199-
self.assertEqual(
200-
spans[2].resource,
201-
Resource(attributes={"endpoint": "s3", "http_method": "put"}),
202-
)
186+
self.assertEqual(spans[2].attributes["endpoint"], "s3")
187+
self.assertEqual(spans[2].attributes["http_method"], "put")
203188

204189
@mock_lambda_deprecated
205190
def test_unpatch(self):
@@ -239,10 +224,8 @@ def test_lambda_client(self):
239224
self.assertEqual(len(spans), 2)
240225
span = spans[0]
241226
assert_span_http_status_code(span, 200)
242-
self.assertEqual(
243-
span.resource,
244-
Resource(attributes={"endpoint": "lambda", "http_method": "get"}),
245-
)
227+
self.assertEqual(span.attributes["endpoint"], "lambda")
228+
self.assertEqual(span.attributes["http_method"], "get")
246229
self.assertEqual(span.attributes["http.method"], "GET")
247230
self.assertEqual(span.attributes["aws.region"], "us-east-2")
248231
self.assertEqual(span.attributes["aws.operation"], "list_functions")
@@ -256,15 +239,8 @@ def test_sts_client(self):
256239
spans = self.memory_exporter.get_finished_spans()
257240
assert spans
258241
span = spans[0]
259-
self.assertEqual(
260-
span.resource,
261-
Resource(
262-
attributes={
263-
"endpoint": "sts",
264-
"http_method": "getfederationtoken",
265-
}
266-
),
267-
)
242+
self.assertEqual(span.attributes["endpoint"], "sts")
243+
self.assertEqual(span.attributes["http_method"], "getfederationtoken")
268244
self.assertEqual(span.attributes["aws.region"], "us-west-2")
269245
self.assertEqual(
270246
span.attributes["aws.operation"], "GetFederationToken"
@@ -288,7 +264,5 @@ def test_elasticache_client(self):
288264
spans = self.memory_exporter.get_finished_spans()
289265
assert spans
290266
span = spans[0]
291-
self.assertEqual(
292-
span.resource, Resource(attributes={"endpoint": "elasticcache"})
293-
)
267+
self.assertEqual(span.attributes["endpoint"], "elasticcache")
294268
self.assertEqual(span.attributes["aws.region"], "us-west-2")

0 commit comments

Comments
 (0)