NAME
Sentry::Tracing::Span - A timed operation within a transaction
SYNOPSIS
my $parent = Sentry::SDK->get_current_span or return;
my $span = $parent->start_child({
op => 'file.read',
description => 'read the price list',
});
$span->set_data('file.size' => -s $path);
...
$span->finish;
DESCRIPTION
A span measures one operation (a database query, an HTTP request, a template...) of a Sentry::Tracing::Transaction, the root span. Spans are sent with their transaction when it finishes; see span operations for the usual values of op.
The integrations create spans for the calls they instrument as children of the active span ("get_current_span" in Sentry::SDK). Start a span of your own with "start_child"; a span is not made the active one by starting it (see set_span in Sentry::Scope).
ATTRIBUTES
Accessors: they return the value; with an argument, they set it and return the span.
op
Short code of the kind of operation, e.g. db.sql.query.
description
What the span does, e.g. the SQL statement. Spans of the same kind of operation should have the same description (no ids in it).
status
The outcome, one of the values of Sentry::Tracing::Status, see "set_http_status".
tags
A hash of tags; Sentry expects values of up to 200 characters.
data
A hash of further data, or undef, see "set_data".
start_timestamp, timestamp
Start and end as epoch seconds with fractions. timestamp stays undef until the span has finished.
trace_id, span_id, parent_span_id
The ids of the trace, of this span and of its parent: their hex values as strings or as objects that stringify to them (see Sentry::Tracing::Id).
sampled
Whether the trace is sampled, inherited from the parent. Unsampled spans are never sent; sampled ones may still be dropped (see "finish").
CONSTANTS
MAX_FLAGS
10, the number of feature flags a span records (see "set_flag").
METHODS
start_child
my $child = $span->start_child({ op => 'db.sql.query', description => $sql });
Starts a child span now with the given attributes; trace, parent and sampling decision are taken from this span, whatever is given. Beyond max_spans per transaction (see "max_spans" in Sentry::SDK) the child works as usual, but is not sent.
set_tag
$span->set_tag(cache_hit => 'true');
Sets a tag. Returns the span.
set_data
$span->set_data('db.system.name' => 'mysql');
Sets an entry of "data". Returns the span.
set_flag
$span->set_flag('new-checkout' => !!1);
Records the result of a feature flag evaluated in the span, sent as data flag.evaluation.new-checkout with a boolean value (Perl's truth of $result). Like sentry-python, a span records the first "MAX_FLAGS" flags; unlike there, a flag recorded already takes the new result even then. Data set with "set_data" under the same key wins. "add_feature_flag" in Sentry::SDK calls it for the active span. Returns the span.
set_http_status
$span->set_http_status(404);
Sets the tag http.status_code, the data http.response.status_code and the "status" matching the code (see "from_http_code" in Sentry::Tracing::Status). Returns the span.
finish
$span->finish;
Ends the span now. Finishing it again changes nothing. Spans not finished when their transaction finishes are not sent.
to_trace_parent
my $sentry_trace = $span->to_trace_parent; # "<trace_id>-<span_id>-1"
The value of the sentry-trace header that makes this span the parent of the receiving service's transaction. The sampling flag is left out if the decision is unknown. "get_traceparent, get_baggage" in Sentry::SDK gives the one of the current trace.
INTERNAL METHODS
Used by the SDK; not part of the public API, may change without notice.
get_trace_context, dynamic_sampling_context, TO_JSON
The trace context of events, the dynamic sampling context of the trace and the span as sent to Sentry.
spans, transaction
The child spans and the transaction the span belongs to (weakly referenced).
SEE ALSO
Sentry::Tracing::Transaction, "get_current_span" in Sentry::SDK, "start_transaction" in Sentry::SDK