Skip to content

fix(gcp): map OpenTelemetry trace fields - #442

Closed
viliket wants to merge 1 commit into
entur:mainfrom
viliket:fix/gcp-opentelemetry-trace-fields
Closed

fix(gcp): map OpenTelemetry trace fields#442
viliket wants to merge 1 commit into
entur:mainfrom
viliket:fix/gcp-opentelemetry-trace-fields

Conversation

@viliket

@viliket viliket commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

GKE ingests structured JSON logs written to stdout. The logging agent promotes only its reserved logging.googleapis.com/trace and logging.googleapis.com/spanId keys to the corresponding LogEntry fields; ordinary traceId and spanId keys remain in jsonPayload.

Map the real OpenTelemetry trace and span IDs to those reserved keys. Prefer OpenTelemetry values over legacy MDC values and avoid duplicate JSON fields.

See: https://docs.cloud.google.com/logging/docs/agent/logging/configuration#special-fields

GKE ingests structured JSON logs written to stdout. The logging agent promotes only its reserved logging.googleapis.com/trace and logging.googleapis.com/spanId keys to the corresponding LogEntry fields; ordinary traceId and spanId keys remain in jsonPayload.

Map the real OpenTelemetry trace and span IDs to those reserved keys. Prefer OpenTelemetry values over legacy MDC values and avoid duplicate JSON fields.

See: https://docs.cloud.google.com/logging/docs/agent/logging/configuration#special-fields

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@viliket
viliket requested a review from a team as a code owner August 7, 2026 12:36
Copilot AI lite review requested due to automatic review settings August 7, 2026 12:36
@viliket
viliket requested a review from a team as a code owner August 7, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the GCP Logstash encoder’s MDC handling to ensure OpenTelemetry traceId/spanId are emitted using Google Cloud Logging’s reserved special-field keys (logging.googleapis.com/trace, logging.googleapis.com/spanId), so the ingestion agent promotes them into the corresponding LogEntry trace/span fields rather than leaving them in jsonPayload.

Changes:

  • Update StackdriverOpenTelemetryTraceMdcJsonProvider to remap traceIdlogging.googleapis.com/trace and spanIdlogging.googleapis.com/spanId.
  • Ensure OpenTelemetry values take precedence over already-present GCP special-field MDC values, while preventing duplicate JSON output fields.
  • Add focused unit tests covering mapping behavior, precedence behavior, and preservation when OpenTelemetry values are absent.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
gcp/logback-logstash-encoder-gcp/src/main/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverOpenTelemetryTraceMdcJsonProvider.java Remaps OpenTelemetry MDC keys to GCP special-field keys and skips legacy GCP keys when OpenTelemetry equivalents exist to avoid duplicates.
gcp/logback-logstash-encoder-gcp/src/test/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverOpenTelemetryTraceMdcJsonProviderTest.java Adds tests validating remapping, precedence over existing GCP keys, and preservation of existing keys when OpenTelemetry values are missing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@toukovk toukovk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tommybo-entur

Copy link
Copy Markdown
Contributor

This issue is addressed in #439

@viliket

viliket commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

This issue is addressed in #439

Ah, I missed that, closing this one 👍

@viliket viliket closed this Aug 12, 2026
@skjolber skjolber mentioned this pull request Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants