File Coverage

blib/lib/Sentry/Hub/Scope.pm
Criterion Covered Total %
statement 96 155 61.9
branch 11 22 50.0
condition 8 14 57.1
subroutine 18 29 62.0
pod 0 21 0.0
total 133 241 55.1


line stmt bran cond sub pod time code
1             use Mojo::Base -base, -signatures;
2 5     5   191799  
  5         14  
  5         27  
3             use Clone qw();
4 5     5   2678 use Mojo::Util 'dumper';
  5         10510  
  5         121  
5 5     5   30 use Sentry::Severity;
  5         7  
  5         195  
6 5     5   1812 use Sentry::Tracing::Span;
  5         10  
  5         38  
7 5     5   1880 use Sentry::Util 'merge';
  5         13  
  5         43  
8 5     5   169 use Time::HiRes;
  5         7  
  5         186  
9 5     5   24  
  5         11  
  5         17  
10             has breadcrumbs => sub { [] };
11             has contexts => sub { {} };
12             has error_event_processors => sub { [] };
13             has event_processors => sub { [] };
14             has extra => sub { {} };
15             has fingerprint => sub { [] };
16             has level => Sentry::Severity->Info;
17             has span => undef;
18             has tags => sub { {} };
19             has transaction_name => undef;
20             has user => undef;
21              
22             $self->span($span);
23 8     8 0 9 return $self;
  8         12  
  8         11  
  8         11  
24 8         26 }
25 8         51  
26             $self->user($user);
27             }
28 1     1 0 6  
  1         2  
  1         1  
  1         2  
29 1         3 $self->extra->{$name} = $value;
30             }
31              
32 0     0 0 0 $self->extra = { %{ $self->extra }, %{$extras} };
  0         0  
  0         0  
  0         0  
  0         0  
33 0         0 }
34              
35             $self->tags->{$key} = $value;
36 0     0 0 0 }
  0         0  
  0         0  
  0         0  
37 0         0  
  0         0  
  0         0  
38             $self->tags({ $self->tags->%*, $tags->%* });
39             }
40 1     1 0 14  
  1         2  
  1         1  
  1         2  
  1         1  
41 1         4 if (not defined $context) {
42             delete $self->contexts->{$key};
43             } else {
44 15     15 0 129 $self->contexts->{$key} = $context;
  15         21  
  15         18  
  15         20  
45 15         31 }
46              
47             # $self->_notify_scope_listeners();
48 0     0 0 0  
  0         0  
  0         0  
  0         0  
  0         0  
49 0 0       0 return $self;
50 0         0 }
51              
52 0         0 $self->level($level);
53             }
54              
55             $self->transaction_name($name);
56             return $self;
57 0         0 }
58              
59             return $self->span;
60 0     0 0 0 }
  0         0  
  0         0  
  0         0  
61 0         0  
62             $self->fingerprint($fingerprint);
63             }
64 0     0 0 0  
  0         0  
  0         0  
  0         0  
65 0         0 push $self->event_processors->@*, $event_processor;
66 0         0 }
67              
68             push $self->error_event_processors->@*, $error_event_processor;
69 2     2 0 12 }
  2         2  
  2         4  
70 2         5  
71              
72             # Resets a scope to default values while keeping all registered event
73 0     0 0 0 # processors. This does not affect either child or parent scopes
  0         0  
  0         0  
  0         0  
74 0         0 }
75              
76             $breadcrumb->{timestamp} //= time;
77 0     0 0 0 push @{ $self->breadcrumbs }, $breadcrumb;
  0         0  
  0         0  
  0         0  
78 0         0 }
79              
80             $self->breadcrumbs([]);
81 0     0 0 0 }
  0         0  
  0         0  
  0         0  
82 0         0  
83             # Applies fingerprint from the scope to the event if there's one,
84             # uses message if there's one instead or get rid of empty fingerprint
85 0     0 0 0 $event->{fingerprint} //= [];
  0         0  
86              
87             $event->{fingerprint} = [$event->{fingerprint}]
88             if ref($event->{fingerprint} ne 'ARRAY');
89              
90             $event->{fingerprint} = [$event->{fingerprint}->@*, $self->fingerprint->@*];
91 15     15 0 50  
  15         21  
  15         18  
  15         19  
92 15   66     81 delete $event->{fingerprint} unless scalar $event->{fingerprint}->@*;
93 15         26 }
  15         40  
94              
95             # Applies the scope data to the given event object. This also applies the event
96 0     0 0 0 # processors stored in the scope internally. Some implementations might want to
  0         0  
  0         0  
97 0         0 # set a max breadcrumbs count here.
98             merge($event, $self, 'extra') if $self->extra;
99             merge($event, $self, 'tags') if $self->tags;
100             merge($event, $self, 'user') if $self->user;
101             merge($event, $self, 'contexts') if $self->contexts;
102 21     21   28  
  21         26  
  21         27  
  21         25  
103 21   50     89 $event->{level} //= $self->level if $self->level;
104             $event->{transaction} = $self->transaction_name if $self->transaction_name;
105              
106 21 50       74 if ($self->span) {
107             $event->{request} = $self->span->request;
108 21         84  
109             $event->{contexts} = {
110 21 50       84 trace => $self->span->get_trace_context(),
111             ($event->{contexts} // {})->%*
112             };
113              
114             if (my $transaction_name = $self->span->transaction->name) {
115             $event->{tags}
116 21     21 0 778 = { transaction => $transaction_name, ($event->{tags} // {})->%* };
  21         39  
  21         26  
  21         29  
  21         25  
117 21 50       54 }
118 21 50       77 }
119 21 50       69  
120 21 50       104 $self->_apply_fingerprint($event);
121              
122 21 50 66     58 $event->{breadcrumbs}
123 21 50       212 = [($event->{breadcrumbs} // [])->@*, $self->breadcrumbs->@*];
124              
125 21 100       95 my @event_processors
126 20         88 = (get_global_event_processors()->@*, $self->event_processors->@*);
127              
128             foreach my $processor (@event_processors) {
129             $event = $processor->($event, $hint);
130 20   50     132 }
131              
132             return $event;
133 20 50       224 }
134              
135 20   50     236 Clone::clone($self);
136             }
137              
138             $self->$_($fields->{$_}) for keys $fields->%*;
139 21         71 }
140              
141             state $processors = [];
142 21   50     123 return $processors;
143             }
144              
145 21         92 push get_global_event_processors()->@*, $processor;
146             }
147 21         62  
148 1         5 1;