Skip to content

Commit 4dcb485

Browse files
authored
Merge branch 'main' into fix-gunicorn
2 parents ffd7f1b + 9ff3b90 commit 4dcb485

File tree

6 files changed

+56
-51
lines changed

6 files changed

+56
-51
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_attribute_keys.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
# AWS_#_NAME attributes are not supported in python as they are not part of the Semantic Conventions.
1616
# TODO:Move to Semantic Conventions when these attributes are added.
17-
AWS_QUEUE_URL: str = "aws.sqs.queue_url"
18-
AWS_QUEUE_NAME: str = "aws.sqs.queue_name"
19-
AWS_STREAM_NAME: str = "aws.kinesis.stream_name"
17+
AWS_SQS_QUEUE_URL: str = "aws.sqs.queue.url"
18+
AWS_SQS_QUEUE_NAME: str = "aws.sqs.queue.name"
19+
AWS_KINESIS_STREAM_NAME: str = "aws.kinesis.stream.name"

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
from urllib.parse import ParseResult, urlparse
77

88
from amazon.opentelemetry.distro._aws_attribute_keys import (
9+
AWS_KINESIS_STREAM_NAME,
910
AWS_LOCAL_OPERATION,
1011
AWS_LOCAL_SERVICE,
11-
AWS_QUEUE_NAME,
12-
AWS_QUEUE_URL,
1312
AWS_REMOTE_DB_USER,
1413
AWS_REMOTE_OPERATION,
1514
AWS_REMOTE_RESOURCE_IDENTIFIER,
1615
AWS_REMOTE_RESOURCE_TYPE,
1716
AWS_REMOTE_SERVICE,
1817
AWS_SPAN_KIND,
19-
AWS_STREAM_NAME,
18+
AWS_SQS_QUEUE_NAME,
19+
AWS_SQS_QUEUE_URL,
2020
)
2121
from amazon.opentelemetry.distro._aws_span_processing_util import (
2222
LOCAL_ROOT,
@@ -361,19 +361,19 @@ def _set_remote_type_and_identifier(span: ReadableSpan, attributes: BoundedAttri
361361
if is_key_present(span, _AWS_TABLE_NAMES) and len(span.attributes.get(_AWS_TABLE_NAMES)) == 1:
362362
remote_resource_type = _NORMALIZED_DYNAMO_DB_SERVICE_NAME + "::Table"
363363
remote_resource_identifier = _escape_delimiters(span.attributes.get(_AWS_TABLE_NAMES)[0])
364-
elif is_key_present(span, AWS_STREAM_NAME):
364+
elif is_key_present(span, AWS_KINESIS_STREAM_NAME):
365365
remote_resource_type = _NORMALIZED_KINESIS_SERVICE_NAME + "::Stream"
366-
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_STREAM_NAME))
366+
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_KINESIS_STREAM_NAME))
367367
elif is_key_present(span, _AWS_BUCKET_NAME):
368368
remote_resource_type = _NORMALIZED_S3_SERVICE_NAME + "::Bucket"
369369
remote_resource_identifier = _escape_delimiters(span.attributes.get(_AWS_BUCKET_NAME))
370-
elif is_key_present(span, AWS_QUEUE_NAME):
370+
elif is_key_present(span, AWS_SQS_QUEUE_NAME):
371371
remote_resource_type = _NORMALIZED_SQS_SERVICE_NAME + "::Queue"
372-
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_QUEUE_NAME))
373-
elif is_key_present(span, AWS_QUEUE_URL):
372+
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_SQS_QUEUE_NAME))
373+
elif is_key_present(span, AWS_SQS_QUEUE_URL):
374374
remote_resource_type = _NORMALIZED_SQS_SERVICE_NAME + "::Queue"
375375
remote_resource_identifier = _escape_delimiters(
376-
SqsUrlParser.get_queue_name(span.attributes.get(AWS_QUEUE_URL))
376+
SqsUrlParser.get_queue_name(span.attributes.get(AWS_SQS_QUEUE_URL))
377377
)
378378
elif is_db_span(span):
379379
remote_resource_type = _DB_CONNECTION_STRING_TYPE

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_botocore_patches.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License.
44
import importlib
55

