xs/logger.xs

filter: Statementstmt 95.1% 39 / 41 Branchbran 64.2% 36 / 56 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 77.3% 75 / 97 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/otel_w3c.h ↑ Summary include/otel_export.h »
1 MODULE = Punk::OpenTelemetry PACKAGE = Punk::OpenTelemetry::Logs
2  
3 PROTOTYPES: DISABLE
4  
5 # The logs signal. Records are a COPY: the application's logs still go
6 # wherever they were going, and the collector gets a duplicate. A telemetry
7 # layer that silently redirects an operator's logs is a bad neighbour, and the
8 # failure mode when the collector is down would be that the logs vanish.
9  
10 SV *
11 new(class, ...)
12 SV *class
13 CODE:
14 {
15 24 otel_logger *lg = otel_logger_new(aTHX);
16 int i;
17 56 ▶ for (i = 1; i + 1 < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i + 1 < items; i += 2) { 32 24 56
18 32 const char *k = SvPV_nolen(ST(i));
19 32 SV *v = ST(i + 1);
20 32 ▶ if (strEQ(k, "scope_name")) lg->scope_name = newSVsv(v);
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(k, "scope_name")) lg->scope_name = newSVsv(v); 16 16 32
21 16 ▶ else if (strEQ(k, "scope_version")) lg->scope_version = newSVsv(v);
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(k, "scope_version")) lg->scope_version = newSVsv(v); 0 16 16
22 16 ▶ else if (strEQ(k, "resource")
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(k, "resource") 16 0 16
23 16 ▶ && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
&& SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) { 16 0 16
&& SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) { 16 0 16
24 16 HV *src = (HV *)SvRV(v);
25 HE *he;
26 16 hv_iterinit(src);
27 172 ▶ while ((he = hv_iternext(src)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(src))) 156 16 172
28 156 (void)hv_store_ent(lg->resource, hv_iterkeysv(he),
29 newSVsv(HeVAL(he)), 0);
30 }
31 }
32 24 RETVAL = sv_bless(newRV_noinc(newSViv(PTR2IV(lg))),
33 gv_stashpv("Punk::OpenTelemetry::Logs", GV_ADD));
34 }
35 OUTPUT:
36 RETVAL
37  
38 void
39 DESTROY(self)
40 SV *self
41 CODE:
42 24 ▶ if (SvROK(self) && SvIOK(SvRV(self)))
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(self) && SvIOK(SvRV(self))) 24 0 24
if (SvROK(self) && SvIOK(SvRV(self))) 24 0 24
43 24 otel_logger_free(aTHX_ INT2PTR(otel_logger *, SvIV(SvRV(self))));
44  
45 # emit($level, $body, \%attributes, $span)
46 #
47 # $span is what correlates the line with a trace, and is the highest-value,
48 # lowest-cost part of this whole signal: it is what makes somebody actually
49 # click from a log line into a trace.
50 void
51 emit(self, level, body, attrs = &PL_sv_undef, span = &PL_sv_undef)
52 SV *self
53 SV *level
54 SV *body
55 SV *attrs
56 SV *span
57 CODE:
58 {
59 10018 otel_logger *lg = INT2PTR(otel_logger *, SvIV(SvRV(self)));
60 2 ▶ HV *a = (SvROK(attrs) && SvTYPE(SvRV(attrs)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
HV *a = (SvROK(attrs) && SvTYPE(SvRV(attrs)) == SVt_PVHV) 2 0 2
61 10020 ▶ ? (HV *)SvRV(attrs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(attrs) : NULL; 2 10016 10018
62 2 ▶ otel_span *sp = (SvROK(span) && SvIOK(SvRV(span)) && SvIV(SvRV(span)))
Branch: 2 branches
BranchTrueFalseTotal
otel_span *sp = (SvROK(span) && SvIOK(SvRV(span)) && SvIV(SvRV(span))) 2 0 2
otel_span *sp = (SvROK(span) && SvIOK(SvRV(span)) && SvIV(SvRV(span))) 2 0 2
63 10020 ▶ ? INT2PTR(otel_span *, SvIV(SvRV(span))) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? INT2PTR(otel_span *, SvIV(SvRV(span))) : NULL; 2 10016 10018
64 /* the SDK's own diagnostics must never come back round through here */
65 10018 ▶ if (OTEL_INSTR.suppress) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (OTEL_INSTR.suppress) XSRETURN_EMPTY; 2 10016 10018
66 10016 otel_logger_emit(aTHX_ lg, level, body, a, sp);
67 }
68  
69 SV *
70 drain(self, max = 512)
71 SV *self
72 int max
73 CODE:
74 {
75 10 otel_logger *lg = INT2PTR(otel_logger *, SvIV(SvRV(self)));
76 10 ▶ SV *p = otel_logger_drain(aTHX_ lg, max > 0 ? max : 512);
Branch: 1 branch
BranchTrueFalseTotal
SV *p = otel_logger_drain(aTHX_ lg, max > 0 ? max : 512); 10 0 10
77 10 ▶ if (!p) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!p) XSRETURN_UNDEF; 3 7 10
78 7 RETVAL = p;
79 }
80 OUTPUT:
81 RETVAL
82  
83 # The OTLP severity number for a Punk level. The bands are four wide and this
84 # picks the FIRST of each, which is what every other SDK emits and what a
85 # threshold written as ">= 13" compares against.
86 IV
87 severity(level)
88 SV *level
89 CODE:
90 16 ▶ RETVAL = otel_sev_of(aTHX_ level);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = otel_sev_of(aTHX_ level); 0 16 16
91 OUTPUT:
92 RETVAL
93  
94 void
95 stats(self)
96 SV *self
97 PPCODE:
98 {
99 8 otel_logger *lg = INT2PTR(otel_logger *, SvIV(SvRV(self)));
100 8 otel_logger_check_fork(aTHX_ lg);
101 8 ▶ EXTEND(SP, 6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 6); 0 8 8
102 8 mPUSHp("emitted", 7); mPUSHi(lg->emitted);
103 8 mPUSHp("dropped", 7); mPUSHi(lg->dropped);
104 8 mPUSHp("queued", 6); mPUSHi(lg->qcount);
105 }
106  
107 MODULE = Punk::OpenTelemetry PACKAGE = Punk::OpenTelemetry::Encode
108  
109 PROTOTYPES: DISABLE
110  
111 # The other two signals on the wire. Same two-pass encoder as the traces one.
112  
113 SV *
114 metrics_protobuf(payload)
115 SV *payload
116 CODE:
117 {
118 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
119 0 croak("Punk::OpenTelemetry::Encode::metrics_protobuf: "
120 "expected a hashref payload");
121 14 RETVAL = otel_encode_metrics(aTHX_ (HV *)SvRV(payload));
122 }
123 OUTPUT:
124 RETVAL
125  
126 SV *
127 logs_protobuf(payload)
128 SV *payload
129 CODE:
130 {
131 4 ▶ if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV)) 4 0 4
if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV)) 4 0 4
if (!(payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV)) 0 4 4
132 0 croak("Punk::OpenTelemetry::Encode::logs_protobuf: "
133 "expected a hashref payload");
134 4 RETVAL = otel_encode_logs(aTHX_ (HV *)SvRV(payload));
135 }
136 OUTPUT:
137 RETVAL
138  
139 MODULE = Punk::OpenTelemetry PACKAGE = Punk::OpenTelemetry::Logs
140  
141 # Make this the logger the log tap emits into.
142 #
143 # THE PACKAGE LINE ABOVE IS LOAD-BEARING. This file switches to
144 # Punk::OpenTelemetry::Encode part way down, so anything appended to the end
145 # of it lands in THAT package - which is a method that exists, on the wrong
146 # class, and fails only when something calls it.
147 #
148 # The tap is a C observer registered with Punk's logger; it needs to know
149 # which logger to put records in, and there is exactly one per process. The
150 # plugin calls this once, when the logs signal is on - and passing undef turns
151 # the tap off, which is what "logs => 0" has to mean.
152 void
153 install_tap(self = &PL_sv_undef)
154 SV *self
155 CODE:
156 {
157 29 ▶ OTEL_LOGGER = (SvROK(self) && SvIOK(SvRV(self)) && SvIV(SvRV(self)))
Branch: 2 branches
BranchTrueFalseTotal
OTEL_LOGGER = (SvROK(self) && SvIOK(SvRV(self)) && SvIV(SvRV(self))) 14 0 14
OTEL_LOGGER = (SvROK(self) && SvIOK(SvRV(self)) && SvIV(SvRV(self))) 14 0 14
158 29 ▶ ? INT2PTR(otel_logger *, SvIV(SvRV(self))) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? INT2PTR(otel_logger *, SvIV(SvRV(self))) : NULL; 14 1 15
159 }
« include/otel_w3c.h ↑ Summary include/otel_export.h »