Skip to content

Commit 08ba010

Browse files
committed
add missing special char assertions for sdk client span test case
1 parent db1aa06 commit 08ba010

File tree

1 file changed

+87
-9
lines changed

1 file changed

+87
-9
lines changed

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

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,13 +1179,34 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
11791179
)
11801180
self._mock_attribute([AWS_SECRETSMANAGER_SECRET_ARN], [None])
11811181

1182+
# Validate behaviour of AWS_SECRETSMANAGER_SECRET_ARN attribute with special chars, then remove it.
1183+
self._mock_attribute(
1184+
[AWS_SECRETSMANAGER_SECRET_ARN],
1185+
["arn:aws:secretsmanager:us-east-1:123456789012:secret:secret|name^test-lERW9H"],
1186+
keys,
1187+
values,
1188+
)
1189+
self._validate_remote_resource_attributes(
1190+
"AWS::SecretsManager::Secret",
1191+
"secret^|name^^test-lERW9H",
1192+
"arn:aws:secretsmanager:us-east-1:123456789012:secret:secret^|name^^test-lERW9H",
1193+
)
1194+
self._mock_attribute([AWS_SECRETSMANAGER_SECRET_ARN], [None])
1195+
11821196
# Validate behaviour of AWS_SNS_TOPIC_ARN attribute, then remove it.
11831197
self._mock_attribute([AWS_SNS_TOPIC_ARN], ["arn:aws:sns:us-west-2:012345678901:test_topic"], keys, values)
11841198
self._validate_remote_resource_attributes(
11851199
"AWS::SNS::Topic", "test_topic", "arn:aws:sns:us-west-2:012345678901:test_topic"
11861200
)
11871201
self._mock_attribute([AWS_SNS_TOPIC_ARN], [None])
11881202

1203+
# Validate behaviour of AWS_SNS_TOPIC_ARN attribute with special chars, then remove it.
1204+
self._mock_attribute([AWS_SNS_TOPIC_ARN], ["arn:aws:sns:us-west-2:012345678901:test|topic^name"], keys, values)
1205+
self._validate_remote_resource_attributes(
1206+
"AWS::SNS::Topic", "test^|topic^^name", "arn:aws:sns:us-west-2:012345678901:test^|topic^^name"
1207+
)
1208+
self._mock_attribute([AWS_SNS_TOPIC_ARN], [None])
1209+
11891210
# Validate behaviour of AWS_STEPFUNCTIONS_STATEMACHINE_ARN attribute, then remove it.
11901211
self._mock_attribute(
11911212
[AWS_STEPFUNCTIONS_STATEMACHINE_ARN],
@@ -1200,6 +1221,20 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
12001221
)
12011222
self._mock_attribute([AWS_STEPFUNCTIONS_STATEMACHINE_ARN], [None])
12021223

1224+
# Validate behaviour of AWS_STEPFUNCTIONS_STATEMACHINE_ARN attribute with special chars, then remove it.
1225+
self._mock_attribute(
1226+
[AWS_STEPFUNCTIONS_STATEMACHINE_ARN],
1227+
["arn:aws:states:us-east-1:123456789012:stateMachine:test|state^machine"],
1228+
keys,
1229+
values,
1230+
)
1231+
self._validate_remote_resource_attributes(
1232+
"AWS::StepFunctions::StateMachine",
1233+
"test^|state^^machine",
1234+
"arn:aws:states:us-east-1:123456789012:stateMachine:test^|state^^machine",
1235+
)
1236+
self._mock_attribute([AWS_STEPFUNCTIONS_STATEMACHINE_ARN], [None])
1237+
12031238
# Validate behaviour of AWS_STEPFUNCTIONS_ACTIVITY_ARN attribute, then remove it.
12041239
self._mock_attribute(
12051240
[AWS_STEPFUNCTIONS_ACTIVITY_ARN],
@@ -1214,22 +1249,30 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
12141249
)
12151250
self._mock_attribute([AWS_STEPFUNCTIONS_ACTIVITY_ARN], [None])
12161251

