Skip to content

Commit 46a358d

Browse files
committed
feat: Add span data for Step Functions
1 parent 8462cd4 commit 46a358d

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@
2525
AWS_BEDROCK_AGENT_ID: str = "aws.bedrock.agent.id"
2626
AWS_BEDROCK_GUARDRAIL_ID: str = "aws.bedrock.guardrail.id"
2727
AWS_SECRETSMANAGER_SECRET_ARN: str = "aws.secretsmanager.secret.arn"
28+
AWS_STEPFUNCTIONS_STATEMACHINE_ARN: str = "aws.stepfunctions.state_machine.arn"
29+
AWS_STEPFUNCTIONS_ACTIVITY_ARN: str = "aws.stepfunctions.activity.arn"

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
AWS_SPAN_KIND,
2525
AWS_SQS_QUEUE_NAME,
2626
AWS_SQS_QUEUE_URL,
27+
AWS_STEPFUNCTIONS_ACTIVITY_ARN,
28+
AWS_STEPFUNCTIONS_STATEMACHINE_ARN,
2729
)
2830
from amazon.opentelemetry.distro._aws_span_processing_util import (
2931
GEN_AI_REQUEST_MODEL,
@@ -92,6 +94,7 @@
9294
_NORMALIZED_BEDROCK_SERVICE_NAME: str = "AWS::Bedrock"
9395
_NORMALIZED_BEDROCK_RUNTIME_SERVICE_NAME: str = "AWS::BedrockRuntime"
9496
_NORMALIZED_SECRETSMANAGER_SERVICE_NAME: str = "AWS::SecretsManager"
97+
_NORMALIZED_STEPFUNCTIONS_SERVICE_NAME: str = "AWS::StepFunctions"
9598
_DB_CONNECTION_STRING_TYPE: str = "DB::Connection"
9699

97100
# Special DEPENDENCY attribute value if GRAPHQL_OPERATION_TYPE attribute key is present.
@@ -314,6 +317,7 @@ def _normalize_remote_service_name(span: ReadableSpan, service_name: str) -> str
314317
"Bedrock Agent Runtime": _NORMALIZED_BEDROCK_SERVICE_NAME,
315318
"Bedrock Runtime": _NORMALIZED_BEDROCK_RUNTIME_SERVICE_NAME,
316319
"Secrets Manager": _NORMALIZED_SECRETSMANAGER_SERVICE_NAME,
320+
"SFN": _NORMALIZED_STEPFUNCTIONS_SERVICE_NAME,
317321
}
318322
return aws_sdk_service_mapping.get(service_name, "AWS::" + service_name)
319323
return service_name
@@ -436,7 +440,16 @@ def _set_remote_type_and_identifier(span: ReadableSpan, attributes: BoundedAttri
436440
remote_resource_type = _NORMALIZED_SECRETSMANAGER_SERVICE_NAME + "::Secret"
437441
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_SECRETSMANAGER_SECRET_ARN))
438442
cloudformation_primary_identifier = remote_resource_identifier
443+
elif is_key_present(span, AWS_STEPFUNCTIONS_STATEMACHINE_ARN):
444+
remote_resource_type = _NORMALIZED_STEPFUNCTIONS_SERVICE_NAME + "::StateMachine"
445+
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_STEPFUNCTIONS_STATEMACHINE_ARN))
446+
cloudformation_primary_identifier = remote_resource_identifier
447+
elif is_key_present(span, AWS_STEPFUNCTIONS_ACTIVITY_ARN):
448+
remote_resource_type = _NORMALIZED_STEPFUNCTIONS_SERVICE_NAME + "::Activity"
449+
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_STEPFUNCTIONS_ACTIVITY_ARN))
450+
cloudformation_primary_identifier = remote_resource_identifier
439451
elif is_db_span(span):
452+
_logger.debug("DB span detected")
440453
remote_resource_type = _DB_CONNECTION_STRING_TYPE
441454
remote_resource_identifier = _get_db_connection(span)
442455

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
from amazon.opentelemetry.distro._aws_attribute_keys import (
77
AWS_KINESIS_STREAM_NAME,
8+
AWS_SECRETSMANAGER_SECRET_ARN,
89
AWS_SQS_QUEUE_NAME,
910
AWS_SQS_QUEUE_URL,
11+
AWS_STEPFUNCTIONS_ACTIVITY_ARN,
12+
AWS_STEPFUNCTIONS_STATEMACHINE_ARN,
1013
)
1114
from amazon.opentelemetry.distro.patches._bedrock_patches import ( # noqa # pylint: disable=unused-import
1215
_BedrockAgentExtension,
@@ -33,6 +36,18 @@ def _apply_botocore_instrumentation_patches() -> None:
3336
_apply_botocore_bedrock_patch()
3437
_apply_botocore_sns_patch()
3538
_apply_botocore_secretsmanager_patch()
39+
_apply_botocore_stepfunctions_patch()
40+
41+
42+
def _apply_botocore_stepfunctions_patch() -> None:
43+
"""Botocore instrumentation patch for StepFunctions
44+
45+
This patch adds an extension to the upstream's list of known extensions for
46+
StepFunctions. Extensionse allow for custom logic for adding service-specific
47+
information to spans, such as attributes. Specifically, we are adding logic
48+
to add the AWS_STEPFUNCTIONS_STATEMACHINE_ARN attribute.
49+
"""
50+
_KNOWN_EXTENSIONS["stepfunctions"] = _lazy_load(".", "_StepFunctionsExtension")
3651

3752

3853
def _apply_botocore_secretsmanager_patch() -> None:
@@ -145,6 +160,16 @@ def loader():
145160
# END The OpenTelemetry Authors code
146161

147162

163+
class _StepFunctionsExtension(_AwsSdkExtension):
164+
def extract_attributes(self, attributes: _AttributeMapT):
165+
state_machine_arn = self._call_context.params.get("stateMachineArn")
166+
if state_machine_arn:
167+
attributes[AWS_STEPFUNCTIONS_STATEMACHINE_ARN] = state_machine_arn
168+
activity_arn = self._call_context.params.get("activityArn")
169+
if activity_arn:
170+
attributes[AWS_STEPFUNCTIONS_ACTIVITY_ARN] = activity_arn
171+
172+
148173
class _SecretsManagerExtension(_AwsSdkExtension):
149174
def extract_attributes(self, attributes: _AttributeMapT):
150175
"""
@@ -154,7 +179,7 @@ def extract_attributes(self, attributes: _AttributeMapT):
154179
"""
155180
secret_id = self._call_context.params.get("SecretId")
156181
if secret_id and secret_id.startswith("arn:aws:secretsmanager:"):
157-
attributes["aws.secretsmanager.secret.arn"] = secret_id
182+
attributes[AWS_SECRETSMANAGER_SECRET_ARN] = secret_id
158183

159184
# pylint: disable=no-self-use
160185
def on_success(self, span: Span, result: _BotoResultT):

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ def test_normalize_remote_service_name_aws_sdk(self):
881881
self.validate_aws_sdk_service_normalization("Bedrock Runtime", "AWS::BedrockRuntime")
882882
self.validate_aws_sdk_service_normalization("SNS", "AWS::SNS")
883883
self.validate_aws_sdk_service_normalization("Secrets Manager", "AWS::SecretsManager")
884+
self.validate_aws_sdk_service_normalization("SFN", "AWS::StepFunctions")
884885

885886
def validate_aws_sdk_service_normalization(self, service_name: str, expected_remote_service: str):
886887
self._mock_attribute([SpanAttributes.RPC_SYSTEM, SpanAttributes.RPC_SERVICE], ["aws-api", service_name])

0 commit comments

Comments
 (0)