Skip to content

Commit 5b69509

Browse files
committed
add better log messages
1 parent 06fc811 commit 5b69509

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,14 @@ function getXrayDaemonEndpoint() {
833833
*/
834834

835835
function isAwsOtlpEndpoint(otlpEndpoint: string, service: string): boolean {
836-
const pattern = service === 'xray' ? AWS_TRACES_OTLP_ENDPOINT_PATTERN : AWS_LOGS_OTLP_ENDPOINT_PATTERN;
836+
let pattern = '';
837+
if (service === 'xray') {
838+
pattern = AWS_TRACES_OTLP_ENDPOINT_PATTERN;
839+
} else if (service === 'logs') {
840+
pattern = AWS_LOGS_OTLP_ENDPOINT_PATTERN;
841+
} else {
842+
return false;
843+
}
837844

838845
return new RegExp(pattern).test(otlpEndpoint.toLowerCase());
839846
}
@@ -847,8 +854,9 @@ function validateLogsHeaders() {
847854

848855
if (!logsHeaders) {
849856
diag.warn(
850-
'Improper configuration: Please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS ' +
851-
'to include x-aws-log-group and x-aws-log-stream'
857+
'Missing required configuration: The environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS must be set with ' +
858+
`required headers ${AWS_OTLP_LOGS_GROUP_HEADER} and ${AWS_OTLP_LOGS_STREAM_HEADER}. ` +
859+
`Example: OTEL_EXPORTER_OTLP_LOGS_HEADERS="${AWS_OTLP_LOGS_GROUP_HEADER}=my-log-group,${AWS_OTLP_LOGS_STREAM_HEADER}=my-log-stream"`
852860
);
853861
return false;
854862
}
@@ -868,9 +876,13 @@ function validateLogsHeaders() {
868876
}
869877

870878
if (!hasLogGroup || !hasLogStream) {
879+
const missingHeaders = [];
880+
if (!hasLogGroup) missingHeaders.push(AWS_OTLP_LOGS_GROUP_HEADER);
881+
if (!hasLogStream) missingHeaders.push(AWS_OTLP_LOGS_STREAM_HEADER);
882+
871883
diag.warn(
872-
`Improper configuration: Please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS ' +
873-
'to have values for ${AWS_OTLP_LOGS_GROUP_HEADER} and ${AWS_OTLP_LOGS_STREAM_HEADER}`
884+
'Incomplete configuration: Please configure the environment variable OTEL_EXPORTER_OTLP_LOGS_HEADERS ' +
885+
`to have values for ${AWS_OTLP_LOGS_GROUP_HEADER} and ${AWS_OTLP_LOGS_STREAM_HEADER}`
874886
);
875887
return false;
876888
}

0 commit comments

Comments
 (0)