File Coverage

blib/lib/Sentry/Tracing/Span.pm
Criterion Covered Total %
statement 56 60 93.3
branch 4 4 100.0
condition n/a
subroutine 13 14 92.8
pod 0 7 0.0
total 73 85 85.8


line stmt bran cond sub pod time code
1             use Mojo::Base -base, -signatures;
2 8     8   183951  
  8         23  
  8         50  
3             use HTTP::Status qw(status_message);
4 8     8   4150 use Readonly;
  8         24254  
  8         815  
5 8     8   3906 use Sentry::Tracing::Status;
  8         26652  
  8         440  
6 8     8   3580 use Sentry::Tracing::Transaction;
  8         22  
  8         71  
7 8     8   3005 use Sentry::Util qw(uuid4);
  8         20  
  8         72  
8 8     8   3117 use Time::HiRes qw(time);
  8         22  
  8         517  
9 8     8   65  
  8         12  
  8         62  
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 5     5 0 4543 $span_context->%*,
  5         11  
  5         7  
  5         8  
63 5         22 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 5         73 $child_span->transaction($self->transaction);
72              
73 5         15 return $child_span;
74             }
75 5         37  
76             return {
77             data => $self->data,
78 29     29 0 113 description => $self->description,
  29         39  
  29         45  
79             op => $self->op,
80 29         88 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             my $sampled_string = '';
103              
104             if (defined $self->sampled) {
105             $sampled_string = $self->sampled ? '-1' : '0';
106 4     4 0 3874 }
  4         8  
  4         7  
107 4         6  
108             return $self->trace_id . '-' . $self->span_id . $sampled_string;
109 4 100       10 }
110 2 100       12  
111             $self->tags({ $self->tags->%*, $key => $value });
112             }
113 4         23  
114             $self->set_tag('http.status_code' => $status);
115             $self->status(Sentry::Tracing::Status->from_http_code($status));
116 12     12 0 3159 }
  12         17  
  12         18  
  12         20  
  12         14  
117 12         42  
118             $self->timestamp(time);
119             }
120 10     10 0 1194  
  10         19  
  10         15  
  10         13  
121 10         37 1;