Fix: remove gcp project and get host-project ID - #467
Conversation
…ect_id
Kubernetes workloads will export traces to the cluster host project
(ent-kub-<env>) instead of their own project (CLOUD-4435), so the
projects/{projectId}/traces/{traceId} value written to logs must use
that destination project. It is carried in the gcp.project_id OTel
resource attribute; GOOGLE_CLOUD_PROJECT remains the fallback for
runtimes (Cloud Run, Firebase) that still export to their own project.
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
Updates the GCP Logback Logstash encoder to resolve the trace project ID from OpenTelemetry resource attributes (supporting Kubernetes “host project” trace export), and removes the non-standard GCP_PROJECT_ID environment variable fallback.
Changes:
- Prefer
gcp.project_idfromOTEL_RESOURCE_ATTRIBUTESwhen resolving the project ID used inprojects/{projectId}/traces/{traceId}. - Keep
GOOGLE_CLOUD_PROJECTas the fallback source for runtimes where traces remain in the workload project. - Add a small parsing helper for
OTEL_RESOURCE_ATTRIBUTES.
File summaries
| File | Description |
|---|---|
gcp/logback-logstash-encoder-gcp/src/main/java/no/entur/logging/cloud/gcp/logback/logstash/StackdriverLogstashEncoder.java |
Switches project-id resolution to prefer OTel resource attribute gcp.project_id and removes GCP_PROJECT_ID fallback. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Did todays findings with ditto hacking change the validity of this PR? My spidey sense is that we should not need to do so much manual work and that the java agent augments logs correctly when using the default behavior (logs and traces to same default project aka the host project) |
Resolve project ID from OTel resource attribute instead of GCP_PROJECT_ID
resolveProjectId() built the projects/{projectId}/traces/{traceId} value written to logs by falling back through GOOGLE_CLOUD_PROJECT → GCP_PROJECT_ID. GCP_PROJECT_ID isn't a GCP standard env var and was unused as a fallback source, so it's dropped.
In its place: Kubernetes workloads are moving trace export to the cluster's host project (ent-kub-) instead of their own project, so the code now reads the gcp.project_id OpenTelemetry resource attribute from OTEL_RESOURCE_ATTRIBUTES first - that's where the destination project will actually live post-migration. GOOGLE_CLOUD_PROJECT remains the fallback for runtimes it doesn't affect (Cloud Run, Firebase), which still export traces to their own project.
No behavior change for services that don't set gcp.project_id.