@@ -42,7 +42,7 @@ import {
4242 checkEmfExporterEnabled ,
4343 createEmfExporter ,
4444 customBuildSamplerFromEnv ,
45- isXrayOtlpEndpoint ,
45+ isAwsOtlpEndpoint ,
4646 validateAndFetchLogsHeader ,
4747} from '../src/aws-opentelemetry-configurator' ;
4848import { AwsSpanMetricsProcessor } from '../src/aws-span-metrics-processor' ;
@@ -804,80 +804,6 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
804804 delete process . env . OTEL_EXPORTER_OTLP_TRACES_PROTOCOL ;
805805 } ) ;
806806
807- it ( 'ExportUnsampledSpanForAgentObservabilityTest' , ( ) => {
808- const spanProcessorsToTest : SpanProcessor [ ] = [ ] ;
809-
810- // Test with agent observability disabled
811- AwsOpentelemetryConfigurator . exportUnsampledSpanForAgentObservability ( spanProcessorsToTest , Resource . empty ( ) ) ;
812- expect ( spanProcessorsToTest ) . toEqual ( [ ] ) ;
813-
814- // Test with agent observability enabled
815- process . env . AGENT_OBSERVABILITY_ENABLED = 'true' ;
816- process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'https://xray.us-east-1.amazonaws.com/v1/traces' ;
817-
818- AwsOpentelemetryConfigurator . exportUnsampledSpanForAgentObservability ( spanProcessorsToTest , Resource . empty ( ) ) ;
819- expect ( spanProcessorsToTest . length ) . toEqual ( 1 ) ;
820-
821- const processor = spanProcessorsToTest [ 0 ] ;
822- expect ( processor ) . toBeInstanceOf ( AwsBatchUnsampledSpanProcessor ) ;
823-
824- // Cleanup
825- delete process . env . AGENT_OBSERVABILITY_ENABLED ;
826- delete process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ;
827- } ) ;
828-
829- it ( 'ExportUnsampledSpanForAgentObservabilityUsesOtlpAwsSpanExporterTest' , ( ) => {
830- const spanProcessorsToTest : SpanProcessor [ ] = [ ] ;
831-
832- process . env . AGENT_OBSERVABILITY_ENABLED = 'true' ;
833- process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'https://xray.us-east-1.amazonaws.com/v1/traces' ;
834-
835- AwsOpentelemetryConfigurator . exportUnsampledSpanForAgentObservability ( spanProcessorsToTest , Resource . empty ( ) ) ;
836-
837- // Verify AwsBatchUnsampledSpanProcessor was created with the AWS exporter
838- expect ( spanProcessorsToTest [ 0 ] ) . toBeInstanceOf ( AwsBatchUnsampledSpanProcessor ) ;
839- const otlpAwsSpanExporter = ( spanProcessorsToTest [ 0 ] as AwsBatchUnsampledSpanProcessor ) [ '_exporter' ] ;
840-
841- // Verify OTLPAwsSpanExporter was created with correct parameters
842- expect ( otlpAwsSpanExporter ) . toBeInstanceOf ( OTLPAwsSpanExporter ) ;
843- expect ( otlpAwsSpanExporter [ 'endpoint' ] ) . toEqual ( 'https://xray.us-east-1.amazonaws.com/v1/traces' ) ;
844- expect ( otlpAwsSpanExporter [ 'loggerProvider' ] ) . toBeDefined ( ) ;
845-
846- // Cleanup environment variables
847- delete process . env . AGENT_OBSERVABILITY_ENABLED ;
848- delete process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ;
849- } ) ;
850-
851- it ( 'CustomizeSpanProcessorsCallsExportUnsampledSpanTest' , ( ) => {
852- const spanProcessorsToTest : SpanProcessor [ ] = [ ] ;
853-
854- // Create spy for exportUnsampledSpanForAgentObservability
855- const exportUnsampledSpanSpy = sinon . spy (
856- AwsOpentelemetryConfigurator ,
857- 'exportUnsampledSpanForAgentObservability'
858- ) ;
859-
860- try {
861- // Test that function is NOT called when agent observability is disabled
862- delete process . env . AGENT_OBSERVABILITY_ENABLED ;
863- AwsOpentelemetryConfigurator . customizeSpanProcessors ( spanProcessorsToTest , Resource . empty ( ) ) ;
864- expect ( exportUnsampledSpanSpy . called ) . toBeFalsy ( ) ;
865-
866- // Test that function is called when agent observability is enabled
867- exportUnsampledSpanSpy . resetHistory ( ) ;
868- process . env . AGENT_OBSERVABILITY_ENABLED = 'true' ;
869- AwsOpentelemetryConfigurator . customizeSpanProcessors ( spanProcessorsToTest , Resource . empty ( ) ) ;
870- expect ( exportUnsampledSpanSpy . calledOnce ) . toBeTruthy ( ) ;
871- expect ( exportUnsampledSpanSpy . calledWith ( spanProcessorsToTest , Resource . empty ( ) ) ) . toBeTruthy ( ) ;
872- } finally {
873- // Restore original implementation
874- exportUnsampledSpanSpy . restore ( ) ;
875-
876- // Cleanup
877- delete process . env . AGENT_OBSERVABILITY_ENABLED ;
878- }
879- } ) ;
880-
881807 it ( 'configureOtlp - OtlpAwsSpanExporter' , ( ) => {
882808 const OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT' ;
883809 const OTEL_TRACES_EXPORTER = 'OTEL_TRACES_EXPORTER' ;
@@ -1125,6 +1051,77 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
11251051 } ) ;
11261052 } ) ;
11271053
1054+ it ( 'ExportUnsampledSpanForAgentObservabilityTest' , ( ) => {
1055+ const spanProcessorsToTest : SpanProcessor [ ] = [ ] ;
1056+
1057+ // Test with agent observability disabled
1058+ AwsOpentelemetryConfigurator . exportUnsampledSpanForAgentObservability ( spanProcessorsToTest , Resource . empty ( ) ) ;
1059+ expect ( spanProcessorsToTest ) . toEqual ( [ ] ) ;
1060+
1061+ // Test with agent observability enabled
1062+ process . env . AGENT_OBSERVABILITY_ENABLED = 'true' ;
1063+ process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'https://xray.us-east-1.amazonaws.com/v1/traces' ;
1064+
1065+ AwsOpentelemetryConfigurator . exportUnsampledSpanForAgentObservability ( spanProcessorsToTest , Resource . empty ( ) ) ;
1066+ expect ( spanProcessorsToTest . length ) . toEqual ( 1 ) ;
1067+
1068+ const processor = spanProcessorsToTest [ 0 ] ;
1069+ expect ( processor ) . toBeInstanceOf ( AwsBatchUnsampledSpanProcessor ) ;
1070+
1071+ // Cleanup
1072+ delete process . env . AGENT_OBSERVABILITY_ENABLED ;
1073+ delete process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ;
1074+ } ) ;
1075+
1076+ it ( 'ExportUnsampledSpanForAgentObservabilityUsesOtlpAwsSpanExporterTest' , ( ) => {
1077+ const spanProcessorsToTest : SpanProcessor [ ] = [ ] ;
1078+
1079+ process . env . AGENT_OBSERVABILITY_ENABLED = 'true' ;
1080+ process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'https://xray.us-east-1.amazonaws.com/v1/traces' ;
1081+
1082+ AwsOpentelemetryConfigurator . exportUnsampledSpanForAgentObservability ( spanProcessorsToTest , Resource . empty ( ) ) ;
1083+
1084+ // Verify AwsBatchUnsampledSpanProcessor was created with the AWS exporter
1085+ expect ( spanProcessorsToTest [ 0 ] ) . toBeInstanceOf ( AwsBatchUnsampledSpanProcessor ) ;
1086+ const otlpAwsSpanExporter = ( spanProcessorsToTest [ 0 ] as AwsBatchUnsampledSpanProcessor ) [ '_exporter' ] ;
1087+
1088+ // Verify OTLPAwsSpanExporter was created with correct parameters
1089+ expect ( otlpAwsSpanExporter ) . toBeInstanceOf ( OTLPAwsSpanExporter ) ;
1090+ expect ( otlpAwsSpanExporter [ 'endpoint' ] ) . toEqual ( 'https://xray.us-east-1.amazonaws.com/v1/traces' ) ;
1091+ expect ( otlpAwsSpanExporter [ 'loggerProvider' ] ) . toBeDefined ( ) ;
1092+
1093+ // Cleanup environment variables
1094+ delete process . env . AGENT_OBSERVABILITY_ENABLED ;
1095+ delete process . env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ;
1096+ } ) ;
1097+
1098+ it ( 'CustomizeSpanProcessorsCallsExportUnsampledSpanTest' , ( ) => {
1099+ const spanProcessorsToTest : SpanProcessor [ ] = [ ] ;
1100+
1101+ // Create spy for exportUnsampledSpanForAgentObservability
1102+ const exportUnsampledSpanSpy = sinon . spy ( AwsOpentelemetryConfigurator , 'exportUnsampledSpanForAgentObservability' ) ;
1103+
1104+ try {
1105+ // Test that function is NOT called when agent observability is disabled
1106+ delete process . env . AGENT_OBSERVABILITY_ENABLED ;
1107+ AwsOpentelemetryConfigurator . customizeSpanProcessors ( spanProcessorsToTest , Resource . empty ( ) ) ;
1108+ expect ( exportUnsampledSpanSpy . called ) . toBeFalsy ( ) ;
1109+
1110+ // Test that function is called when agent observability is enabled
1111+ exportUnsampledSpanSpy . resetHistory ( ) ;
1112+ process . env . AGENT_OBSERVABILITY_ENABLED = 'true' ;
1113+ AwsOpentelemetryConfigurator . customizeSpanProcessors ( spanProcessorsToTest , Resource . empty ( ) ) ;
1114+ expect ( exportUnsampledSpanSpy . calledOnce ) . toBeTruthy ( ) ;
1115+ expect ( exportUnsampledSpanSpy . calledWith ( spanProcessorsToTest , Resource . empty ( ) ) ) . toBeTruthy ( ) ;
1116+ } finally {
1117+ // Restore original implementation
1118+ exportUnsampledSpanSpy . restore ( ) ;
1119+
1120+ // Cleanup
1121+ delete process . env . AGENT_OBSERVABILITY_ENABLED ;
1122+ }
1123+ } ) ;
1124+
11281125 it ( 'testCheckEmfExporterEnabled' , ( ) => {
11291126 process . env . OTEL_METRICS_EXPORTER = 'first,awsemf,third' ;
11301127 checkEmfExporterEnabled ( ) ;
@@ -1140,9 +1137,12 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
11401137 } ) ;
11411138
11421139 it ( 'testIsAwsOtlpEndpoint' , ( ) => {
1143- expect ( isXrayOtlpEndpoint ( 'https://xray.us-east-1.amazonaws.com/v1/traces' ) ) . toBeTruthy ( ) ;
1144- expect ( isXrayOtlpEndpoint ( 'https://lambda.us-east-1.amazonaws.com/v1/traces' ) ) . toBeFalsy ( ) ;
1145- expect ( isXrayOtlpEndpoint ( 'https://xray.us-east-1.amazonaws.com/v1/logs' ) ) . toBeFalsy ( ) ;
1140+ expect ( isAwsOtlpEndpoint ( 'https://xray.us-east-1.amazonaws.com/v1/traces' , 'xray' ) ) . toBeTruthy ( ) ;
1141+ expect ( isAwsOtlpEndpoint ( 'https://lambda.us-east-1.amazonaws.com/v1/traces' , 'xray' ) ) . toBeFalsy ( ) ;
1142+ expect ( isAwsOtlpEndpoint ( 'https://xray.us-east-1.amazonaws.com/v1/logs' , 'xray' ) ) . toBeFalsy ( ) ;
1143+ expect ( isAwsOtlpEndpoint ( 'https://logs.us-east-1.amazonaws.com/v1/logs' , 'logs' ) ) . toBeTruthy ( ) ;
1144+ expect ( isAwsOtlpEndpoint ( 'https://lambda.us-east-1.amazonaws.com/v1/logs' , 'logs' ) ) . toBeFalsy ( ) ;
1145+ expect ( isAwsOtlpEndpoint ( 'https://logs.us-east-1.amazonaws.com/v1/traces' , 'logs' ) ) . toBeFalsy ( ) ;
11461146 } ) ;
11471147
11481148 it ( 'testvalidateAndFetchLogsHeader' , ( ) => {
0 commit comments