Skip to content

fix: bare trace id instead of legacy projects/<id>/traces/<id> - #468

Merged
AlexanderBrevig merged 1 commit into
mainfrom
fix/trace-correlation
Sep 1, 2026
Merged

fix: bare trace id instead of legacy projects/<id>/traces/<id>#468
AlexanderBrevig merged 1 commit into
mainfrom
fix/trace-correlation

Conversation

@AlexanderBrevig

Copy link
Copy Markdown
Contributor

Google now documents the bare TRACE_ID as the preferred format for LogEntry.trace / logging.googleapis.com/trace; the full resource name is legacy. Both the Logs Explorer correlation and the Cloud Trace log integration accept the bare id, so the project id lookup (GOOGLE_CLOUD_PROJECT / GCP_PROJECT_ID) and prefix construction are no longer needed.

See https://docs.cloud.google.com/trace/docs/trace-log-integration and https://docs.cloud.google.com/logging/docs/view/correlate-logs

Note: cross-project disambiguation now relies on Google matching the id within the reader's log scopes rather than an explicit project in the value.

Supersedes #467

…rce name

Google now documents the bare TRACE_ID as the preferred format for
LogEntry.trace / logging.googleapis.com/trace; the full resource name is
legacy. Both the Logs Explorer correlation and the Cloud Trace log
integration accept the bare id, so the project id lookup
(GOOGLE_CLOUD_PROJECT / GCP_PROJECT_ID) and prefix construction are no
longer needed.

See https://docs.cloud.google.com/trace/docs/trace-log-integration and
https://docs.cloud.google.com/logging/docs/view/correlate-logs

Note: cross-project disambiguation now relies on Google matching the id
within the reader's log scopes rather than an explicit project in the
value.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AlexanderBrevig
AlexanderBrevig requested a review from a team as a code owner September 1, 2026 10:36
Copilot AI lite review requested due to automatic review settings September 1, 2026 10:36
@AlexanderBrevig
AlexanderBrevig requested a review from a team as a code owner September 1, 2026 10: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.

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the GCP Stackdriver logging integration to emit the bare W3C TRACE_ID (instead of the legacy projects/<projectId>/traces/<traceId> resource name) in LogEntry.trace / logging.googleapis.com/trace, removing the need to resolve a GCP project id at runtime.

Changes:

  • Write logging.googleapis.com/trace as the bare trace id for both OpenTelemetry- and Micrometer-sourced MDC values.
  • Remove project-id lookup/prefix construction from StackdriverLogstashEncoder and related providers.
  • Update tests and in-code documentation/comments to reflect the preferred trace-id format.
File summaries
File Description
gcp/logback-logstash-encoder-gcp/src/test/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverOpenTelemetryTraceMdcJsonProviderTest.java Updates expected trace value and provider construction for bare trace-id behavior.
gcp/logback-logstash-encoder-gcp/src/test/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverMicrometerTraceMdcJsonProviderTest.java Updates expected trace value and provider construction for bare trace-id behavior.
gcp/logback-logstash-encoder-gcp/src/main/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverOpenTelemetryTraceMdcJsonProvider.java Emits bare trace id; updates Javadoc.
gcp/logback-logstash-encoder-gcp/src/main/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverMicrometerTraceMdcJsonProvider.java Emits bare trace id; updates Javadoc.
gcp/logback-logstash-encoder-gcp/src/main/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverLogstashEncoder.java Removes env-based project id resolution and uses no-arg providers.
gcp/correlation-id-trace-spring-boot-gcp-web/src/main/java/no/entur/logging/cloud/gcp/trace/spring/web/GcpTraceFilter.java Updates comment to reflect preferred bare trace-id format (deprecated component).
gcp/correlation-id-trace-spring-boot-gcp-grpc/src/main/java/no/entur/logging/cloud/gcp/trace/spring/grpc/interceptor/OrderedTraceIdGrpcMdcContextServerInterceptor.java Updates comment to reflect preferred bare trace-id format (deprecated component).
Review details

Suppressed comments (2)

gcp/logback-logstash-encoder-gcp/src/main/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverOpenTelemetryTraceMdcJsonProvider.java:62

  • This provider can emit duplicate JSON fields if MDC contains both the OpenTelemetry keys (e.g. trace_id/span_id) and the already-mapped GCP keys (logging.googleapis.com/trace/spanId). Duplicate field names are risky for downstream ingestion (and can cause log loss with some agents). Add precedence rules to ensure each GCP special field is written at most once.
            switch (key) {
                case OPENTELEMETRY_TRACE_ID_KEY -> generator.writeStringProperty(GCP_TRACE_KEY, value);
                case OPENTELEMETRY_SPAN_ID_KEY  -> generator.writeStringProperty(GCP_SPAN_ID_KEY, value);
                case OPENTELEMETRY_TRACE_FLAGS_KEY -> {
                    if (isSampled(value)) {

gcp/logback-logstash-encoder-gcp/src/main/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverMicrometerTraceMdcJsonProvider.java:60

  • This provider can emit duplicate JSON fields if MDC contains both Micrometer keys (traceId/spanId/traceSampled) and the already-mapped GCP keys (logging.googleapis.com/trace/spanId/trace_sampled). Add precedence rules to ensure each GCP special field is written at most once.
            switch (key) {
                case MICROMETER_TRACE_ID_KEY -> generator.writeStringProperty(GCP_TRACE_KEY, value);
                case MICROMETER_SPAN_ID_KEY  -> generator.writeStringProperty(GCP_SPAN_ID_KEY, value);
                case MICROMETER_SAMPLED_KEY -> {
                    generator.writeBooleanProperty(GCP_TRACE_SAMPLED, Boolean.parseBoolean(value));
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@helleengebakken helleengebakken left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM 👍

@AlexanderBrevig
AlexanderBrevig merged commit 971cc95 into main Sep 1, 2026
12 of 13 checks passed
@AlexanderBrevig
AlexanderBrevig deleted the fix/trace-correlation branch September 1, 2026 11:50
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.

3 participants