This document describes how you can associate a trace with a
Cloud Logging LogEntry
.
Associating a trace with a log entry
When you use the Trace client libraries, or when you use the
OpenCensus library for Python or for Java,
you associate a trace with a log entry by setting the trace
field in the
LogEntry
object.
The trace
field must be set to a string with the following format:
projects/PROJECT_ID/traces/TRACE_ID
where PROJECT_ID
is your Google Cloud project ID and
TRACE_ID
is the trace identifier
To associate a span with a log entry when using the REST API,
set the span_id
field in the LogEntry
object
to the 16-character hexadecimal encoding of the span's ID. If you are using
the gRPC API, then set the spanId
field.
For example, to associate a span with an ID of 74
to a log entry when
using the REST API, set span_id
to 000000000000004a
.
To indicate that you are using trace sampling and that the trace was sampled
for storage when the log entry was written, set the trace_sampled
field in
the LogEntry
object when using the REST API. If you are using
the gRPC API, then set the traceSampled
field. When you use trace sampling,
it's possible that a log entry is created when the trace itself isn't captured.
For more information, see the following resources:
- OpenCensus logging integration when using Python.
- OpenCensus Log Correlation.
- Cloud Logging agent configuration.
Viewing logs
You can view the log entry for a trace alongside the waterfall graph or
in the Logs Explorer. When you use the Logs Explorer, it's automatically restricted
to the timestamp range of the trace. If there are no log entries to display,
the Logs Explorer displays the message
No entries found matching current filter
.
From the Trace details pane, to view the log entry for the trace, do one of the following:
To display the trace log entries alongside the waterfall graph, go to the waterfall graph and click Show logs. When Show logs isn't displayed, no log entries are available.
To view the log entry in the Logs Explorer, click View next to the label Log in the Details section. Note that when you have a Cloud Load Balancing trace, click View next to the label VM Log.
For more information about viewing log entries in Cloud Logging, see Using the Logs Explorer.
Log viewing permissions
To view any log entries, you must have the logging.logEntries.list
permission
in your project. This permission is provided by the Logs Viewer and
Project Viewer Identity and Access Management (IAM) roles.
To view VM instance logs, you must have the compute.instances.get
permission
in your project. This permission is provided by the Compute Engine Network
Viewer and Project Viewer IAM roles.