xs/exporter.xs

filter: Statementstmt 94.3% 217 / 230 Branchbran 58.8% 146 / 248 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 75.9% 363 / 478 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/otel_instr.h ↑ Summary xs/resource.xs »
1 MODULE = Punk::OpenTelemetry PACKAGE = Punk::OpenTelemetry::Exporter
2  
3 PROTOTYPES: DISABLE
4  
5 # new(%opt): endpoint, endpoints, protocol, headers, timeout, compression,
6 # max_retries, ua. The object is a blessed HASH with exactly those keys plus
7 # `stats`, because they are part of the interface - an application reads
8 # $e->{protocol} and bumps $e->{stats}{dropped}.
9 SV *
10 new(class, ...)
11 SV *class
12 CODE:
13 {
14 37 HV *self = newHV();
15 37 HV *args = newHV();
16 SV *proto, *ua, *tmo;
17 0 ▶ const char *cls = (SvROK(class) && SvOBJECT(SvRV(class)))
Branch: 1 branch
BranchTrueFalseTotal
const char *cls = (SvROK(class) && SvOBJECT(SvRV(class))) 0 0 0
18 74 ▶ ? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class);
Branch: 7 branches
BranchTrueFalseTotal
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 37 37
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
19 int i;
20 37 sv_2mortal((SV *)args);
21 37 ▶ if ((items - 1) % 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 1) % 2) 0 37 37
22 0 croak("Punk::OpenTelemetry::Exporter::new: odd number of options");
23 124 ▶ for (i = 1; i + 1 < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i + 1 < items; i += 2) { 87 37 124
24 STRLEN kl;
25 87 const char *k = SvPV_const(ST(i), kl);
26 87 (void)hv_store(args, k, (I32)kl, newSVsv(ST(i + 1)), 0);
27 }
28  
29 37 proto = otel_h(aTHX_ args, "protocol");
30 37 ▶ if (!proto) proto = sv_2mortal(newSVpvs("http/protobuf"));
Branch: 1 branch
BranchTrueFalseTotal
if (!proto) proto = sv_2mortal(newSVpvs("http/protobuf")); 16 21 37
31 {
32 STRLEN pl;
33 37 const char *pp = SvPV_const(proto, pl);
34 37 ▶ if (!otel_exp_content_type(pp, pl))
Branch: 1 branch
BranchTrueFalseTotal
if (!otel_exp_content_type(pp, pl)) 2 35 37
35 2 croak("Punk::OpenTelemetry::Exporter: unknown protocol '%s' "
36 "(http/protobuf or http/json)\n", pp);
37 }
38  
39 35 ▶ (void)hv_stores(self, "endpoint",
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(self, "endpoint", 23 12 35
40 (tmo = otel_h(aTHX_ args, "endpoint")) ? newSVsv(tmo) : newSV(0));
41 35 ▶ (void)hv_stores(self, "endpoints",
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(self, "endpoints", 1 34 35
42 otel_h_hv(aTHX_ args, "endpoints")
43 ? newSVsv(*hv_fetchs(args, "endpoints", 0))
44 : newRV_noinc((SV *)newHV()));
45 35 (void)hv_stores(self, "protocol", newSVsv(proto));
46 35 ▶ (void)hv_stores(self, "headers",
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(self, "headers", 1 34 35
47 otel_h_hv(aTHX_ args, "headers")
48 ? newSVsv(*hv_fetchs(args, "headers", 0))
49 : newRV_noinc((SV *)newHV()));
50 35 tmo = otel_h(aTHX_ args, "timeout");
51 35 ▶ (void)hv_stores(self, "timeout", tmo ? newSVsv(tmo) : newSViv(10));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(self, "timeout", tmo ? newSVsv(tmo) : newSViv(10)); 16 19 35
52 35 ▶ (void)hv_stores(self, "compression",
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(self, "compression", 16 19 35
53 (tmo = otel_h(aTHX_ args, "compression")) ? newSVsv(tmo)
54 : newSVpvs("none"));
55 35 tmo = otel_h(aTHX_ args, "max_retries");
56 35 ▶ (void)hv_stores(self, "max_retries", tmo ? newSVsv(tmo) : newSViv(5));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(self, "max_retries", tmo ? newSVsv(tmo) : newSViv(5)); 0 35 35
57  
58 { /* what happened, so a telemetry layer can report its own losses -
59 * one that cannot is asking to be trusted for no reason */
60 35 HV *st = newHV();
61 35 (void)hv_stores(st, "exported", newSViv(0));
62 35 (void)hv_stores(st, "rejected", newSViv(0));
63 35 (void)hv_stores(st, "dropped", newSViv(0));
64 35 (void)hv_stores(st, "failures", newSViv(0));
65 35 (void)hv_stores(st, "retries", newSViv(0));
66 35 (void)hv_stores(st, "partial", newSViv(0));
67 35 (void)hv_stores(self, "stats", newRV_noinc((SV *)st));
68 }
69  
70 35 ua = otel_h(aTHX_ args, "ua");
71 35 ▶ if (ua) (void)hv_stores(self, "ua", newSVsv(ua));
Branch: 1 branch
BranchTrueFalseTotal
if (ua) (void)hv_stores(self, "ua", newSVsv(ua)); 9 26 35
72 else {
73 26 dSP; int count; SV *made = NULL;
74 26 SV *t = otel_h(aTHX_ self, "timeout");
75 /* Fetch has to be LOADED before it can be called. It is a runtime
76 * prerequisite of this dist rather than a compile-time one, so
77 * nothing else has necessarily pulled it in, and a caller who
78 * passed no `ua` is precisely the caller who did not think about
79 * the HTTP client at all. Failing here with "can't locate method
80 * new via package Fetch" sends them looking for a typo. */
81 26 eval_pv("require Fetch;", FALSE);
82 26 SPAGAIN;
83 26 ENTER; SAVETMPS;
84 26 ▶ PUSHMARK(SP); EXTEND(SP, 3);
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 3); 0 26 26
PUSHMARK(SP); EXTEND(SP, 3); 0 26 26
85 26 PUSHs(sv_2mortal(newSVpvs("Fetch")));
86 26 PUSHs(sv_2mortal(newSVpvs("timeout")));
87 26 ▶ PUSHs(t ? t : sv_2mortal(newSViv(10)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(t ? t : sv_2mortal(newSViv(10))); 0 26 26
88 26 PUTBACK;
89 26 count = call_method("new", G_SCALAR | G_EVAL);
90 26 SPAGAIN;
91 26 ▶ if (!SvTRUE(ERRSV) && count > 0) made = newSVsv(POPs);
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) made = newSVsv(POPs); 26 0 26
if (!SvTRUE(ERRSV) && count > 0) made = newSVsv(POPs); 26 0 26
if (!SvTRUE(ERRSV) && count > 0) made = newSVsv(POPs); 26 0 26
92 0 ▶ else if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) (void)POPs; 0 0 0
93 26 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 26 0 26
94 26 ▶ if (!made)
Branch: 1 branch
BranchTrueFalseTotal
if (!made) 0 26 26
95 0 ▶ croak("Punk::OpenTelemetry::Exporter: no `ua` given and "
Branch: 1 branch
BranchTrueFalseTotal
croak("Punk::OpenTelemetry::Exporter: no `ua` given and " 0 0 0
96 "Fetch->new failed: %" SVf, SVfARG(ERRSV));
97 26 (void)hv_stores(self, "ua", made);
98 }
99  
100 35 RETVAL = sv_bless(newRV_noinc((SV *)self), gv_stashpv(cls, GV_ADD));
101 }
102 OUTPUT:
103 RETVAL
104  
105 # stats(): a COPY of the counters, so a caller cannot edit the live hash by
106 # accident - and so a snapshot taken now still reads the same later.
107 SV *
108 stats(self)
109 SV *self
110 CODE:
111 {
112 2 HV *h = otel_hv_of(aTHX_ self);
113 2 ▶ HV *st = h ? otel_h_hv(aTHX_ h, "stats") : NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *st = h ? otel_h_hv(aTHX_ h, "stats") : NULL; 2 0 2
114 2 HV *out = newHV();
115 2 ▶ if (st) {
Branch: 1 branch
BranchTrueFalseTotal
if (st) { 2 0 2
116 HE *e;
117 2 hv_iterinit(st);
118 14 ▶ while ((e = hv_iternext(st))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((e = hv_iternext(st))) { 12 2 14
119 STRLEN kl;
120 12 ▶ const char *k = HePV(e, kl);
Branch: 1 branch
BranchTrueFalseTotal
const char *k = HePV(e, kl); 0 12 12
121 12 (void)hv_store(out, k, (I32)kl, newSVsv(HeVAL(e)), 0);
122 }
123 }
124 2 RETVAL = newRV_noinc((SV *)out);
125 }
126 OUTPUT:
127 RETVAL
128  
129 # _endpoint_for($signal): the URL to post this signal to, or undef.
130 SV *
131 _endpoint_for(self, signal)
132 SV *self
133 SV *signal
134 CODE:
135 {
136 7 HV *h = otel_hv_of(aTHX_ self);
137 7 ▶ SV *u = h ? otel_exp_endpoint_for(aTHX_ h, signal) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *u = h ? otel_exp_endpoint_for(aTHX_ h, signal) : NULL; 7 0 7
138 7 ▶ if (!u) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!u) XSRETURN_UNDEF; 1 6 7
139 6 RETVAL = newSVsv(u);
140 }
141 OUTPUT:
142 RETVAL
143  
144 # _classify($status, $headers, $body) -> ($verdict, $detail)
145 #
146 # ok - accepted in full
147 # partial - accepted, but some of it was rejected. NOT a failure and NOT
148 # retryable; the count has to be surfaced or data disappears
149 # while every dashboard stays green.
150 # retry - a transient refusal; detail is the Retry-After seconds, if any
151 # permanent - a refusal that will not improve by being repeated
152 void
153 _classify(self, status, headers = &PL_sv_undef, body = &PL_sv_undef)
154 SV *self
155 SV *status
156 SV *headers
157 SV *body
158 PPCODE:
159 {
160 30 HV *h = otel_hv_of(aTHX_ self);
161 IV st;
162 30 ▶ if (!h) croak("Punk::OpenTelemetry::Exporter::_classify: not an exporter");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Punk::OpenTelemetry::Exporter::_classify: not an exporter"); 0 30 30
163 30 ▶ if (!SvOK(status)) { /* transport failure */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(status)) { /* transport failure */ 1 29 30
164 1 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 1 1
165 1 mPUSHp("retry", 5);
166 1 PUSHs(&PL_sv_undef);
167 1 XSRETURN(2);
168 }
169 29 st = SvIV(status);
170 29 ▶ if (st >= 200 && st < 300) {
Branch: 2 branches
BranchTrueFalseTotal
if (st >= 200 && st < 300) { 29 0 29
if (st >= 200 && st < 300) { 10 19 29
171 10 SV *p = otel_exp_is_json(aTHX_ h)
172 1 ? otel_exp_parse_partial_json(aTHX_ body)
173 10 ▶ : otel_exp_parse_partial(aTHX_ body);
Branch: 1 branch
BranchTrueFalseTotal
: otel_exp_parse_partial(aTHX_ body); 1 9 10
174 10 ▶ if (p) {
Branch: 1 branch
BranchTrueFalseTotal
if (p) { 3 7 10
175 3 HV *ph = otel_hv_of(aTHX_ p);
176 3 ▶ SV **r = ph ? hv_fetchs(ph, "rejected", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **r = ph ? hv_fetchs(ph, "rejected", 0) : NULL; 3 0 3
177 3 ▶ if (r && *r && SvTRUE(*r)) {
Branch: 3 branches
BranchTrueFalseTotal
if (r && *r && SvTRUE(*r)) { 3 0 3
if (r && *r && SvTRUE(*r)) { 3 0 3
if (r && *r && SvTRUE(*r)) { 2 1 3
178 2 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 2 2
179 2 mPUSHp("partial", 7);
180 2 PUSHs(p);
181 2 XSRETURN(2);
182 }
183 }
184 8 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 8 8
185 8 mPUSHp("ok", 2);
186 8 PUSHs(&PL_sv_undef);
187 8 XSRETURN(2);
188 }
189 19 ▶ if (otel_exp_retryable(st)) {
Branch: 1 branch
BranchTrueFalseTotal
if (otel_exp_retryable(st)) { 8 11 19
190 8 SV *after = otel_exp_retry_after(aTHX_ headers);
191 8 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 8 8
192 8 mPUSHp("retry", 5);
193 8 ▶ PUSHs(after ? after : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(after ? after : &PL_sv_undef); 3 5 8
194 8 XSRETURN(2);
195 }
196 11 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 11 11
197 11 mPUSHp("permanent", 9);
198 11 PUSHs(&PL_sv_undef);
199 11 XSRETURN(2);
200 }
201  
202 # backoff($attempt, $retry_after): the delay before this attempt. Pure, so the
203 # policy is tested directly rather than inferred from timings.
204 NV
205 backoff(self, attempt, retry_after = &PL_sv_undef)
206 SV *self
207 IV attempt
208 SV *retry_after
209 CODE:
210 PERL_UNUSED_VAR(self);
211 602 RETVAL = otel_exp_backoff(aTHX_ attempt, retry_after);
212 OUTPUT:
213 RETVAL
214  
215 # _retry_after($headers): exposed so the header parse is tested on its own
216 # rather than only through a 503.
217 SV *
218 _retry_after(headers)
219 SV *headers
220 CODE:
221 {
222 6 SV *v = otel_exp_retry_after(aTHX_ headers);
223 6 ▶ if (!v) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!v) XSRETURN_UNDEF; 3 3 6
224 3 RETVAL = newSVsv(v);
225 }
226 OUTPUT:
227 RETVAL
228  
229 # _parse_partial($bytes) / _parse_partial_json($bytes)
230 SV *
231 _parse_partial(body)
232 SV *body
233 CODE:
234 {
235 0 SV *p = otel_exp_parse_partial(aTHX_ body);
236 0 ▶ if (!p) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!p) XSRETURN_UNDEF; 0 0 0
237 0 RETVAL = newSVsv(p);
238 }
239 OUTPUT:
240 RETVAL
241  
242 SV *
243 _parse_partial_json(body)
244 SV *body
245 CODE:
246 {
247 0 SV *p = otel_exp_parse_partial_json(aTHX_ body);
248 0 ▶ if (!p) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!p) XSRETURN_UNDEF; 0 0 0
249 0 RETVAL = newSVsv(p);
250 }
251 OUTPUT:
252 RETVAL
253  
254 # encode($signal, $payload): the payload as bytes for the configured protocol.
255 SV *
256 encode(self, signal, payload)
257 SV *self
258 SV *signal
259 SV *payload
260 CODE:
261 {
262 15 HV *h = otel_hv_of(aTHX_ self);
263 STRLEN sl;
264 30 ▶ const char *sp = SvOK(signal) ? SvPV_const(signal, sl) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *sp = SvOK(signal) ? SvPV_const(signal, sl) : ""; 15 0 15
265 15 ▶ if (!SvOK(signal)) sl = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(signal)) sl = 0; 0 15 15
266 15 ▶ int is_traces = (sl == 6 && memEQ(sp, "traces", 6));
Branch: 2 branches
BranchTrueFalseTotal
int is_traces = (sl == 6 && memEQ(sp, "traces", 6)); 6 9 15
int is_traces = (sl == 6 && memEQ(sp, "traces", 6)); 6 0 6
267 15 ▶ int is_metrics = (sl == 7 && memEQ(sp, "metrics", 7));
Branch: 2 branches
BranchTrueFalseTotal
int is_metrics = (sl == 7 && memEQ(sp, "metrics", 7)); 5 10 15
int is_metrics = (sl == 7 && memEQ(sp, "metrics", 7)); 5 0 5
268 15 ▶ int is_logs = (sl == 4 && memEQ(sp, "logs", 4));
Branch: 2 branches
BranchTrueFalseTotal
int is_logs = (sl == 4 && memEQ(sp, "logs", 4)); 3 12 15
int is_logs = (sl == 4 && memEQ(sp, "logs", 4)); 3 0 3
269  
270 15 ▶ if (!h) croak("Punk::OpenTelemetry::Exporter::encode: not an exporter");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Punk::OpenTelemetry::Exporter::encode: not an exporter"); 0 15 15
271 15 ▶ if (!(is_traces || is_metrics || is_logs))
Branch: 3 branches
BranchTrueFalseTotal
if (!(is_traces || is_metrics || is_logs)) 9 6 15
if (!(is_traces || is_metrics || is_logs)) 4 5 9
if (!(is_traces || is_metrics || is_logs)) 1 3 4
272 1 croak("Punk::OpenTelemetry::Exporter: unknown signal '%.*s' - "
273 "traces, metrics and logs exist\n", (int)sl, sp);
274 14 ▶ if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV)) 14 0 14
if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV)) 14 0 14
if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV)) 0 14 14
275 0 croak("Punk::OpenTelemetry::Exporter::encode: "
276 "expected a hashref payload");
277 14 ▶ if (otel_exp_is_json(aTHX_ h)) {
Branch: 1 branch
BranchTrueFalseTotal
if (otel_exp_is_json(aTHX_ h)) { 3 11 14
278 frj_opts o;
279 SV *tree;
280 /* Only traces have a JSON rendering. Refused by NAME rather than
281 * silently sent as protobuf under a JSON content type, which
282 * would be a body the far side cannot parse and an error message
283 * blaming the receiver. */
284 3 ▶ if (!is_traces)
Branch: 1 branch
BranchTrueFalseTotal
if (!is_traces) 1 2 3
285 1 croak("Punk::OpenTelemetry::Exporter: %.*s over OTLP/JSON is "
286 "not implemented - use http/protobuf for this signal\n",
287 (int)sl, sp);
288 2 Zero(&o, 1, frj_opts);
289 2 o.sort_keys = 1; /* same reason as Encode::traces_json */
290 2 tree = sv_2mortal(otel_json_traces_sv(aTHX_ (HV *)SvRV(payload)));
291 2 RETVAL = otel_frj(aTHX)->encode(aTHX_ tree, &o);
292 }
293 11 ▶ else if (is_metrics) RETVAL = otel_encode_metrics(aTHX_ (HV *)SvRV(payload));
Branch: 1 branch
BranchTrueFalseTotal
else if (is_metrics) RETVAL = otel_encode_metrics(aTHX_ (HV *)SvRV(payload)); 4 7 11
294 7 ▶ else if (is_logs) RETVAL = otel_encode_logs(aTHX_ (HV *)SvRV(payload));
Branch: 1 branch
BranchTrueFalseTotal
else if (is_logs) RETVAL = otel_encode_logs(aTHX_ (HV *)SvRV(payload)); 3 4 7
295 4 else RETVAL = otel_encode_traces(aTHX_ (HV *)SvRV(payload));
296 }
297 OUTPUT:
298 RETVAL
299  
300 # _attempt($signal, $bytes): one POST. Returns the ua's future, or undef when
301 # no endpoint is configured for the signal.
302 SV *
303 _attempt(self, signal, bytes)
304 SV *self
305 SV *signal
306 SV *bytes
307 CODE:
308 {
309 10 HV *h = otel_hv_of(aTHX_ self);
310 SV *url, *ua, *body;
311 AV *hdrs;
312 HV *extra;
313 10 ▶ if (!h) croak("Punk::OpenTelemetry::Exporter::_attempt: not an exporter");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Punk::OpenTelemetry::Exporter::_attempt: not an exporter"); 0 10 10
314 10 url = otel_exp_endpoint_for(aTHX_ h, signal);
315 10 ▶ if (!url) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!url) XSRETURN_UNDEF; 1 9 10
316 {
317 9 hdrs = (AV *)sv_2mortal((SV *)newAV());
318 {
319 9 SV *p = otel_h(aTHX_ h, "protocol");
320 STRLEN pl;
321 18 ▶ const char *pp = p ? SvPV_const(p, pl) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *pp = p ? SvPV_const(p, pl) : ""; 9 0 9
322 9 ▶ if (!p) pl = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!p) pl = 0; 0 9 9
323 9 av_push(hdrs, newSVpvs("Content-Type"));
324 9 av_push(hdrs, newSVpv(otel_exp_content_type(pp, pl), 0));
325 }
326 9 extra = otel_h_hv(aTHX_ h, "headers");
327 9 ▶ if (extra) {
Branch: 1 branch
BranchTrueFalseTotal
if (extra) { 9 0 9
328 HE *e;
329 9 hv_iterinit(extra);
330 10 ▶ while ((e = hv_iternext(extra))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((e = hv_iternext(extra))) { 1 9 10
331 STRLEN kl;
332 1 ▶ const char *k = HePV(e, kl);
Branch: 1 branch
BranchTrueFalseTotal
const char *k = HePV(e, kl); 0 1 1
333 1 av_push(hdrs, newSVpvn(k, kl));
334 1 av_push(hdrs, newSVsv(HeVAL(e)));
335 }
336 }
337  
338 9 body = bytes;
339 { /* gzip when asked for it and IO::Compress::Gzip is there; a
340 * missing compressor sends it uncompressed rather than not at
341 * all, because telemetry that did not arrive is worse than
342 * telemetry that arrived large */
343 9 SV *c = otel_h(aTHX_ h, "compression");
344 STRLEN cl;
345 18 ▶ const char *cp = c ? SvPV_const(c, cl) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *cp = c ? SvPV_const(c, cl) : ""; 9 0 9
346 9 ▶ if (c && cl == 4 && memEQ(cp, "gzip", 4)) {
Branch: 3 branches
BranchTrueFalseTotal
if (c && cl == 4 && memEQ(cp, "gzip", 4)) { 9 0 9
if (c && cl == 4 && memEQ(cp, "gzip", 4)) { 9 0 9
if (c && cl == 4 && memEQ(cp, "gzip", 4)) { 1 8 9
347 1 SV *out = sv_2mortal(newSVpvs(""));
348 1 dSP; int count; int ok = 0;
349 1 eval_pv("require IO::Compress::Gzip;", FALSE);
350 1 SPAGAIN;
351 1 ▶ if (!SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV)) { 1 0 1
if (!SvTRUE(ERRSV)) { 1 0 1
352 1 ENTER; SAVETMPS;
353 1 ▶ PUSHMARK(SP); EXTEND(SP, 2);
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 2); 0 1 1
PUSHMARK(SP); EXTEND(SP, 2); 0 1 1
354 1 PUSHs(sv_2mortal(newRV_inc(bytes)));
355 1 PUSHs(sv_2mortal(newRV_inc(out)));
356 1 PUTBACK;
357 1 count = call_pv("IO::Compress::Gzip::gzip",
358 G_SCALAR | G_EVAL);
359 1 SPAGAIN;
360 /* POPs into a TEMPORARY, never straight into SvTRUE.
361 * Before perl 5.30 SvTRUE is a macro that evaluates
362 * its argument more than once, so SvTRUE(POPs) pops
363 * the stack several times and corrupts it - the crash
364 * lands later, wherever the damaged stack is next
365 * used, which is why this showed up as a SEGV after
366 * all 72 subtests had passed. */
367 1 ▶ if (!SvTRUE(ERRSV) && count > 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) { 1 0 1
if (!SvTRUE(ERRSV) && count > 0) { 1 0 1
if (!SvTRUE(ERRSV) && count > 0) { 1 0 1
368 1 SV *r = POPs;
369 1 ok = SvTRUE(r);
370 }
371 0 ▶ else if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) (void)POPs; 0 0 0
372 1 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 1 0 1
373 }
374 1 ▶ if (ok && SvCUR(out)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ok && SvCUR(out)) { 1 0 1
if (ok && SvCUR(out)) { 1 0 1
375 1 body = out;
376 1 av_push(hdrs, newSVpvs("Content-Encoding"));
377 1 av_push(hdrs, newSVpvs("gzip"));
378 }
379 }
380 }
381  
382 9 ua = otel_h(aTHX_ h, "ua");
383 9 ▶ if (!ua) croak("Punk::OpenTelemetry::Exporter::_attempt: no ua");
Branch: 1 branch
BranchTrueFalseTotal
if (!ua) croak("Punk::OpenTelemetry::Exporter::_attempt: no ua"); 0 9 9
384 {
385 9 dSP; int count; SV *f = NULL;
386 9 SV *t = otel_h(aTHX_ h, "timeout");
387 9 ENTER; SAVETMPS;
388 9 ▶ PUSHMARK(SP); EXTEND(SP, 9);
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 9); 0 9 9
PUSHMARK(SP); EXTEND(SP, 9); 0 9 9
389 9 PUSHs(ua);
390 9 PUSHs(sv_2mortal(newSVpvs("POST")));
391 9 PUSHs(url);
392 9 PUSHs(sv_2mortal(newSVpvs("headers")));
393 9 PUSHs(sv_2mortal(newRV_inc((SV *)hdrs)));
394 9 PUSHs(sv_2mortal(newSVpvs("body")));
395 9 PUSHs(body);
396 9 PUSHs(sv_2mortal(newSVpvs("timeout")));
397 9 ▶ PUSHs(t ? t : sv_2mortal(newSViv(10)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(t ? t : sv_2mortal(newSViv(10))); 0 9 9
398 9 PUTBACK;
399 9 count = call_method("request", G_SCALAR);
400 9 SPAGAIN;
401 9 ▶ if (count > 0) f = newSVsv(POPs);
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) f = newSVsv(POPs); 9 0 9
402 9 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 9 0 9
403 9 ▶ if (!f) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!f) XSRETURN_UNDEF; 0 9 9
404 9 RETVAL = f;
405 }
406 }
407 }
408 OUTPUT:
409 RETVAL
410  
411 # _sleep($secs, $cb): wait, then call back. On a loop that can time (Fetch's
412 # adapters) this parks; with no loop it blocks, which is the honest thing for a
413 # retry in a script. Returns 1 when it parked, 0 when it blocked.
414 IV
415 _sleep(self, secs, cb)
416 SV *self
417 NV secs
418 SV *cb
419 CODE:
420 {
421 2 HV *h = otel_hv_of(aTHX_ self);
422 2 ▶ SV *ua = h ? otel_h(aTHX_ h, "ua") : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *ua = h ? otel_h(aTHX_ h, "ua") : NULL; 2 0 2
423 2 SV *loop = NULL;
424 2 RETVAL = 0;
425 2 ▶ if (ua) {
Branch: 1 branch
BranchTrueFalseTotal
if (ua) { 2 0 2
426 2 dSP; int count;
427 2 ENTER; SAVETMPS;
428 2 ▶ PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ua); PUTBACK;
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ua); PUTBACK; 0 2 2
PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ua); PUTBACK; 0 2 2
429 2 count = call_method("loop", G_SCALAR | G_EVAL);
430 2 SPAGAIN;
431 2 ▶ if (!SvTRUE(ERRSV) && count > 0) { SV *l = POPs; if (SvOK(l)) loop = newSVsv(l); }
Branch: 4 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) { SV *l = POPs; if (SvOK(l)) loop = newSVsv(l); } 2 0 2
if (!SvTRUE(ERRSV) && count > 0) { SV *l = POPs; if (SvOK(l)) loop = newSVsv(l); } 2 0 2
if (!SvTRUE(ERRSV) && count > 0) { SV *l = POPs; if (SvOK(l)) loop = newSVsv(l); } 2 0 2
if (!SvTRUE(ERRSV) && count > 0) { SV *l = POPs; if (SvOK(l)) loop = newSVsv(l); } 1 1 2
432 0 ▶ else if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) (void)POPs; 0 0 0
433 2 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 2 0 2
434 }
435 2 ▶ if (loop) sv_2mortal(loop);
Branch: 1 branch
BranchTrueFalseTotal
if (loop) sv_2mortal(loop); 1 1 2
436 2 ▶ if (loop && SvROK(loop) && SvOBJECT(SvRV(loop))
Branch: 3 branches
BranchTrueFalseTotal
if (loop && SvROK(loop) && SvOBJECT(SvRV(loop)) 1 1 2
if (loop && SvROK(loop) && SvOBJECT(SvRV(loop)) 1 0 1
if (loop && SvROK(loop) && SvOBJECT(SvRV(loop)) 1 0 1
437 1 ▶ && gv_fetchmethod_autoload(SvSTASH(SvRV(loop)), "_ft_timer", 0)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gv_fetchmethod_autoload(SvSTASH(SvRV(loop)), "_ft_timer", 0)) { 1 0 1
438 1 dSP;
439 1 ENTER; SAVETMPS;
440 1 ▶ PUSHMARK(SP); EXTEND(SP, 3);
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 3); 0 1 1
PUSHMARK(SP); EXTEND(SP, 3); 0 1 1
441 1 PUSHs(loop);
442 1 PUSHs(sv_2mortal(newSVnv(secs)));
443 1 PUSHs(cb);
444 1 PUTBACK;
445 1 (void)call_method("_ft_timer", G_VOID | G_DISCARD);
446 1 ▶ SPAGAIN; PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
SPAGAIN; PUTBACK; FREETMPS; LEAVE; 1 0 1
447 1 RETVAL = 1;
448 }
449 else {
450 1 dSP;
451 { /* select undef,undef,undef,$secs - the same blocking wait */
452 struct timeval tv;
453 1 ▶ NV s = secs > 0 ? secs : 0;
Branch: 1 branch
BranchTrueFalseTotal
NV s = secs > 0 ? secs : 0; 1 0 1
454 1 tv.tv_sec = (long)s;
455 1 tv.tv_usec = (long)((s - (NV)tv.tv_sec) * 1000000.0);
456 1 PerlSock_select(0, NULL, NULL, NULL, &tv);
457 }
458 1 ENTER; SAVETMPS;
459 1 ▶ PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); PUTBACK; 0 1 1
460 1 (void)call_sv(cb, G_VOID | G_DISCARD);
461 1 ▶ SPAGAIN; PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
SPAGAIN; PUTBACK; FREETMPS; LEAVE; 0 1 1
462 }
463 }
464 OUTPUT:
465 RETVAL
« include/otel_instr.h ↑ Summary xs/resource.xs »