From 0c66ea361642f75fd900748dd210ff1ad882baf8 Mon Sep 17 00:00:00 2001 From: Bryan Atkinson Date: Thu, 24 Oct 2024 18:28:18 +0000 Subject: [PATCH] Clear trace metadata from logs not used by GCP plugin. --- js/plugins/google-cloud/src/gcpOpenTelemetry.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/plugins/google-cloud/src/gcpOpenTelemetry.ts b/js/plugins/google-cloud/src/gcpOpenTelemetry.ts index 428ba720e..6fa67cf13 100644 --- a/js/plugins/google-cloud/src/gcpOpenTelemetry.ts +++ b/js/plugins/google-cloud/src/gcpOpenTelemetry.ts @@ -97,6 +97,15 @@ export class GcpOpenTelemetry { `projects/${projectId}/traces/${spanContext.traceId}`; record['logging.googleapis.com/trace_sampled'] ??= isSampled ? '1' : '0'; record['logging.googleapis.com/spanId'] ??= spanContext.spanId; + + // Clear out the duplicate trace and span information in the log metadata. + // These will be incorrect for logs written during span export time since + // the logs are written after the span has fully executed. Those logs are + // explicitly tied to the correct span in createCommonLogAttributes in + // utils.ts. + delete record['span_id']; + delete record['trace_id']; + delete record['trace_flags']; }; async getConfig(): Promise> {