@@ -29,21 +29,24 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
2929 const modifiedConfig : OTLPExporterNodeConfigBase = {
3030 ...config ,
3131 url : endpoint ,
32- compression : CompressionAlgorithm . NONE ,
32+ compression : CompressionAlgorithm . NONE , // Setting Compression to NONE as compression will be handled here.
3333 } ;
3434
3535 super ( modifiedConfig ) ;
3636 this . region = endpoint . split ( '.' ) [ 1 ] ;
3737 this . endpoint = endpoint ;
3838 this . authenticator = new AwsAuthenticator ( this . region , 'xray' ) ;
39+
40+ // This is used in order to prevent serializing and compressing the data twice. Once for signing Sigv4 and
41+ // once when we pass the data to super.export() which will serialize and compress the data again.
3942 this . serializer = new PassthroughSerializer ( ProtobufTraceSerializer . deserializeResponse ) ;
4043 this [ '_delegate' ] . _serializer = this . serializer ;
4144 }
4245
4346 /**
44- * Overrides the upstream implementation of export. All behaviors are the same except if the
45- * endpoint is an XRay OTLP endpoint, we will sign the request with SigV4 in headers before
46- * sending it to the endpoint. Otherwise, we will skip signing .
47+ * Overrides the upstream implementation of export.
48+ * All behaviors are the same except if the endpoint is an XRay OTLP endpoint, we will sign the request with SigV4
49+ * in headers before sending it to the endpoint.
4750 * To prevent performance degradation from serializing and compressing data twice, we handle serialization and compression
4851 * locally in this exporter and pass the pre-processed data to the upstream export functionality.
4952 */
@@ -58,15 +61,17 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
5861 return ;
5962 }
6063
61- // Pass pre-processed data to passthrough serializer. When super.export() is called, the Passthrough Serializer will
62- // use the pre-processed data instead of serializing and compressing the data again.
6364 const shouldCompress = this . compression && this . compression !== CompressionAlgorithm . NONE ;
65+
6466 if ( shouldCompress ) {
6567 serializedSpans = gzipSync ( serializedSpans ) ;
6668 }
6769
70+ // Pass pre-processed data to passthrough serializer. When super.export() is called, the Passthrough Serializer will
71+ // use the pre-processed data instead of serializing and compressing the data again.
6872 this . serializer . setSerializedData ( serializedSpans ) ;
6973
74+ // See type: https://github.com/open-telemetry/opentelemetry-js/blob/experimental/v0.57.1/experimental/packages/otlp-exporter-base/src/transport/http-transport-types.ts#L31
7075 const headers = this [ '_delegate' ] . _transport ?. _transport ?. _parameters ?. headers ( ) ;
7176
7277 if ( headers ) {
@@ -76,11 +81,11 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
7681 delete headers [ 'Content-Encoding' ] ;
7782 }
7883
79- const signedRequest = await this . authenticator . authenticate ( this . endpoint , headers , serializedSpans ) ;
84+ const signedRequestHeaders = await this . authenticator . authenticate ( this . endpoint , headers , serializedSpans ) ;
8085
81- // See type: https://github.com/open-telemetry/opentelemetry-js/blob/experimental/v0.57.1/experimental/packages/otlp-exporter-base/src/transport/http-transport-types.ts#L31
82- const newHeaders : ( ) => Record < string , string > = ( ) => signedRequest ;
83- this [ '_delegate' ] . _transport . _transport . _parameters . headers = newHeaders ;
86+ if ( 'authorization' in signedRequestHeaders ) {
87+ this [ '_delegate' ] . _transport . _transport . _parameters . headers = ( ) => signedRequestHeaders ;
88+ }
8489 } else {
8590 diag . debug ( 'Delegate headers is undefined - unable to authenticate request to XRay OTLP endpoint' ) ;
8691 }
0 commit comments