Skip to content

Choosing Spans, Instruments and Log Records: OTCA practice questions

The spec overview describes tracing, metrics and baggage as separate signals that share the context propagation subsystem, and it also defines a log signal. Knowing which tool fits which question is a core OTCA skill.

By Ibrahim Yesilay · Published · Updated

Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.

What Choosing Spans, Instruments and Log Records covers in OTCA

The spec overview describes tracing, metrics and baggage as separate signals that share the context propagation subsystem, and it also defines a log signal. Knowing which tool fits which question is a core OTCA skill.

A span represents one operation with a start and an end. Its name should describe a class of operations, such as get_account, with identifiers like the account number recorded as attributes instead of being built into the name. SpanKind describes the relationship to other spans. CLIENT and SERVER are used for request and response calls where the caller waits. PRODUCER and CONSUMER are for deferred work such as queue messages, where the producer does not wait for the outcome. INTERNAL is for in-process work and is the default. A span event marks a meaningful moment inside a span. If the timestamp of a piece of data matters, record it as an event, and otherwise as an attribute. Exceptions are recorded with RecordException, which adds an event named exception with type, message and stacktrace attributes.

Metrics come from instruments created by a Meter. Counter accepts only non-negative increments, which suits counts of requests or bytes. UpDownCounter allows increments and decrements, for example the number of active requests or the items in a queue. Histogram records values whose statistics are interesting, such as request durations. The synchronous Gauge records non-additive values when a change event fires. The asynchronous instruments, called Asynchronous Counter, Asynchronous UpDownCounter and Asynchronous Gauge, report absolute values from callbacks that run only when metrics are collected. The guidelines recommend Asynchronous UpDownCounter for additive values such as heap size, so consumers know they may add them across processes. Instrument names are case-insensitive ASCII strings that start with a letter and are at most 255 characters long. Units are case-sensitive and limited to 63 characters.

Only synchronous measurements can be associated with the current Context, which is why exemplars work through them. The default exemplar filter is TraceBased, so a measurement can become an exemplar only when it is recorded inside a sampled span.

Logs usually come from existing logging libraries. The Logs API was designed mainly for authors of log appenders, also called bridges, that connect a logging library to the OpenTelemetry SDK. An application developer normally keeps the familiar logger and configures an appender, although the API can also be called directly, for example to emit structured events. Baggage carries name/value pairs to later services so they can index their own telemetry with that data. It is not copied into span, metric or log attributes unless code or a processor does so explicitly.

Key points

  • Use PRODUCER and CONSUMER for deferred messaging, and CLIENT and SERVER for calls where the caller waits.
  • Record a span event when the timestamp of a moment matters, and an attribute when it does not.
  • Counter is monotonic, UpDownCounter can go down, Histogram captures distributions and Gauge records non-additive values.
  • Asynchronous instruments report absolute values from callbacks invoked during collection.
  • The Logs API mainly serves appender authors, so applications usually keep their logging library.

Three sample questions

23 OTCA questions on Choosing Spans, Instruments and Log Records, 23 with explanations. How practice works

Question 1

Your application processes incoming requests in batches, where each batch operation is initiated by multiple spans representing individual items. How should you represent the relationship between the batch operation span and the individual item spans in OpenTelemetry?
  1. A.Set each item span as a child of the batch operation span using the parent field.
  2. B.Use Span Links to associate the batch operation span with each individual item span.
  3. C.Use separate traces for the batch operation and individual item spans without linking them.
  4. D.Merge all individual item spans into the batch operation span.

Correct answer: B

The specification overview says links "can be used to represent batched operations where a Span was initiated by multiple initiating Spans, each representing a single incoming item being processed in the batch", and recommends not setting a parent in this case because the parent field represents a single parent. The Traces concepts page describes links as associating one span with several causally related spans. Why the other options are wrong. "Set each item span as a child of the batch operati…": a span has only one parent, so the batch span cannot be the child of many item spans; the spec advises links here instead. "Use separate traces for the batch operation and in…": unlinked traces lose the causal relationship between the batch and its items. "Merge all individual item spans into the batch ope…": merging spans destroys the per-item timing and attributes; OpenTelemetry has no span merge for this case.

Sources: OpenTelemetry spec: Overview, OpenTelemetry docs: Traces

Question 2

Which type of metric instrument in OpenTelemetry is best suited for capturing the current value of a resource, such as memory usage?
  1. A.Histogram
  2. B.Gauge
  3. C.Summary
  4. D.Counter

Correct answer: B

The Metrics concepts page describes a Gauge as an instrument that "Measures a current value at the time it is read", like the fuel gauge in a vehicle. A current reading such as memory usage fits a gauge, or an Asynchronous Gauge when the value is only observed at export. Why the other options are wrong. "Histogram": a histogram aggregates the distribution of many values, such as request latencies. "Summary": Summary is a legacy point type in the data model, kept for compatibility; it is not an OpenTelemetry instrument. "Counter": a counter only goes up, so it cannot follow memory usage as it rises and falls.

Sources: OpenTelemetry docs: Metrics, OpenTelemetry spec: Metrics Data Model

Question 3

A web server wants to track how many requests are currently in flight, incrementing when a request starts and decrementing when it ends. Which instrument fits best?
  1. A.UpDownCounter
  2. B.Counter
  3. C.Histogram
  4. D.Asynchronous Counter

Correct answer: A

The Metrics API describes UpDownCounter as "a synchronous Instrument which supports increments and decrements", with "the number of active requests" as an example use. The supplementary guidelines say that when counting by recording delta values that are "NOT monotonically increasing (the delta value can be positive, negative or zero)", you use an UpDownCounter. Why the other options are wrong. "Counter": it "supports non-negative increments" only, so decrements are not allowed. "Histogram": it records the distribution of values such as durations and does not keep a running total that goes up and down. "Asynchronous Counter": it reports monotonically increasing absolute values from a callback, which fits neither the decrement nor the inline start/end events.

Sources: OpenTelemetry spec: Metrics API, OpenTelemetry spec: Metrics Supplementary Guidelines

Practice this topic

Focus mode keeps every question on Choosing Spans, Instruments and Log Records until you leave it. 10 free guest answers, then a free account; no credit card.

Or open OTCA practice across all topics.

Sources

The explanation above was checked against these official documents.

Frequently asked questions

When should a synchronous Gauge be used instead of an Asynchronous Gauge?

Use the synchronous Gauge when the value arrives through change events you subscribe to. Use the Asynchronous Gauge when you read the value through an accessor inside a collection callback.

Why do only some measurements show exemplars?

The default ExemplarFilter is TraceBased, so only measurements recorded in the context of a sampled span are eligible, and the reservoir then decides which of them are kept.