File Coverage

blib/lib/Sentry/Tracing/Span.pm
Criterion Covered Total %
statement 49 53 92.4
branch n/a
condition n/a
subroutine 12 13 92.3
pod 0 6 0.0
total 61 72 84.7


line stmt bran cond sub pod time code
1             use Mojo::Base -base, -signatures;
2 7     7   164809  
  7         18  
  7         43  
3             use HTTP::Status qw(status_message);
4 7     7   3727 use Readonly;
  7         22810  
  7         584  
5 7     7   2878 use Sentry::Tracing::Status;
  7         21180  
  7         320  
6 7     7   2534 use Sentry::Tracing::Transaction;
  7         17  
  7         56  
7 7     7   2185 use Sentry::Util qw(uuid4);
  7         15  
  7         69  
8 7     7   2545 use Time::HiRes qw(time);
  7         17  
  7         386  
9 7     7   43  
  7         13  
  7         36  
10             Readonly my $SPAN_ID_LENGTH => 16;
11              
12             # https://develop.sentry.dev/sdk/unified-api/tracing
13              
14             # Hexadecimal string representing a uuid4 value. The length is exactly 32
15             # characters. Dashes are not allowed. Has to be lowercase
16             has span_id => sub { substr(uuid4(), 0, $SPAN_ID_LENGTH) };
17              
18             # Optional. A map or list of tags for this event. Each tag must be less than 200
19             # characters.
20             has tags => sub { {} };
21              
22             # Required. Determines which trace the Span belongs to. The value should be 16
23             # random bytes encoded as a hex string (32 characters long).
24             has trace_id => sub { uuid4() };
25              
26             # Recommended. Short code identifying the type of operation the span is
27             # measuring.
28             has op => undef;
29              
30             # Optional. Longer description of the span's operation, which uniquely
31             # identifies the span but is consistent across instances of the span.
32             has description => undef;
33              
34             # Required. A timestamp representing when the measuring started. The format is
35             # either a string as defined in RFC 3339 or a numeric (integer or float) value
36             # representing the number of seconds that have elapsed since the Unix epoch. The
37             # start_timestamp value must be greater or equal the timestamp value, otherwise
38             # the Span is discarded as invalid.
39             has start_timestamp => time;
40              
41             # Required. A timestamp representing when the measuring finished. The format is
42             # either a string as defined in RFC 3339 or a numeric (integer or float) value
43             # representing the number of seconds that have elapsed since the Unix epoch.
44             has timestamp => undef;
45              
46             # Optional. Describes the status of the Span/Transaction.
47             has status => undef;
48              
49             # Optional. Arbitrary data associated with this Span.
50             has data => undef;
51              
52             has parent_span_id => undef;
53              
54             # Was this span chosen to be sent as part of the sample?
55             has sampled => undef;
56              
57             has spans => sub { [] };
58             has transaction => undef;
59             has request => undef;
60              
61             my $child_span = Sentry::Tracing::Span->new({
62 4     4 0 4705 $span_context->%*,
  4         5  
  4         7  
  4         5  
63 4         12 parent_span_id => $self->span_id,
64             sampled => $self->sampled,
65             trace_id => $self->trace_id,
66             start_timestamp => time,
67             });
68              
69             push $self->spans->@*, $child_span;
70              
71 4         39 $child_span->transaction($self->transaction);
72              
73 4         8 return $child_span;
74             }
75 4         26  
76             return {
77             data => $self->data,
78 29     29 0 84 description => $self->description,
  29         44  
  29         38  
79             op => $self->op,
80 29         75 parent_span_id => $self->parent_span_id,
81             span_id => $self->span_id,
82             status => $self->status,
83             tags => $self->tags,
84             trace_id => $self->trace_id,
85             };
86             }
87              
88             return {
89             data => $self->data,
90             description => $self->description,
91 0     0 0 0 op => $self->op,
  0         0  
  0         0  
92             parent_span_id => $self->parent_span_id,
93 0         0 span_id => $self->span_id,
94             start_timestamp => $self->start_timestamp,
95             status => $self->status,
96             tags => $self->tags,
97             timestamp => $self->timestamp,
98             trace_id => $self->trace_id,
99             };
100             }
101              
102             $self->tags({ $self->tags->%*, $key => $value });
103             }
104              
105             $self->set_tag('http.status_code' => $status);
106 11     11 0 2179 $self->status(Sentry::Tracing::Status->from_http_code($status));
  11         13  
  11         15  
  11         12  
  11         12  
107 11         29 }
108              
109             $self->timestamp(time);
110 9     9 0 1360 }
  9         12  
  9         12  
  9         12  
111 9         25  
112 9         154 1;