6+
from amazon.opentelemetry.distro._aws_attribute_keys import (
7+
AWS_KINESIS_STREAM_NAME,
8+
AWS_SQS_QUEUE_NAME,
9+
AWS_SQS_QUEUE_URL,
10+
)
611
from opentelemetry.instrumentation.botocore.extensions import _KNOWN_EXTENSIONS
712
from opentelemetry.instrumentation.botocore.extensions.sqs import _SqsExtension
813
from opentelemetry.instrumentation.botocore.extensions.types import _AttributeMapT, _AwsSdkExtension
@@ -24,7 +29,7 @@ def _apply_botocore_kinesis_patch() -> None:
2429
2530
This patch adds an extension to the upstream's list of known extension for Kinesis. Extensions allow for custom
2631
logic for adding service-specific information to spans, such as attributes. Specifically, we are adding logic to add
27-
the `aws.kinesis.stream_name` attribute, to be used to generate RemoteTarget and achieve parity with the Java
32+
the `aws.kinesis.stream.name` attribute, to be used to generate RemoteTarget and achieve parity with the Java
2833
instrumentation.
2934
"""
3035
_KNOWN_EXTENSIONS["kinesis"] = _lazy_load(".", "_KinesisExtension")
@@ -47,7 +52,7 @@ def _apply_botocore_sqs_patch() -> None:
4752
4853
This patch extends the existing upstream extension for SQS. Extensions allow for custom logic for adding
4954
service-specific information to spans, such as attributes. Specifically, we are adding logic to add
50-
`aws.sqs.queue_url` and `aws.sqs.queue_name` attributes, to be used to generate RemoteTarget and achieve parity
55+
`aws.sqs.queue.url` and `aws.sqs.queue.name` attributes, to be used to generate RemoteTarget and achieve parity
5156
with the Java instrumentation. Callout that today, the upstream logic adds `aws.queue_url` but we feel that
5257
`aws.sqs` is more in line with existing AWS Semantic Convention attributes like `AWS_S3_BUCKET`, etc.
5358
"""
@@ -58,9 +63,9 @@ def patch_extract_attributes(self, attributes: _AttributeMapT):
5863
queue_name = self._call_context.params.get("QueueName")
5964
queue_url = self._call_context.params.get("QueueUrl")
6065
if queue_name:
61-
attributes["aws.sqs.queue_name"] = queue_name
66+
attributes[AWS_SQS_QUEUE_NAME] = queue_name
6267
if queue_url:
63-
attributes["aws.sqs.queue_url"] = queue_url
68+
attributes[AWS_SQS_QUEUE_URL] = queue_url
6469

6570
_SqsExtension.extract_attributes = patch_extract_attributes
6671

@@ -93,4 +98,4 @@ class _KinesisExtension(_AwsSdkExtension):
9398
def extract_attributes(self, attributes: _AttributeMapT):
9499
stream_name = self._call_context.params.get("StreamName")
95100
if stream_name:
96-
attributes["aws.kinesis.stream_name"] = stream_name
101+
attributes[AWS_KINESIS_STREAM_NAME] = stream_name

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_metric_attribute_generator.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99