1217-
# Validate behaviour of AWS_LAMBDA_RESOURCEMAPPING_ID attribute, then remove it.
1218-
self._mock_attribute([AWS_LAMBDA_RESOURCEMAPPING_ID], ["aws_event_source_mapping_id"], keys, values)
1219-
self._validate_remote_resource_attributes("AWS::Lambda::EventSourceMapping", "aws_event_source_mapping_id")
1220-
self._mock_attribute([AWS_LAMBDA_RESOURCEMAPPING_ID], [None])
1221-
1222-
# Validate behaviour of AWS_LAMBDA_RESOURCE_MAPPING_ID,
1223-
# then remove it.
1252+
# Validate behaviour of AWS_STEPFUNCTIONS_ACTIVITY_ARN attribute with special chars, then remove it.
12241253
self._mock_attribute(
1225-
[AWS_LAMBDA_RESOURCEMAPPING_ID],
1226-
["aws_event_source_mapping_id"],
1254+
[AWS_STEPFUNCTIONS_ACTIVITY_ARN],
1255+
["arn:aws:states:us-east-1:007003123456789012:activity:test|Activity^name"],
12271256
keys,
12281257
values,
12291258
)
1259+
self._validate_remote_resource_attributes(
1260+
"AWS::StepFunctions::Activity",
1261+
"test^|Activity^^name",
1262+
"arn:aws:states:us-east-1:007003123456789012:activity:test^|Activity^^name",
1263+
)
1264+
self._mock_attribute([AWS_STEPFUNCTIONS_ACTIVITY_ARN], [None])
1265+
1266+
# Validate behaviour of AWS_LAMBDA_RESOURCEMAPPING_ID attribute, then remove it.
1267+
self._mock_attribute([AWS_LAMBDA_RESOURCEMAPPING_ID], ["aws_event_source_mapping_id"], keys, values)
12301268
self._validate_remote_resource_attributes("AWS::Lambda::EventSourceMapping", "aws_event_source_mapping_id")
12311269
self._mock_attribute([AWS_LAMBDA_RESOURCEMAPPING_ID], [None])
12321270

1271+
# Validate behaviour of AWS_LAMBDA_RESOURCEMAPPING_ID attribute with special chars, then remove it.
1272+
self._mock_attribute([AWS_LAMBDA_RESOURCEMAPPING_ID], ["aws_event|source^mapping_id"], keys, values)
1273+
self._validate_remote_resource_attributes("AWS::Lambda::EventSourceMapping", "aws_event^|source^^mapping_id")
1274+
self._mock_attribute([AWS_LAMBDA_RESOURCEMAPPING_ID], [None])
1275+
12331276
# Test AWS Lambda Invoke scenario with default lambda remote environment
12341277
self.span_mock.kind = SpanKind.CLIENT
12351278
self._mock_attribute(
@@ -1319,6 +1362,41 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
13191362
[None, None, None, None, None],
13201363
)
13211364

1365+
# Validate behaviour of AWS_LAMBDA_NAME for non-Invoke operations with special chars
1366+
self._mock_attribute(
1367+
[
1368+
SpanAttributes.RPC_SYSTEM,
1369+
SpanAttributes.RPC_SERVICE,
1370+
SpanAttributes.RPC_METHOD,
1371+
AWS_LAMBDA_FUNCTION_NAME,
1372+
AWS_LAMBDA_FUNCTION_ARN,
1373+
],
1374+
[
1375+
"aws-api",
1376+
"Lambda",
1377+
"GetFunction",
1378+
"test|Lambda^Name",
1379+
"arn:aws:lambda:us-east-1:123456789012:function:test|Lambda^Name",
1380+
],
1381+
keys,
1382+
values,
1383+
)
1384+
self._validate_remote_resource_attributes(
1385+
"AWS::Lambda::Function",
1386+
"test^|Lambda^^Name",
1387+
"arn:aws:lambda:us-east-1:123456789012:function:test^|Lambda^^Name",
1388+
)
1389+
self._mock_attribute(
1390+
[
1391+
SpanAttributes.RPC_SYSTEM,
1392+
SpanAttributes.RPC_SERVICE,
1393+
SpanAttributes.RPC_METHOD,
1394+
AWS_LAMBDA_FUNCTION_NAME,
1395+
AWS_LAMBDA_FUNCTION_ARN,
1396+
],
1397+
[None, None, None, None, None],
1398+
)
1399+
13221400
# Validate that Lambda Invoke with function name treats Lambda as a service, not a resource
13231401
self._mock_attribute(
13241402
[

0 commit comments

Comments
 (0)