Recording events, exceptions, and status
Quickly identifying when an issue arises is a key aspect of distributed tracing. As demonstrated in Figure 4.7 with the Jaeger interface, in many backends, traces that contain errors are highlighted to make them easy to find for users of data:
In the following sections, we will explore the facilities that OpenTelemetry provides to capture events, record exceptions, and set the status of a span.
Events
In addition to attributes, an event provides the facility to record data about a span that occurs at a specific time. Events are similar to logs in OpenTracing in that they contain a timestamp and can contain a list of attributes or key/value pairs. An event is added via an add_event
method on the span, which accepts a name
argument and, optionally, a timestamp and a list of attributes, as shown in the following code:
shopper.py
...