1010
from amazon.opentelemetry.distro._aws_attribute_keys import (
1111
AWS_CONSUMER_PARENT_SPAN_KIND,
12+
AWS_KINESIS_STREAM_NAME,
1213
AWS_LOCAL_OPERATION,
1314
AWS_LOCAL_SERVICE,
14-
AWS_QUEUE_NAME,
15-
AWS_QUEUE_URL,
1615
AWS_REMOTE_DB_USER,
1716
AWS_REMOTE_OPERATION,
1817
AWS_REMOTE_RESOURCE_IDENTIFIER,
1918
AWS_REMOTE_RESOURCE_TYPE,
2019
AWS_REMOTE_SERVICE,
2120
AWS_SPAN_KIND,
22-
AWS_STREAM_NAME,
21+
AWS_SQS_QUEUE_NAME,
22+
AWS_SQS_QUEUE_URL,
2323
)
2424
from amazon.opentelemetry.distro._aws_metric_attribute_generator import _AwsMetricAttributeGenerator
2525
from amazon.opentelemetry.distro.metric_attribute_generator import DEPENDENCY_METRIC, SERVICE_METRIC
@@ -971,31 +971,31 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
971971
self._validate_remote_resource_attributes("AWS::S3::Bucket", "aws_s3_bucket_name")
972972
self._mock_attribute([SpanAttributes.AWS_S3_BUCKET], [None])
973973

974-
# Validate behaviour of AWS_QUEUE_NAME attribute, then remove it
975-
self._mock_attribute([AWS_QUEUE_NAME], ["aws_queue_name"], keys, values)
974+
# Validate behaviour of AWS_SQS_QUEUE_NAME attribute, then remove it
975+
self._mock_attribute([AWS_SQS_QUEUE_NAME], ["aws_queue_name"], keys, values)
976976
self._validate_remote_resource_attributes("AWS::SQS::Queue", "aws_queue_name")
977-
self._mock_attribute([AWS_QUEUE_NAME], [None])
977+
self._mock_attribute([AWS_SQS_QUEUE_NAME], [None])
978978

979-
# Validate behaviour of having both AWS_QUEUE_NAME and AWS_QUEUE_URL attribute, then remove them. Queue name is
980-
# more reliable than queue URL, so we prefer to use name over URL.
979+
# Validate behaviour of having both AWS_SQS_QUEUE_NAME and AWS_SQS_QUEUE_URL attribute, then remove them.
980+
# Queue name is more reliable than queue URL, so we prefer to use name over URL.
981981
self._mock_attribute(
982-
[AWS_QUEUE_URL, AWS_QUEUE_NAME],
982+
[AWS_SQS_QUEUE_URL, AWS_SQS_QUEUE_NAME],
983983
["https://sqs.us-east-2.amazonaws.com/123456789012/Queue", "aws_queue_name"],
984984
keys,
985985
values,
986986
)
987987
self._validate_remote_resource_attributes("AWS::SQS::Queue", "aws_queue_name")
988-
self._mock_attribute([AWS_QUEUE_URL, AWS_QUEUE_NAME], [None, None])
988+
self._mock_attribute([AWS_SQS_QUEUE_URL, AWS_SQS_QUEUE_NAME], [None, None])
989989

990990
# Valid queue name with invalid queue URL, we should default to using the queue name.
991-
self._mock_attribute([AWS_QUEUE_URL, AWS_QUEUE_NAME], ["invalidUrl", "aws_queue_name"], keys, values)
991+
self._mock_attribute([AWS_SQS_QUEUE_URL, AWS_SQS_QUEUE_NAME], ["invalidUrl", "aws_queue_name"], keys, values)
992992
self._validate_remote_resource_attributes("AWS::SQS::Queue", "aws_queue_name")
993-
self._mock_attribute([AWS_QUEUE_URL, AWS_QUEUE_NAME], [None, None])
993+
self._mock_attribute([AWS_SQS_QUEUE_URL, AWS_SQS_QUEUE_NAME], [None, None])
994994

995-
# Validate behaviour of AWS_STREAM_NAME attribute, then remove it.
996-
self._mock_attribute([AWS_STREAM_NAME], ["aws_stream_name"], keys, values)
995+
# Validate behaviour of AWS_KINESIS_STREAM_NAME attribute, then remove it.
996+
self._mock_attribute([AWS_KINESIS_STREAM_NAME], ["aws_stream_name"], keys, values)
997997
self._validate_remote_resource_attributes("AWS::Kinesis::Stream", "aws_stream_name")
998-
self._mock_attribute([AWS_STREAM_NAME], [None])
998+
self._mock_attribute([AWS_KINESIS_STREAM_NAME], [None])
999999

