|
17 | 17 |
|
18 | 18 | from amazon.opentelemetry.distro._aws_attribute_keys import AWS_LOCAL_SERVICE, AWS_SERVICE_TYPE |
19 | 19 | from amazon.opentelemetry.distro._aws_resource_attribute_configurator import get_service_attribute |
20 | | -from amazon.opentelemetry.distro._utils import get_aws_session, is_agent_observability_enabled |
| 20 | +from amazon.opentelemetry.distro._utils import get_aws_session, is_agentic_observability_enabled |
21 | 21 | from amazon.opentelemetry.distro.always_record_sampler import AlwaysRecordSampler |
22 | 22 | from amazon.opentelemetry.distro.attribute_propagating_span_processor_builder import ( |
23 | 23 | AttributePropagatingSpanProcessorBuilder, |
@@ -204,7 +204,7 @@ def _initialize_components(): |
204 | 204 | AwsEksResourceDetector(), |
205 | 205 | AwsEcsResourceDetector(), |
206 | 206 | ] |
207 | | - if not (_is_lambda_environment() or is_agent_observability_enabled()) |
| 207 | + if not (_is_lambda_environment() or is_agentic_observability_enabled()) |
208 | 208 | else [] |
209 | 209 | ) |
210 | 210 |
|
@@ -326,7 +326,7 @@ def _export_unsampled_span_for_lambda(trace_provider: TracerProvider, resource: |
326 | 326 |
|
327 | 327 |
|
328 | 328 | def _export_unsampled_span_for_agent_observability(trace_provider: TracerProvider, resource: Resource = None): |
329 | | - if not is_agent_observability_enabled(): |
| 329 | + if not is_agentic_observability_enabled(): |
330 | 330 | return |
331 | 331 |
|
332 | 332 | traces_endpoint = os.environ.get(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) |
@@ -467,7 +467,7 @@ def _customize_log_record_processor(logger_provider: LoggerProvider, log_exporte |
467 | 467 | if not log_exporter: |
468 | 468 | return |
469 | 469 |
|
470 | | - if is_agent_observability_enabled(): |
| 470 | + if is_agentic_observability_enabled(): |
471 | 471 | # pylint: disable=import-outside-toplevel |
472 | 472 | from amazon.opentelemetry.distro.exporter.otlp.aws.logs._aws_cw_otlp_batch_log_record_processor import ( |
473 | 473 | AwsCloudWatchOtlpBatchLogRecordProcessor, |
@@ -519,20 +519,18 @@ def _customize_span_processors(provider: TracerProvider, resource: Resource, sam |
519 | 519 | if _is_lambda_environment(): |
520 | 520 | provider.add_span_processor(AwsLambdaSpanProcessor()) |
521 | 521 |
|
522 | | - # We always send 100% spans to Genesis platform for agent observability because |
| 522 | + # Propagates baggage entries matching OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS into span attributes. |
| 523 | + baggage_keys: set[str] = _parse_otel_baggage_keys_env_var() |
| 524 | + |
| 525 | + # We always send 100% spans to AgentCore Runtime platform for agent observability because |
523 | 526 | # AI applications typically have low throughput traffic patterns and require |
524 | 527 | # comprehensive monitoring to catch subtle failure modes like hallucinations |
525 | 528 | # and quality degradation that sampling could miss. |
526 | | - # Add session.id baggage attribute to span attributes to support AI Agent use cases |
527 | | - # enabling session ID tracking in spans. |
528 | | - if is_agent_observability_enabled(): |
| 529 | + if is_agentic_observability_enabled(): |
529 | 530 | _export_unsampled_span_for_agent_observability(provider, resource) |
530 | | - # propagates baggage entries matching OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS into span attributes |
531 | | - raw: str = os.environ.get(OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS, "").strip() |
532 | | - keys: set[str] = {k.strip() for k in raw.split(",") if k.strip()} |
| 531 | + baggage_keys.add("session.id") |
533 | 532 |
|
534 | | - keys.add("session.id") |
535 | | - provider.add_span_processor(BaggageSpanProcessor(lambda key: key in keys)) |
| 533 | + provider.add_span_processor(BaggageSpanProcessor(lambda key: key in baggage_keys)) |
536 | 534 |
|
537 | 535 | if not _is_application_signals_enabled(): |
538 | 536 | return |
@@ -635,7 +633,7 @@ def _customize_resource(resource: Resource) -> Resource: |
635 | 633 |
|
636 | 634 | custom_attributes = {AWS_LOCAL_SERVICE: service_name} |
637 | 635 |
|
638 | | - if is_agent_observability_enabled(): |
| 636 | + if is_agentic_observability_enabled(): |
639 | 637 | # Add aws.service.type if it doesn't exist in the resource |
640 | 638 | if resource and resource.attributes.get(AWS_SERVICE_TYPE) is None: |
641 | 639 | # Set a default agent type for AI agent observability |
@@ -737,6 +735,11 @@ def _fetch_logs_header() -> OtlpLogHeaderSetting: |
737 | 735 | return _otlp_log_header_setting_cache |
738 | 736 |
|
739 | 737 |
|
| 738 | +def _parse_otel_baggage_keys_env_var() -> set[str]: |
| 739 | + raw: str = os.environ.get(OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS, "").strip() |
| 740 | + return {k.strip() for k in raw.split(",") if k.strip()} |
| 741 | + |
| 742 | + |
740 | 743 | def _clear_logs_header_cache(): |
741 | 744 | """Clear the singleton cache for OtlpLogHeaderSetting. Used primarily for testing.""" |
742 | 745 | global _otlp_log_header_setting_cache # pylint: disable=global-statement |
@@ -916,7 +919,7 @@ def _create_aws_otlp_exporter(endpoint: str, service: str, region: str): |
916 | 919 | from amazon.opentelemetry.distro.exporter.otlp.aws.traces.otlp_aws_span_exporter import OTLPAwsSpanExporter |
917 | 920 |
|
918 | 921 | if service == XRAY_SERVICE: |
919 | | - if is_agent_observability_enabled(): |
| 922 | + if is_agentic_observability_enabled(): |
920 | 923 | # Span exporter needs an instance of logger provider in ai agent |
921 | 924 | # observability case because we need to split input/output prompts |
922 | 925 | # from span attributes and send them to the logs pipeline per |
|
0 commit comments