Skip to content

Commit 629faf5

Browse files
authored
Move Sigv4 Log Configuration Message (#232)
*Issue #, if available:* *Description of changes:* Migrate Python change aws-observability/aws-otel-python-instrumentation#420 to JS. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent cc55fa3 commit 629faf5

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -561,42 +561,52 @@ export class AwsLoggerProcessorProvider {
561561
case 'http/json':
562562
exporters.push(new OTLPHttpLogExporter());
563563
break;
564-
case 'http/protobuf':
565-
if (
566-
otlpExporterLogsEndpoint &&
567-
isAwsOtlpEndpoint(otlpExporterLogsEndpoint, 'logs') &&
568-
validateAndFetchLogsHeader().isValid
569-
) {
564+
case 'http/protobuf': {
565+
let logExporter: LogRecordExporter | undefined = undefined;
566+
if (otlpExporterLogsEndpoint && isAwsOtlpEndpoint(otlpExporterLogsEndpoint, 'logs')) {
570567
diag.debug('Detected CloudWatch Logs OTLP endpoint. Switching exporter to OTLPAwsLogExporter');
571-
exporters.push(
572-
new OTLPAwsLogExporter(otlpExporterLogsEndpoint.toLowerCase(), {
568+
if (validateAndFetchLogsHeader().isValid) {
569+
logExporter = new OTLPAwsLogExporter(otlpExporterLogsEndpoint.toLowerCase(), {
573570
compression: CompressionAlgorithm.GZIP,
574-
})
575-
);
576-
} else {
577-
exporters.push(new OTLPProtoLogExporter());
571+
});
572+
} else {
573+
diag.warn(
574+
`Invalid configuration for OTLPAwsLogExporter, please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS to have values for ${AWS_OTLP_LOGS_GROUP_HEADER} and ${AWS_OTLP_LOGS_STREAM_HEADER}. Falling back to OTLPProtoLogExporter`
575+
);
576+
}
578577
}
578+
579+
if (!logExporter) {
580+
logExporter = new OTLPProtoLogExporter();
581+
}
582+
exporters.push(logExporter);
579583
break;
584+
}
580585
case undefined:
581586
case '':
582587
exporters.push(new OTLPProtoLogExporter());
583588
break;
584-
default:
589+
default: {
585590
diag.warn(`Unsupported OTLP logs protocol: "${protocol}". Using http/protobuf.`);
586-
if (
587-
otlpExporterLogsEndpoint &&
588-
isAwsOtlpEndpoint(otlpExporterLogsEndpoint, 'logs') &&
589-
validateAndFetchLogsHeader().isValid
590-
) {
591+
let logExporter: LogRecordExporter | undefined = undefined;
592+
if (otlpExporterLogsEndpoint && isAwsOtlpEndpoint(otlpExporterLogsEndpoint, 'logs')) {
591593
diag.debug('Detected CloudWatch Logs OTLP endpoint. Switching exporter to OTLPAwsLogExporter');
592-
exporters.push(
593-
new OTLPAwsLogExporter(otlpExporterLogsEndpoint.toLowerCase(), {
594+
if (validateAndFetchLogsHeader().isValid) {
595+
logExporter = new OTLPAwsLogExporter(otlpExporterLogsEndpoint.toLowerCase(), {
594596
compression: CompressionAlgorithm.GZIP,
595-
})
596-
);
597-
} else {
598-
exporters.push(new OTLPProtoLogExporter());
597+
});
598+
} else {
599+
diag.warn(
600+
`Invalid configuration for OTLPAwsLogExporter, please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS to have values for ${AWS_OTLP_LOGS_GROUP_HEADER} and ${AWS_OTLP_LOGS_STREAM_HEADER}. Falling back to OTLPProtoLogExporter`
601+
);
602+
}
603+
}
604+
605+
if (!logExporter) {
606+
logExporter = new OTLPProtoLogExporter();
599607
}
608+
exporters.push(logExporter);
609+
}
600610
}
601611
} else if (exporter === 'console') {
602612
exporters.push(new ConsoleLogRecordExporter());
@@ -967,7 +977,6 @@ export function validateAndFetchLogsHeader(): OtlpLogHeaderSetting {
967977
let logGroup: string | undefined = undefined;
968978
let logStream: string | undefined = undefined;
969979
let namespace: string | undefined = undefined;
970-
let filteredLogHeadersCount: number = 0;
971980

972981
for (const pair of logHeaders.split(',')) {
973982
const splitIndex = pair.indexOf('=');
@@ -977,23 +986,15 @@ export function validateAndFetchLogsHeader(): OtlpLogHeaderSetting {
977986

978987
if (key === AWS_OTLP_LOGS_GROUP_HEADER && value) {
979988
logGroup = value;
980-
filteredLogHeadersCount++;
981989
} else if (key === AWS_OTLP_LOGS_STREAM_HEADER && value) {
982990
logStream = value;
983-
filteredLogHeadersCount++;
984991
} else if (key === AWS_EMF_METRICS_NAMESPACE && value) {
985992
namespace = value;
986993
}
987994
}
988995
}
989996

990-
const isValid = filteredLogHeadersCount === 2 && !!logGroup && !!logStream;
991-
if (!isValid) {
992-
diag.warn(
993-
'Incomplete configuration: Please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS ' +
994-
`to have values for ${AWS_OTLP_LOGS_GROUP_HEADER} and ${AWS_OTLP_LOGS_STREAM_HEADER}`
995-
);
996-
}
997+
const isValid = !!logGroup && !!logStream;
997998

998999
return {
9991000
logGroup: logGroup,

0 commit comments

Comments
 (0)