xs/resource.xs

filter: Statementstmt 88.6% 39 / 44 Branchbran 65.3% 34 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 76.0% 73 / 96 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/exporter.xs ↑ Summary include/otel_w3c.h »
1 MODULE = Punk::OpenTelemetry PACKAGE = Punk::OpenTelemetry::Resource
2  
3 PROTOTYPES: DISABLE
4  
5 # instance_id(): a fresh UUID-shaped id, from the same entropy source the
6 # trace ids use. Never cached - see otel_resource.h for why rand() is not an
7 # option here.
8 SV *
9 instance_id()
10 CODE:
11 0 RETVAL = otel_res_instance_id(aTHX);
12 OUTPUT:
13 RETVAL
14  
15 # detect(%overrides): the resource, as a hashref.
16 #
17 # Precedence, lowest first: the detected defaults, then
18 # OTEL_RESOURCE_ATTRIBUTES, then OTEL_SERVICE_NAME for the service name, then
19 # the explicit arguments - which win over everything, including the
20 # environment, because a caller that said so meant it.
21 SV *
22 detect(...)
23 CODE:
24 {
25 70 HV *r = newHV();
26 70 HV *over = (HV *)sv_2mortal((SV *)newHV());
27 70 SV *service = NULL;
28 SV *tmp;
29 int i;
30  
31 70 ▶ if (items % 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items % 2) 0 70 70
32 0 croak("Punk::OpenTelemetry::Resource::detect: "
33 "odd number of overrides");
34 136 ▶ for (i = 0; i + 1 < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i + 1 < items; i += 2) { 66 70 136
35 STRLEN kl;
36 66 const char *k = SvPV_const(ST(i), kl);
37 66 ▶ if (kl == 12 && memEQ(k, "service_name", 12))
Branch: 2 branches
BranchTrueFalseTotal
if (kl == 12 && memEQ(k, "service_name", 12)) 66 0 66
if (kl == 12 && memEQ(k, "service_name", 12)) 66 0 66
38 66 service = ST(i + 1); /* the one named override */
39 else
40 0 (void)hv_store(over, k, (I32)kl, newSVsv(ST(i + 1)), 0);
41 }
42  
43 70 ▶ if (!(service && SvOK(service))) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(service && SvOK(service))) { 66 4 70
if (!(service && SvOK(service))) { 0 66 66
44 4 SV **e = hv_fetchs(GvHV(PL_envgv), "OTEL_SERVICE_NAME", 0);
45 4 ▶ service = (e && *e && SvOK(*e)) ? *e : NULL;
Branch: 3 branches
BranchTrueFalseTotal
service = (e && *e && SvOK(*e)) ? *e : NULL; 3 1 4
service = (e && *e && SvOK(*e)) ? *e : NULL; 3 0 3
service = (e && *e && SvOK(*e)) ? *e : NULL; 2 1 3
46 }
47 70 ▶ if (!(service && SvOK(service)))
Branch: 2 branches
BranchTrueFalseTotal
if (!(service && SvOK(service))) 68 2 70
if (!(service && SvOK(service))) 0 68 68
48 2 service = sv_2mortal(newSVpvs("unknown_service"));
49  
50 /* unknown_service is the spec's default and a genuinely bad place to
51 * end up: it is the single most common reason a trace cannot be found
52 * again, because every unnamed service in the fleet shares the name.
53 * Say so once, at boot, where somebody can still act on it. */
54 {
55 STRLEN sl;
56 70 const char *sp = SvPV_const(service, sl);
57 70 ▶ if (sl == 15 && memEQ(sp, "unknown_service", 15)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sl == 15 && memEQ(sp, "unknown_service", 15)) { 2 68 70
if (sl == 15 && memEQ(sp, "unknown_service", 15)) { 2 0 2
58 2 SV **d = hv_fetchs(GvHV(PL_envgv), "OTEL_SDK_DISABLED", 0);
59 2 ▶ if (!(d && *d && SvTRUE(*d)))
Branch: 3 branches
BranchTrueFalseTotal
if (!(d && *d && SvTRUE(*d))) 1 1 2
if (!(d && *d && SvTRUE(*d))) 1 0 1
if (!(d && *d && SvTRUE(*d))) 0 1 1
60 1 warn("Punk::OpenTelemetry: no service.name configured - "
61 "telemetry will arrive as 'unknown_service' and be "
62 "indistinguishable from every other unnamed "
63 "service\n");
64 }
65 }
66  
67 70 (void)hv_stores(r, "service.name", newSVsv(service));
68 70 (void)hv_stores(r, "service.instance.id", otel_res_instance_id(aTHX));
69 70 (void)hv_stores(r, "telemetry.sdk.name", newSVpvs("punk-opentelemetry"));
70 70 (void)hv_stores(r, "telemetry.sdk.language", newSVpvs("perl"));
71 70 tmp = get_sv("Punk::OpenTelemetry::VERSION", 0);
72 70 ▶ (void)hv_stores(r, "telemetry.sdk.version",
Branch: 2 branches
BranchTrueFalseTotal
(void)hv_stores(r, "telemetry.sdk.version", 70 0 70
(void)hv_stores(r, "telemetry.sdk.version", 70 0 70
73 (tmp && SvOK(tmp)) ? newSVsv(tmp) : newSV(0));
74 70 (void)hv_stores(r, "process.pid", newSViv((IV)PerlProc_getpid()));
75 70 (void)hv_stores(r, "process.runtime.name", newSVpvs("perl"));
76 /* sprintf('%vd', $^V), built from the same numbers $^V is */
77 70 (void)hv_stores(r, "process.runtime.version",
78 newSVpvf("%d.%d.%d", (int)PERL_REVISION, (int)PERL_VERSION,
79 (int)PERL_SUBVERSION));
80 70 tmp = otel_res_perl_sv(aTHX_ "\030", 1); /* $^X */
81 70 ▶ if (tmp) (void)hv_stores(r, "process.executable.name", newSVsv(tmp));
Branch: 1 branch
BranchTrueFalseTotal
if (tmp) (void)hv_stores(r, "process.executable.name", newSVsv(tmp)); 70 0 70
82  
83 70 tmp = otel_res_hostname(aTHX);
84 70 ▶ if (tmp) (void)hv_stores(r, "host.name", newSVsv(tmp));
Branch: 1 branch
BranchTrueFalseTotal
if (tmp) (void)hv_stores(r, "host.name", newSVsv(tmp)); 70 0 70
85 #ifdef ARCHNAME
86 /* $Config{archname}, without loading Config: the macro IS what the
87 * Config entry was generated from. */
88 70 (void)hv_stores(r, "host.arch", newSVpvs(ARCHNAME));
89 #endif
90  
91 {
92 70 SV **e = hv_fetchs(GvHV(PL_envgv), "OTEL_RESOURCE_ATTRIBUTES", 0);
93 70 ▶ if (e && *e && SvOK(*e) && SvCUR(*e)) {
Branch: 4 branches
BranchTrueFalseTotal
if (e && *e && SvOK(*e) && SvCUR(*e)) { 2 68 70
if (e && *e && SvOK(*e) && SvCUR(*e)) { 2 0 2
if (e && *e && SvOK(*e) && SvCUR(*e)) { 1 1 2
if (e && *e && SvOK(*e) && SvCUR(*e)) { 1 0 1
94 STRLEN el;
95 1 const char *ep = SvPV_const(*e, el);
96 1 otel_res_parse_env_attrs(aTHX_ r, ep, el);
97 }
98 }
99  
100 { /* explicit overrides win over everything, including the
101 * environment. Applied last, so they always do. */
102 HE *he;
103 70 hv_iterinit(over);
104 70 ▶ while ((he = hv_iternext(over))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(over))) { 0 70 70
105 STRLEN kl;
106 0 ▶ const char *k = HePV(he, kl);
Branch: 1 branch
BranchTrueFalseTotal
const char *k = HePV(he, kl); 0 0 0
107 0 (void)hv_store(r, k, (I32)kl, newSVsv(HeVAL(he)), 0);
108 }
109 }
110  
111 70 RETVAL = newRV_noinc((SV *)r);
112 }
113 OUTPUT:
114 RETVAL
« xs/exporter.xs ↑ Summary include/otel_w3c.h »