Assertions
Introduction
This section describes Mtracer assertions. Assertions are a tool that allows you to perform more specific verifications on the collected trace using different assertion languages.
Supported Assertions
Currently, Mtracer supports the assertions detailed in the sections below.
Additionally, the default assertion type is cel.
Common Expression Language (CEL)
CEL is an expression language designed to be simple and efficient, allowing you to write boolean expressions to verify if the collected trace meets certain conditions.
It is recommended to read the short tutorial for an overview of CEL’s capabilities.
Example
assertions:
- name: "Check error count and span status"
type: "cel"
queries:
errorCheck: "trace.errorCount == 0"
spanStatusCheck: "trace.spans.all(s, s.spanStatus == 'unset')"Note that you can define multiple assertions and, within each one, multiple queries. All queries are evaluated and must be true for the assertion to be considered verified.
Trace Fields
Within CEL expressions, you can access various fields of the collected trace.
The following fields are available:
traceId: unique identifier of the collected tracestartTime: start timestamp of the trace in RFC3339 formatendTime: end timestamp of the trace in RFC3339 formatduration: duration of the trace in seconds; the string is expressed in seconds and must have the “s” suffix, e.g.,1.5sspanCount: number of spans present in the collected traceerrorCount: number of spans with an error status present in the collected tracespans: list of spans present in the collected trace
You can perform operations with the startTime and endTime fields using the timestamp() and duration() functions, for example, to verify that the trace was generated within a certain time window:
now > timestamp("2026-06-12T08:00:00Z") + duration("2h30m")Span Fields
Within CEL expressions, you can access various fields of the spans present in the collected trace.
The following fields are available for each span:
s.spanId: unique identifier of the spans.parentId: identifier of the parent span, if anys.serviceName: OTel service name associated with the spans.operationName: OTel operation name associated with the spans.spanKind: OTel kind of the spans.spanStatus: OTel status of the spans.startTime: start timestamp of the span in RFC3339 formats.endTime: end timestamp of the span in RFC3339 formats.duration: duration of the span in seconds; the string is expressed in seconds and must have the “s” suffix, e.g.,1.5ss.attributes: map of attributes associated with the span, with string keys and any type for values. This field is useful for running assertions on specific attributes of one or more spans, for example:
assertions:
- name: "Check db system"
queries:
dbSystemCheck: "trace.spans[3].attributes['db.system'] == 'postgresql'"It is therefore recommended to read the official CEL documentation to discover all available macros.