10001000
# Validate behaviour of SpanAttributes.AWS_DYNAMODB_TABLE_NAMES attribute with one table name, then remove it.
10011001
self._mock_attribute([SpanAttributes.AWS_DYNAMODB_TABLE_NAMES], [["aws_table_name"]], keys, values)

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_instrumentation_patch.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def _test_unpatched_botocore_instrumentation(self):
117117
self.assertTrue("sqs" in _KNOWN_EXTENSIONS, "Upstream has removed the SQS extension")
118118
attributes: Dict[str, str] = _do_extract_sqs_attributes()
119119
self.assertTrue("aws.queue_url" in attributes)
120-
self.assertFalse("aws.sqs.queue_url" in attributes)
121-
self.assertFalse("aws.sqs.queue_name" in attributes)
120+
self.assertFalse("aws.sqs.queue.url" in attributes)
121+
self.assertFalse("aws.sqs.queue.name" in attributes)
122122

123123
def _test_unpatched_gevent_instrumentation(self):
124124
self.assertFalse(gevent.monkey.is_module_patched("os"), "gevent os module has been patched")
@@ -138,8 +138,8 @@ def _test_patched_botocore_instrumentation(self):
138138
# Kinesis
139139
self.assertTrue("kinesis" in _KNOWN_EXTENSIONS)
140140
kinesis_attributes: Dict[str, str] = _do_extract_kinesis_attributes()
141-
self.assertTrue("aws.kinesis.stream_name" in kinesis_attributes)
142-
self.assertEqual(kinesis_attributes["aws.kinesis.stream_name"], _STREAM_NAME)
141+
self.assertTrue("aws.kinesis.stream.name" in kinesis_attributes)
142+
self.assertEqual(kinesis_attributes["aws.kinesis.stream.name"], _STREAM_NAME)
143143

144144
# S3
145145
self.assertTrue("s3" in _KNOWN_EXTENSIONS)
@@ -151,10 +151,10 @@ def _test_patched_botocore_instrumentation(self):
151151
self.assertTrue("sqs" in _KNOWN_EXTENSIONS)
152152
sqs_attributes: Dict[str, str] = _do_extract_sqs_attributes()
153153
self.assertTrue("aws.queue_url" in sqs_attributes)
154-
self.assertTrue("aws.sqs.queue_url" in sqs_attributes)
155-
self.assertEqual(sqs_attributes["aws.sqs.queue_url"], _QUEUE_URL)
156-
self.assertTrue("aws.sqs.queue_name" in sqs_attributes)
157-
self.assertEqual(sqs_attributes["aws.sqs.queue_name"], _QUEUE_NAME)
154+
self.assertTrue("aws.sqs.queue.url" in sqs_attributes)
155+
self.assertEqual(sqs_attributes["aws.sqs.queue.url"], _QUEUE_URL)
156+
self.assertTrue("aws.sqs.queue.name" in sqs_attributes)
157+
self.assertEqual(sqs_attributes["aws.sqs.queue.name"], _QUEUE_NAME)
158158

159159
def _test_patched_gevent_os_ssl_instrumentation(self):
160160
# Only ssl and os module should have been patched since the environment variable was set to 'os, ssl'

contract-tests/tests/test/amazon/botocore/botocore_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
_logger: Logger = getLogger(__name__)
2727
_logger.setLevel(INFO)
2828

29-
_AWS_QUEUE_URL: str = "aws.sqs.queue_url"
30-
_AWS_QUEUE_NAME: str = "aws.sqs.queue_name"
31-
_AWS_STREAM_NAME: str = "aws.kinesis.stream_name"
29+
_AWS_SQS_QUEUE_URL: str = "aws.sqs.queue.url"
30+
_AWS_SQS_QUEUE_NAME: str = "aws.sqs.queue.name"
31+
_AWS_KINESIS_STREAM_NAME: str = "aws.kinesis.stream.name"
3232

