Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
AWS_LAMBDA_FUNCTION_NAME: str = "aws.lambda.function.name"
AWS_LAMBDA_RESOURCEMAPPING_ID: str = "aws.lambda.resource_mapping.id"
AWS_LAMBDA_FUNCTION_ARN: str = "aws.lambda.function.arn"
AWS_AI_AGENT_TYPE: str = "aws.ai.agent.type"
AWS_SERVICE_TYPE: str = "aws.service.type"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from importlib_metadata import version
from typing_extensions import override

from amazon.opentelemetry.distro._aws_attribute_keys import AWS_AI_AGENT_TYPE, AWS_LOCAL_SERVICE
from amazon.opentelemetry.distro._aws_attribute_keys import AWS_LOCAL_SERVICE, AWS_SERVICE_TYPE
from amazon.opentelemetry.distro._aws_resource_attribute_configurator import get_service_attribute
from amazon.opentelemetry.distro._utils import is_agent_observability_enabled, is_installed
from amazon.opentelemetry.distro.always_record_sampler import AlwaysRecordSampler
Expand Down Expand Up @@ -558,10 +558,10 @@ def _customize_resource(resource: Resource) -> Resource:
custom_attributes = {AWS_LOCAL_SERVICE: service_name}

if is_agent_observability_enabled():
# Add aws.ai.agent.type if it doesn't exist in the resource
if resource and resource.attributes.get(AWS_AI_AGENT_TYPE) is None:
# Add aws.service.type if it doesn't exist in the resource
if resource and resource.attributes.get(AWS_SERVICE_TYPE) is None:
# Set a default agent type for AI agent observability
custom_attributes[AWS_AI_AGENT_TYPE] = "default"
custom_attributes[AWS_SERVICE_TYPE] = "gen_ai_agent"

return resource.merge(Resource.create(custom_attributes))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from requests import Session

from amazon.opentelemetry.distro._aws_attribute_keys import AWS_AI_AGENT_TYPE, AWS_LOCAL_SERVICE
from amazon.opentelemetry.distro._aws_attribute_keys import AWS_LOCAL_SERVICE, AWS_SERVICE_TYPE
from amazon.opentelemetry.distro.always_record_sampler import AlwaysRecordSampler
from amazon.opentelemetry.distro.attribute_propagating_span_processor import AttributePropagatingSpanProcessor
from amazon.opentelemetry.distro.aws_batch_unsampled_span_processor import BatchUnsampledSpanProcessor
Expand Down Expand Up @@ -1106,7 +1106,7 @@ def test_customize_resource_without_agent_observability(self, mock_get_service_a

# Should only have AWS_LOCAL_SERVICE added
self.assertEqual(result.attributes[AWS_LOCAL_SERVICE], "test-service")
self.assertNotIn(AWS_AI_AGENT_TYPE, result.attributes)
self.assertNotIn(AWS_SERVICE_TYPE, result.attributes)

@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator.is_agent_observability_enabled")
@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator.get_service_attribute")
Expand All @@ -1120,9 +1120,9 @@ def test_customize_resource_with_agent_observability_default(
resource = Resource.create({ResourceAttributes.SERVICE_NAME: "test-service"})
result = _customize_resource(resource)

# Should have both AWS_LOCAL_SERVICE and AWS_AI_AGENT_TYPE with default value
# Should have both AWS_LOCAL_SERVICE and AWS_SERVICE_TYPE with default value
self.assertEqual(result.attributes[AWS_LOCAL_SERVICE], "test-service")
self.assertEqual(result.attributes[AWS_AI_AGENT_TYPE], "default")
self.assertEqual(result.attributes[AWS_SERVICE_TYPE], "gen_ai_agent")

@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator.is_agent_observability_enabled")
@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator.get_service_attribute")
Expand All @@ -1133,13 +1133,13 @@ def test_customize_resource_with_existing_agent_type(self, mock_get_service_attr

# Create resource with existing agent type
resource = Resource.create(
{ResourceAttributes.SERVICE_NAME: "test-service", AWS_AI_AGENT_TYPE: "existing-agent"}
{ResourceAttributes.SERVICE_NAME: "test-service", AWS_SERVICE_TYPE: "existing-agent"}
)
result = _customize_resource(resource)

# Should preserve existing agent type and not override it
self.assertEqual(result.attributes[AWS_LOCAL_SERVICE], "test-service")
self.assertEqual(result.attributes[AWS_AI_AGENT_TYPE], "existing-agent")
self.assertEqual(result.attributes[AWS_SERVICE_TYPE], "existing-agent")


def validate_distro_environ():
Expand Down
Loading