Skip to content

Commit 264b9cd

Browse files
committed
add CFN primary identifier, fix contract tests
1 parent 995e697 commit 264b9cd

File tree

2 files changed

+16
-101
lines changed

2 files changed

+16
-101
lines changed

src/AWS.Distro.OpenTelemetry.AutoInstrumentation/AwsMetricAttributeGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,13 @@ private static void SetRemoteResourceTypeAndIdentifier(Activity span, ActivityTa
428428
{
429429
remoteResourceType = NormalizedSecretsManagerServiceName + "::Secret";
430430
remoteResourceIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSSecretsManagerSecretArn)).Split(":").Last();
431+
cloudformationPrimaryIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSSecretsManagerSecretArn));
431432
}
432433
else if (IsKeyPresent(span, AttributeAWSSNSTopicArn))
433434
{
434435
remoteResourceType = NormalizedSNSServiceName + "::Topic";
435436
remoteResourceIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSSNSTopicArn)).Split(":").Last();
437+
cloudformationPrimaryIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSSNSTopicArn));
436438
}
437439
else if (IsKeyPresent(span, AttributeAWSSQSQueueName))
438440
{
@@ -450,11 +452,13 @@ private static void SetRemoteResourceTypeAndIdentifier(Activity span, ActivityTa
450452
{
451453
remoteResourceType = NormalizedStepFunctionsName + "::Activity";
452454
remoteResourceIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSStepFunctionsActivityArn)).Split(":").Last();
455+
cloudformationPrimaryIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSStepFunctionsActivityArn));
453456
}
454457
else if (IsKeyPresent(span, AttributeAWSStepFunctionsStateMachineArn))
455458
{
456459
remoteResourceType = NormalizedStepFunctionsName + "::StateMachine";
457460
remoteResourceIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSStepFunctionsStateMachineArn)).Split(":").Last();
461+
cloudformationPrimaryIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSStepFunctionsStateMachineArn));
458462
}
459463
else if (IsKeyPresent(span, AttributeAWSBedrockGuardrailId))
460464
{

test/contract-tests/tests/test/amazon/awssdk/awssdk_test.py

Lines changed: 12 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ def test_secretsmanager_create_secret(self):
336336
remote_operation="CreateSecret",
337337
remote_resource_type="AWS::SecretsManager::Secret",
338338
remote_resource_identifier=r"test-secret-[a-zA-Z0-9]{6}$",
339+
cloudformation_primary_identifier=r"arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-[a-zA-Z0-9]{6}$",
339340
request_response_specific_attributes={
340341
_AWS_SECRETSMANAGER_SECRET_ARN: r"arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-[a-zA-Z0-9]{6}$",
341342
},
@@ -354,6 +355,7 @@ def test_secretsmanager_get_secret_value(self):
354355
remote_operation="GetSecretValue",
355356
remote_resource_type="AWS::SecretsManager::Secret",
356357
remote_resource_identifier=r"test-secret-[a-zA-Z0-9]{6}$",
358+
cloudformation_primary_identifier=r"arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-[a-zA-Z0-9]{6}$",
357359
request_response_specific_attributes={
358360
_AWS_SECRETSMANAGER_SECRET_ARN: r"arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-[a-zA-Z0-9]{6}$",
359361
},
@@ -372,6 +374,7 @@ def test_secretsmanager_error(self):
372374
remote_operation="DescribeSecret",
373375
remote_resource_type="AWS::SecretsManager::Secret",
374376
remote_resource_identifier="test-secret-error",
377+
cloudformation_primary_identifier="arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-error",
375378
request_response_specific_attributes={
376379
_AWS_SECRETSMANAGER_SECRET_ARN: "arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-error",
377380
},
@@ -391,6 +394,7 @@ def test_secretsmanager_error(self):
391394
# remote_operation="CreateSecret",
392395
# remote_resource_type="AWS::SecretsManager::Secret",
393396
# remote_resource_identifier="test-secret-error",
397+
# cloudformation_primary_identifier="arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-error",
394398
# request_response_specific_attributes={
395399
# _AWS_SECRETSMANAGER_SECRET_ARN: "arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-error",
396400
# },
@@ -408,6 +412,7 @@ def test_sns_publish(self):
408412
remote_operation="Publish",
409413
remote_resource_type="AWS::SNS::Topic",
410414
remote_resource_identifier="test-topic",
415+
cloudformation_primary_identifier="arn:aws:sns:us-east-1:000000000000:test-topic",
411416
request_response_specific_attributes={
412417
_AWS_SNS_TOPIC_ARN: "arn:aws:sns:us-east-1:000000000000:test-topic",
413418
},
@@ -425,6 +430,7 @@ def test_sns_error(self):
425430
remote_operation="Publish",
426431
remote_resource_type="AWS::SNS::Topic",
427432
remote_resource_identifier="test-topic-error",
433+
cloudformation_primary_identifier="arn:aws:sns:us-east-1:000000000000:test-topic-error",
428434
request_response_specific_attributes={
429435
_AWS_SNS_TOPIC_ARN: "arn:aws:sns:us-east-1:000000000000:test-topic-error",
430436
},
@@ -443,6 +449,7 @@ def test_sns_error(self):
443449
# remote_operation="GetTopicAttributes",
444450
# remote_resource_type="AWS::SNS::Topic",
445451
# remote_resource_identifier="invalid-topic",
452+
# cloudformation_primary_identifier="arn:aws:sns:us-east-1:000000000000:invalid-topic",
446453
# request_response_specific_attributes={
447454
# _AWS_SNS_TOPIC_ARN: "arn:aws:sns:us-east-1:000000000000:invalid-topic",},
448455
# span_name="SNS.GetTopicAttributes"
@@ -460,6 +467,7 @@ def test_stepfunctions_describe_state_machine(self):
460467
remote_operation="DescribeStateMachine",
461468
remote_resource_type="AWS::StepFunctions::StateMachine",
462469
remote_resource_identifier="test-state-machine",
470+
cloudformation_primary_identifier="arn:aws:states:us-east-1:000000000000:stateMachine:test-state-machine",
463471
request_response_specific_attributes={
464472
_AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: "arn:aws:states:us-east-1:000000000000:stateMachine:test-state-machine",
465473
},
@@ -478,6 +486,7 @@ def test_stepfunctions_describe_activity(self):
478486
remote_operation="DescribeActivity",
479487
remote_resource_type="AWS::StepFunctions::Activity",
480488
remote_resource_identifier="test-activity",
489+
cloudformation_primary_identifier="arn:aws:states:us-east-1:000000000000:activity:test-activity",
481490
request_response_specific_attributes={
482491
_AWS_STEPFUNCTIONS_ACTIVITY_ARN: "arn:aws:states:us-east-1:000000000000:activity:test-activity",
483492
},
@@ -496,6 +505,7 @@ def test_stepfunctions_error(self):
496505
remote_operation="DescribeStateMachine",
497506
remote_resource_type="AWS::StepFunctions::StateMachine",
498507
remote_resource_identifier="error-state-machine",
508+
cloudformation_primary_identifier="arn:aws:states:us-east-1:000000000000:stateMachine:error-state-machine",
499509
request_response_specific_attributes={
500510
_AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: "arn:aws:states:us-east-1:000000000000:stateMachine:error-state-machine",
501511
},
@@ -516,6 +526,7 @@ def test_stepfunctions_error(self):
516526
# remote_operation="ListStateMachineVersions",
517527
# remote_resource_type="AWS::StepFunctions::StateMachine",
518528
# remote_resource_identifier="invalid-state-machine",
529+
# cloudformation_primary_identifier="arn:aws:states:us-east-1:000000000000:stateMachine:invalid-state-machine",
519530
# request_response_specific_attributes={
520531
# _AWS_STEPFUNCTIONS_STATE_MACHINE_ARN: "arn:aws:states:us-east-1:000000000000:stateMachine:invalid-state-machine",},
521532
# span_name="SFN.ListStateMachineVersions",
@@ -533,7 +544,7 @@ def test_bedrock_get_guardrail(self):
533544
remote_operation="GetGuardrail",
534545
remote_resource_type="AWS::Bedrock::Guardrail",
535546
remote_resource_identifier="test-guardrail",
536-
cloudformation_primiary_identifier="test-guardrail",
547+
cloudformation_primary_identifier="test-guardrail",
537548
request_response_specific_attributes={
538549
_AWS_BEDROCK_GUARDRAIL_ID: "test-guardrail",
539550
},
@@ -683,106 +694,6 @@ def test_bedrock_runtime_invoke_model_mistral(self):
683694
remote_resource_type="AWS::Bedrock::Model",
684695
remote_resource_identifier="mistral.mistral-7b-instruct-v0:2",
685696
cloudformation_primary_identifier="mistral.mistral-7b-instruct-v0:2",
686-
request_response_specific_attributes={
687-
_GEN_AI_SYSTEM: "aws_bedrock",
688-
_GEN_AI_REQUEST_MODEL: "mistral.mistral-7b-instruct-v0:2",
689-
_GEN_AI_REQUEST_TEMPERATURE: 0.123,
690-
_GEN_AI_REQUEST_TOP_P: 0.456,
691-
_GEN_AI_REQUEST_MAX_TOKENS: 123,
692-
_GEN_AI_USAGE_INPUT_TOKENS: 456,
693-
_GEN_AI_USAGE_OUTPUT_TOKENS: 789,
694-
_GEN_AI_RESPONSE_FINISH_REASONS: ["finish_reason"],
695-
},
696-
span_name="Bedrock Runtime.InvokeModel",
697-
)
698-
699-
def test_bedrock_runtime_invoke_model_llama(self):
700-
self.do_test_requests(
701-
"bedrock/invokemodel/invoke-model-llama",
702-
"GET",
703-
200,
704-
0,
705-
0,
706-
rpc_service="Bedrock Runtime",
707-
remote_service="AWS::BedrockRuntime",
708-
remote_operation="InvokeModel",
709-
remote_resource_type="AWS::Bedrock::Model",
710-
remote_resource_identifier="meta.llama3-8b-instruct-v1:0",
711-
request_response_specific_attributes={
712-
_GEN_AI_SYSTEM: "aws_bedrock",
713-
_GEN_AI_REQUEST_MODEL: "meta.llama3-8b-instruct-v1:0",
714-
_GEN_AI_REQUEST_TEMPERATURE: 0.123,
715-
_GEN_AI_REQUEST_TOP_P: 0.456,
716-
_GEN_AI_REQUEST_MAX_TOKENS: 123,
717-
_GEN_AI_USAGE_INPUT_TOKENS: 456,
718-
_GEN_AI_USAGE_OUTPUT_TOKENS: 789,
719-
_GEN_AI_RESPONSE_FINISH_REASONS: ["finish_reason"],
720-
},
721-
span_name="Bedrock Runtime.InvokeModel",
722-
)
723-
724-
def test_bedrock_runtime_invoke_model_command(self):
725-
self.do_test_requests(
726-
"bedrock/invokemodel/invoke-model-command",
727-
"GET",
728-
200,
729-
0,
730-
0,
731-
rpc_service="Bedrock Runtime",
732-
remote_service="AWS::BedrockRuntime",
733-
remote_operation="InvokeModel",
734-
remote_resource_type="AWS::Bedrock::Model",
735-
remote_resource_identifier="cohere.command-r-v1:0",
736-
request_response_specific_attributes={
737-
_GEN_AI_SYSTEM: "aws_bedrock",
738-
_GEN_AI_REQUEST_MODEL: "cohere.command-r-v1:0",
739-
_GEN_AI_REQUEST_TEMPERATURE: 0.123,
740-
_GEN_AI_REQUEST_TOP_P: 0.456,
741-
_GEN_AI_REQUEST_MAX_TOKENS: 123,
742-
_GEN_AI_USAGE_INPUT_TOKENS: 12,
743-
_GEN_AI_USAGE_OUTPUT_TOKENS: 10,
744-
_GEN_AI_RESPONSE_FINISH_REASONS: ["finish_reason"],
745-
},
746-
span_name="Bedrock Runtime.InvokeModel",
747-
)
748-
749-
def test_bedrock_runtime_invoke_model_jamba(self):
750-
self.do_test_requests(
751-
"bedrock/invokemodel/invoke-model-jamba",
752-
"GET",
753-
200,
754-
0,
755-
0,
756-
rpc_service="Bedrock Runtime",
757-
remote_service="AWS::BedrockRuntime",
758-
remote_operation="InvokeModel",
759-
remote_resource_type="AWS::Bedrock::Model",
760-
remote_resource_identifier="ai21.jamba-1-5-large-v1:0",
761-
request_response_specific_attributes={
762-
_GEN_AI_SYSTEM: "aws_bedrock",
763-
_GEN_AI_REQUEST_MODEL: "ai21.jamba-1-5-large-v1:0",
764-
_GEN_AI_REQUEST_TEMPERATURE: 0.123,
765-
_GEN_AI_REQUEST_TOP_P: 0.456,
766-
_GEN_AI_REQUEST_MAX_TOKENS: 123,
767-
_GEN_AI_USAGE_INPUT_TOKENS: 456,
768-
_GEN_AI_USAGE_OUTPUT_TOKENS: 789,
769-
_GEN_AI_RESPONSE_FINISH_REASONS: ["finish_reason"],
770-
},
771-
span_name="Bedrock Runtime.InvokeModel",
772-
)
773-
774-
def test_bedrock_runtime_invoke_model_mistral(self):
775-
self.do_test_requests(
776-
"bedrock/invokemodel/invoke-model-mistral",
777-
"GET",
778-
200,
779-
0,
780-
0,
781-
rpc_service="Bedrock Runtime",
782-
remote_service="AWS::BedrockRuntime",
783-
remote_operation="InvokeModel",
784-
remote_resource_type="AWS::Bedrock::Model",
785-
remote_resource_identifier="mistral.mistral-7b-instruct-v0:2",
786697
request_response_specific_attributes={
787698
_GEN_AI_SYSTEM: "aws_bedrock",
788699
_GEN_AI_REQUEST_MODEL: "mistral.mistral-7b-instruct-v0:2",

0 commit comments

Comments
 (0)