fix(gcp): map OpenTelemetry trace fields - #442
Closed
viliket wants to merge 1 commit into
Closed
Conversation
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>
Contributor
There was a problem hiding this comment.
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
StackdriverOpenTelemetryTraceMdcJsonProviderto remaptraceId→logging.googleapis.com/traceandspanId→logging.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.
Contributor
|
This issue is addressed in #439 |
Contributor
Author
Ah, I missed that, closing this one 👍 |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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