You can add user-defined content to a trace. The Cloud Trace API v1 lets you
add labels, while the Cloud Trace API v2 lets you add time events or attributes.
Time events are more flexible, as they let you specify a message,
in the form of a string, in addition to a set of attributes.
Each attribute is represented as a key-value pair.
For example, an attribute might record an instance identifier. For attribute
examples, see the API reference page for
Attributes
.
Annotate with labels
You can add event annotations to spans by creating a labels
object and
attaching it to the TraceSpan
object when you use
Cloud Trace API v1 patchTraces
.
These event annotations are displayed as labels when you view a traces' details. For more information about the labels, see Trace labels.
Annotate with attributes
You can annotate spans by creating an attributes
object
and attaching it to the Span
object when
you use Cloud Trace API v2 batchWrite
.
These event annotations are displayed as labels when you view a traces' details. For more detail, see Explore a trace.
Annotate with time events
You can add event annotations and message event to spans by creating a
TimeEvents
object and attaching it to the
Span object when you use Cloud Trace API
v2 batchWrite
.
The TimeEvents
object is an array of
TimeEvent
objects, each one contains a MessageEvent
object and an
Annotation
object.
To view the TimeEvents
for a trace, go to the traces' waterfall graph
and click Show logs & events. If you select a TimeEvent
, then its details are
displayed in the details pane.