You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The formatter in this sample correctly renames the OpenTelemetry field names to their GCP counterparts, however this does not address the format difference in the trace ID value. Cloud Logging is expecting projects/{project-id}/traces/{trace-id}, but we are only providing the raw trace ID here.
We can propagate existing Cloud Logging trace ID's by including something like this:
This will attach the propagated trace ID to our logging calls correctly, however with the JsonFormatter in this sample alone the logs would not correlate properly in GCP Logs Explorer or Trace Explorer since the projects/{project-id}/traces/ prefix is still missing from the trace ID value. We can use the log_hook argument on LoggingInstrumentor to modify the field value like this:
(Let's pretend we queried metadata.google.internal or something and already set PROJECT_ID somewhere for the sake of this example.) With this, the otelTraceIDvalue will first be changed to the correct format by the LoggingInstrumentor hook, then the field is renamed to logging.googleapis.com/trace by the JsonFormatter in the sample, and now traces will correlate properly in Logs Explorer/Trace Explorer! Hope this helps.
The text was updated successfully, but these errors were encountered:
Cloud Logging is expecting projects/{project-id}/traces/{trace-id}, but we are only providing the raw trace ID here.
I think the docs are a bit outdated here. Afaik, the agents have been updated to recognize the raw trace ID directly. I just tested it in GKE and everything works correctly because the logging agent adds the projects/.../traces/ for you.
kubectl run -it busybox --image=busybox --restart=Never -- echo '{"severity":"INFO","logging.googleapis.com/trace":"3a7b0c3dbf85c424a1fc184831dc565f","logging.googleapis.com/spanId":"562cfa35c0281c38","logging.googleapis.com/trace_sampled":true,"message":"Testing 123"}'
The formatter in this sample correctly renames the OpenTelemetry field names to their GCP counterparts, however this does not address the format difference in the trace ID value. Cloud Logging is expecting
projects/{project-id}/traces/{trace-id}
, but we are only providing the raw trace ID here.We can propagate existing Cloud Logging trace ID's by including something like this:
This will attach the propagated trace ID to our logging calls correctly, however with the JsonFormatter in this sample alone the logs would not correlate properly in GCP Logs Explorer or Trace Explorer since the
projects/{project-id}/traces/
prefix is still missing from the trace ID value. We can use thelog_hook
argument on LoggingInstrumentor to modify the field value like this:(Let's pretend we queried
metadata.google.internal
or something and already setPROJECT_ID
somewhere for the sake of this example.) With this, theotelTraceID
value will first be changed to the correct format by theLoggingInstrumentor
hook, then the field is renamed tologging.googleapis.com/trace
by theJsonFormatter
in the sample, and now traces will correlate properly in Logs Explorer/Trace Explorer! Hope this helps.The text was updated successfully, but these errors were encountered: