fix: bare trace id instead of legacy projects/<id>/traces/<id> - #468
Conversation
…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>
There was a problem hiding this comment.
🟡 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/traceas the bare trace id for both OpenTelemetry- and Micrometer-sourced MDC values. - Remove project-id lookup/prefix construction from
StackdriverLogstashEncoderand 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.
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