3333

3434
# pylint: disable=too-many-public-methods
@@ -248,7 +248,7 @@ def test_sqs_create_queue(self):
248248
remote_resource_type="AWS::SQS::Queue",
249249
remote_resource_identifier="test_queue",
250250
request_specific_attributes={
251-
_AWS_QUEUE_NAME: "test_queue",
251+
_AWS_SQS_QUEUE_NAME: "test_queue",
252252
},
253253
span_name="SQS.CreateQueue",
254254
)
@@ -265,7 +265,7 @@ def test_sqs_send_message(self):
265265
remote_resource_type="AWS::SQS::Queue",
266266
remote_resource_identifier="test_put_get_queue",
267267
request_specific_attributes={
268-
_AWS_QUEUE_URL: "http://localstack:4566/000000000000/test_put_get_queue",
268+
_AWS_SQS_QUEUE_URL: "http://localstack:4566/000000000000/test_put_get_queue",
269269
},
270270
span_name="SQS.SendMessage",
271271
)
@@ -282,7 +282,7 @@ def test_sqs_receive_message(self):
282282
remote_resource_type="AWS::SQS::Queue",
283283
remote_resource_identifier="test_put_get_queue",
284284
request_specific_attributes={
285-
_AWS_QUEUE_URL: "http://localstack:4566/000000000000/test_put_get_queue",
285+
_AWS_SQS_QUEUE_URL: "http://localstack:4566/000000000000/test_put_get_queue",
286286
},
287287
span_name="SQS.ReceiveMessage",
288288
)
@@ -299,7 +299,7 @@ def test_sqs_error(self):
299299
remote_resource_type="AWS::SQS::Queue",
300300
remote_resource_identifier="sqserror",
301301
request_specific_attributes={
302-
_AWS_QUEUE_URL: "http://error.test:8080/000000000000/sqserror",
302+
_AWS_SQS_QUEUE_URL: "http://error.test:8080/000000000000/sqserror",
303303
},
304304
span_name="SQS.SendMessage",
305305
)
@@ -316,7 +316,7 @@ def test_sqs_fault(self):
316316
remote_resource_type="AWS::SQS::Queue",
317317
remote_resource_identifier="invalid_test",
318318
request_specific_attributes={
319-
_AWS_QUEUE_NAME: "invalid_test",
319+
_AWS_SQS_QUEUE_NAME: "invalid_test",
320320
},
321321
span_name="SQS.CreateQueue",
322322
)
@@ -333,7 +333,7 @@ def test_kinesis_put_record(self):
333333
remote_resource_type="AWS::Kinesis::Stream",
334334
remote_resource_identifier="test_stream",
335335
request_specific_attributes={
336-
_AWS_STREAM_NAME: "test_stream",
336+
_AWS_KINESIS_STREAM_NAME: "test_stream",
337337
},
338338
span_name="Kinesis.PutRecord",
339339
)
@@ -350,7 +350,7 @@ def test_kinesis_error(self):
350350
remote_resource_type="AWS::Kinesis::Stream",
351351
remote_resource_identifier="invalid_stream",
352352
request_specific_attributes={
353-
_AWS_STREAM_NAME: "invalid_stream",
353+
_AWS_KINESIS_STREAM_NAME: "invalid_stream",
354354
},
355355
span_name="Kinesis.PutRecord",
356356
)
@@ -367,7 +367,7 @@ def test_kinesis_fault(self):
367367
remote_resource_type="AWS::Kinesis::Stream",
368368
remote_resource_identifier="test_stream",
369369
request_specific_attributes={
370-
_AWS_STREAM_NAME: "test_stream",
370+
_AWS_KINESIS_STREAM_NAME: "test_stream",
371371
},
372372
span_name="Kinesis.PutRecord",
373373
)

0 commit comments

Comments
 (0)