| 1 |
|
| /* otel_trace.h - the OTLP trace message tree, in protobuf. |
| 2 |
|
| * |
| 3 |
|
| * ExportTraceServiceRequest |
| 4 |
|
| * ResourceSpans resource, scope_spans[], schema_url |
| 5 |
|
| * Resource attributes[] |
| 6 |
|
| * ScopeSpans scope, spans[], schema_url |
| 7 |
|
| * Scope name, version, attributes[] |
| 8 |
|
| * Span ids, name, kind, times, attributes[], events[], |
| 9 |
|
| * links[], status, flags |
| 10 |
|
| * |
| 11 |
|
| * The input is a Perl hashref shaped for a human to write and for phase 3's |
| 12 |
|
| * span structs to fill in cheaply; see Punk::OpenTelemetry::OTLP for the |
| 13 |
|
| * shape. Everything below is the usual two passes: a size_ function beside |
| 14 |
|
| * each write_ function, agreeing byte for byte. |
| 15 |
|
| */ |
| 16 |
|
| |
| 17 |
|
| #ifndef OTEL_TRACE_H |
| 18 |
|
| #define OTEL_TRACE_H |
| 19 |
|
| |
| 20 |
|
| #include "otel_pb.h" |
| 21 |
|
| #include "otel_proto.h" |
| 22 |
|
| #include "otel_value.h" |
| 23 |
|
| |
| 24 |
|
| /* ---- small readers over the input hash ---------------------------------- */ |
| 25 |
|
| |
| 26 |
6543 |
| static SV *otel_h(pTHX_ HV *h, const char *k) { |
| 27 |
6543 |
▶ | SV **e = h ? hv_fetch(h, k, (I32)strlen(k), 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **e = h ? hv_fetch(h, k, (I32)strlen(k), 0) : NULL; |
6543 |
0 |
6543 |
|
| 28 |
6543 |
▶ | return (e && *e && SvOK(*e)) ? *e : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (e && *e && SvOK(*e)) ? *e : NULL; |
3811 |
2732 |
6543 |
| return (e && *e && SvOK(*e)) ? *e : NULL; |
3811 |
0 |
3811 |
| return (e && *e && SvOK(*e)) ? *e : NULL; |
3809 |
2 |
3811 |
|
| 29 |
|
| } |
| 30 |
1287 |
| static HV *otel_h_hv(pTHX_ HV *h, const char *k) { |
| 31 |
1287 |
| SV *v = otel_h(aTHX_ h, k); |
| 32 |
1287 |
▶ | return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
709 |
578 |
1287 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
709 |
0 |
709 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
709 |
0 |
709 |
|
| 33 |
|
| } |
| 34 |
1245 |
| static AV *otel_h_av(pTHX_ HV *h, const char *k) { |
| 35 |
1245 |
| SV *v = otel_h(aTHX_ h, k); |
| 36 |
1245 |
▶ | return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; |
851 |
394 |
1245 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; |
851 |
0 |
851 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; |
851 |
0 |
851 |
|
| 37 |
|
| } |
| 38 |
1326 |
| static HV *otel_hv_of(pTHX_ SV *v) { |
| 39 |
1326 |
▶ | return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
1326 |
0 |
1326 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
1305 |
21 |
1326 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
1305 |
0 |
1305 |
|
| 40 |
|
| } |
| 41 |
|
| |
| 42 |
|
| /* A trace or span id as raw bytes. Accepts the binary form (what the C SDK |
| 43 |
|
| * holds) and the hex form (what a human writes in a test), because getting |
| 44 |
|
| * this wrong is invisible: a 32-character hex string encoded as bytes is a |
| 45 |
|
| * valid-looking id of the wrong length that no collector will join to |
| 46 |
|
| * anything. `want` is the byte length the field requires. */ |
| 47 |
535 |
| static const char *otel_id(pTHX_ HV *h, const char *k, STRLEN want, |
| 48 |
|
| STRLEN *out, char *scratch) { |
| 49 |
535 |
| SV *v = otel_h(aTHX_ h, k); |
| 50 |
|
| STRLEN l; |
| 51 |
|
| const char *s; |
| 52 |
|
| STRLEN i; |
| 53 |
535 |
| *out = 0; |
| 54 |
535 |
▶ | if (!v) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!v) return NULL; |
218 |
317 |
535 |
|
| 55 |
317 |
| s = SvPV_const(v, l); |
| 56 |
317 |
▶ | if (l == want) { *out = l; return s; } /* already bytes */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (l == want) { *out = l; return s; } /* already bytes */ |
17 |
300 |
317 |
|
| 57 |
300 |
▶ | if (l == want * 2) { /* hex */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (l == want * 2) { /* hex */ |
295 |
5 |
300 |
|
| 58 |
3807 |
▶ | for (i = 0; i < want; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < want; i++) { |
3512 |
295 |
3807 |
|
| 59 |
3512 |
| int hi = -1, lo = -1, j; |
| 60 |
10536 |
▶ | for (j = 0; j < 2; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < 2; j++) { |
7024 |
3512 |
10536 |
|
| 61 |
7024 |
| char c = s[i * 2 + j]; |
| 62 |
7024 |
▶ | int d = (c >= '0' && c <= '9') ? c - '0' |
Branch: 1 branch
| Branch | True | False | Total |
| int d = (c >= '0' && c <= '9') ? c - '0' |
3885 |
3139 |
7024 |
|
| 63 |
17187 |
▶ | : (c >= 'a' && c <= 'f') ? c - 'a' + 10 |
Branch: 2 branches
| Branch | True | False | Total |
| : (c >= 'a' && c <= 'f') ? c - 'a' + 10 |
7024 |
0 |
7024 |
| : (c >= 'a' && c <= 'f') ? c - 'a' + 10 |
3139 |
0 |
3139 |
|
| 64 |
6278 |
▶ | : (c >= 'A' && c <= 'F') ? c - 'A' + 10 : -1; |
Branch: 3 branches
| Branch | True | False | Total |
| : (c >= 'A' && c <= 'F') ? c - 'A' + 10 : -1; |
3139 |
0 |
3139 |
| : (c >= 'A' && c <= 'F') ? c - 'A' + 10 : -1; |
0 |
0 |
0 |
| : (c >= 'A' && c <= 'F') ? c - 'A' + 10 : -1; |
0 |
0 |
0 |
|
| 65 |
7024 |
▶ | if (d < 0) return NULL; /* not hex after all */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (d < 0) return NULL; /* not hex after all */ |
0 |
7024 |
7024 |
|
| 66 |
7024 |
▶ | if (j == 0) hi = d; else lo = d; |
Branch: 1 branch
| Branch | True | False | Total |
| if (j == 0) hi = d; else lo = d; |
3512 |
3512 |
7024 |
|
| 67 |
|
| } |
| 68 |
3512 |
| scratch[i] = (char)((hi << 4) | lo); |
| 69 |
|
| } |
| 70 |
295 |
| *out = want; |
| 71 |
295 |
| return scratch; |
| 72 |
|
| } |
| 73 |
5 |
| return NULL; /* wrong length: omit it */ |
| 74 |
|
| } |
| 75 |
|
| |
| 76 |
|
| /* ---- Status ------------------------------------------------------------- */ |
| 77 |
|
| |
| 78 |
100 |
| static size_t otel_status_size(pTHX_ HV *st) { |
| 79 |
100 |
| size_t n = 0; |
| 80 |
|
| SV *msg, *code; |
| 81 |
100 |
▶ | if (!st) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!st) return 0; |
69 |
31 |
100 |
|
| 82 |
31 |
| msg = otel_h(aTHX_ st, "message"); |
| 83 |
31 |
| code = otel_h(aTHX_ st, "code"); |
| 84 |
31 |
▶ | if (msg) { STRLEN l; (void)SvPV_const(msg, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (msg) { STRLEN l; (void)SvPV_const(msg, l); |
0 |
31 |
31 |
|
| 85 |
0 |
| n += otel_pb_bytes_size(PB_STATUS_MESSAGE, l); } |
| 86 |
|
| /* UNSET is the proto3 default and is never written - which is the point: |
| 87 |
|
| * an instrumentation layer with no opinion must not claim success */ |
| 88 |
31 |
▶ | if (code && SvIV(code) != OTEL_STATUS_UNSET) |
Branch: 2 branches
| Branch | True | False | Total |
| if (code && SvIV(code) != OTEL_STATUS_UNSET) |
31 |
0 |
31 |
| if (code && SvIV(code) != OTEL_STATUS_UNSET) |
26 |
5 |
31 |
|
| 89 |
26 |
| n += otel_pb_int32_size(PB_STATUS_CODE, (int)SvIV(code)); |
| 90 |
31 |
| return n; |
| 91 |
|
| } |
| 92 |
|
| |
| 93 |
5 |
| static void otel_status_write(pTHX_ otel_buf *b, HV *st) { |
| 94 |
|
| SV *msg, *code; |
| 95 |
5 |
▶ | if (!st) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!st) return; |
0 |
5 |
5 |
|
| 96 |
5 |
| msg = otel_h(aTHX_ st, "message"); |
| 97 |
5 |
| code = otel_h(aTHX_ st, "code"); |
| 98 |
5 |
▶ | if (msg) { STRLEN l; const char *s = SvPV_const(msg, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (msg) { STRLEN l; const char *s = SvPV_const(msg, l); |
0 |
5 |
5 |
|
| 99 |
0 |
| otel_pb_bytes(b, PB_STATUS_MESSAGE, s, l); } |
| 100 |
5 |
▶ | if (code && SvIV(code) != OTEL_STATUS_UNSET) |
Branch: 2 branches
| Branch | True | False | Total |
| if (code && SvIV(code) != OTEL_STATUS_UNSET) |
5 |
0 |
5 |
| if (code && SvIV(code) != OTEL_STATUS_UNSET) |
5 |
0 |
5 |
|
| 101 |
5 |
| otel_pb_int32(b, PB_STATUS_CODE, (int)SvIV(code)); |
| 102 |
|
| } |
| 103 |
|
| |
| 104 |
|
| /* ---- Event -------------------------------------------------------------- */ |
| 105 |
|
| |
| 106 |
16 |
| static size_t otel_event_size(pTHX_ HV *ev) { |
| 107 |
16 |
| size_t n = 0; |
| 108 |
|
| SV *t, *name, *dropped; |
| 109 |
16 |
▶ | if (!ev) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ev) return 0; |
0 |
16 |
16 |
|
| 110 |
16 |
| t = otel_h(aTHX_ ev, "time_unix_nano"); |
| 111 |
16 |
| name = otel_h(aTHX_ ev, "name"); |
| 112 |
16 |
| dropped = otel_h(aTHX_ ev, "dropped_attributes_count"); |
| 113 |
16 |
▶ | if (t) n += otel_pb_fixed64_size(PB_EVENT_TIME); |
Branch: 1 branch
| Branch | True | False | Total |
| if (t) n += otel_pb_fixed64_size(PB_EVENT_TIME); |
16 |
0 |
16 |
|
| 114 |
16 |
▶ | if (name) { STRLEN l; (void)SvPV_const(name, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (name) { STRLEN l; (void)SvPV_const(name, l); |
16 |
0 |
16 |
|
| 115 |
16 |
| n += otel_pb_bytes_size(PB_EVENT_NAME, l); } |
| 116 |
16 |
| n += otel_attrs_size(aTHX_ otel_h_hv(aTHX_ ev, "attributes"), |
| 117 |
|
| PB_EVENT_ATTRIBUTES); |
| 118 |
16 |
▶ | if (dropped && SvUV(dropped)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (dropped && SvUV(dropped)) |
0 |
16 |
16 |
| if (dropped && SvUV(dropped)) |
0 |
0 |
0 |
|
| 119 |
0 |
| n += otel_pb_uint64_size(PB_EVENT_DROPPED_ATTRS, SvUV(dropped)); |
| 120 |
16 |
| return n; |
| 121 |
|
| } |
| 122 |
|
| |
| 123 |
3 |
| static void otel_event_write(pTHX_ otel_buf *b, HV *ev) { |
| 124 |
|
| SV *t, *name, *dropped; |
| 125 |
3 |
▶ | if (!ev) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ev) return; |
0 |
3 |
3 |
|
| 126 |
3 |
| t = otel_h(aTHX_ ev, "time_unix_nano"); |
| 127 |
3 |
| name = otel_h(aTHX_ ev, "name"); |
| 128 |
3 |
| dropped = otel_h(aTHX_ ev, "dropped_attributes_count"); |
| 129 |
3 |
▶ | if (t) otel_pb_fixed64(b, PB_EVENT_TIME, (U64TYPE)SvUV(t)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (t) otel_pb_fixed64(b, PB_EVENT_TIME, (U64TYPE)SvUV(t)); |
3 |
0 |
3 |
|
| 130 |
3 |
▶ | if (name) { STRLEN l; const char *s = SvPV_const(name, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (name) { STRLEN l; const char *s = SvPV_const(name, l); |
3 |
0 |
3 |
|
| 131 |
3 |
| otel_pb_bytes(b, PB_EVENT_NAME, s, l); } |
| 132 |
3 |
| otel_attrs_write(aTHX_ b, otel_h_hv(aTHX_ ev, "attributes"), |
| 133 |
|
| PB_EVENT_ATTRIBUTES); |
| 134 |
3 |
▶ | if (dropped && SvUV(dropped)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (dropped && SvUV(dropped)) |
0 |
3 |
3 |
| if (dropped && SvUV(dropped)) |
0 |
0 |
0 |
|
| 135 |
0 |
| otel_pb_uint64(b, PB_EVENT_DROPPED_ATTRS, SvUV(dropped)); |
| 136 |
|
| } |
| 137 |
|
| |
| 138 |
|
| /* ---- Link --------------------------------------------------------------- */ |
| 139 |
|
| |
| 140 |
0 |
| static size_t otel_link_size(pTHX_ HV *ln) { |
| 141 |
0 |
| size_t n = 0; |
| 142 |
|
| char t16[16], s8[8]; |
| 143 |
|
| STRLEN tl, sl; |
| 144 |
|
| SV *ts; |
| 145 |
0 |
▶ | if (!ln) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ln) return 0; |
0 |
0 |
0 |
|
| 146 |
0 |
▶ | if (otel_id(aTHX_ ln, "trace_id", 16, &tl, t16)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_id(aTHX_ ln, "trace_id", 16, &tl, t16)) |
0 |
0 |
0 |
|
| 147 |
0 |
| n += otel_pb_bytes_size(PB_LINK_TRACE_ID, tl); |
| 148 |
0 |
▶ | if (otel_id(aTHX_ ln, "span_id", 8, &sl, s8)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_id(aTHX_ ln, "span_id", 8, &sl, s8)) |
0 |
0 |
0 |
|
| 149 |
0 |
| n += otel_pb_bytes_size(PB_LINK_SPAN_ID, sl); |
| 150 |
0 |
| ts = otel_h(aTHX_ ln, "trace_state"); |
| 151 |
0 |
▶ | if (ts) { STRLEN l; (void)SvPV_const(ts, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ts) { STRLEN l; (void)SvPV_const(ts, l); |
0 |
0 |
0 |
|
| 152 |
0 |
| n += otel_pb_bytes_size(PB_LINK_TRACE_STATE, l); } |
| 153 |
0 |
| n += otel_attrs_size(aTHX_ otel_h_hv(aTHX_ ln, "attributes"), |
| 154 |
|
| PB_LINK_ATTRIBUTES); |
| 155 |
0 |
| return n; |
| 156 |
|
| } |
| 157 |
|
| |
| 158 |
0 |
| static void otel_link_write(pTHX_ otel_buf *b, HV *ln) { |
| 159 |
|
| char t16[16], s8[8]; |
| 160 |
|
| STRLEN tl, sl; |
| 161 |
|
| const char *tid, *sid; |
| 162 |
|
| SV *ts; |
| 163 |
0 |
▶ | if (!ln) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ln) return; |
0 |
0 |
0 |
|
| 164 |
0 |
| tid = otel_id(aTHX_ ln, "trace_id", 16, &tl, t16); |
| 165 |
0 |
▶ | if (tid) otel_pb_bytes(b, PB_LINK_TRACE_ID, tid, tl); |
Branch: 1 branch
| Branch | True | False | Total |
| if (tid) otel_pb_bytes(b, PB_LINK_TRACE_ID, tid, tl); |
0 |
0 |
0 |
|
| 166 |
0 |
| sid = otel_id(aTHX_ ln, "span_id", 8, &sl, s8); |
| 167 |
0 |
▶ | if (sid) otel_pb_bytes(b, PB_LINK_SPAN_ID, sid, sl); |
Branch: 1 branch
| Branch | True | False | Total |
| if (sid) otel_pb_bytes(b, PB_LINK_SPAN_ID, sid, sl); |
0 |
0 |
0 |
|
| 168 |
0 |
| ts = otel_h(aTHX_ ln, "trace_state"); |
| 169 |
0 |
▶ | if (ts) { STRLEN l; const char *s = SvPV_const(ts, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ts) { STRLEN l; const char *s = SvPV_const(ts, l); |
0 |
0 |
0 |
|
| 170 |
0 |
| otel_pb_bytes(b, PB_LINK_TRACE_STATE, s, l); } |
| 171 |
0 |
| otel_attrs_write(aTHX_ b, otel_h_hv(aTHX_ ln, "attributes"), |
| 172 |
|
| PB_LINK_ATTRIBUTES); |
| 173 |
|
| } |
| 174 |
|
| |
| 175 |
|
| /* ---- Span --------------------------------------------------------------- */ |
| 176 |
|
| |
| 177 |
81 |
| static size_t otel_span_size(pTHX_ HV *sp) { |
| 178 |
81 |
| size_t n = 0; |
| 179 |
|
| char t16[16], s8[8], p8[8]; |
| 180 |
|
| STRLEN tl, sl, pl; |
| 181 |
|
| SV *v; |
| 182 |
|
| AV *av; |
| 183 |
|
| SSize_t i, cnt; |
| 184 |
81 |
▶ | if (!sp) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sp) return 0; |
0 |
81 |
81 |
|
| 185 |
|
| |
| 186 |
81 |
▶ | if (otel_id(aTHX_ sp, "trace_id", 16, &tl, t16)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_id(aTHX_ sp, "trace_id", 16, &tl, t16)) |
65 |
16 |
81 |
|
| 187 |
65 |
| n += otel_pb_bytes_size(PB_SPAN_TRACE_ID, tl); |
| 188 |
81 |
▶ | if (otel_id(aTHX_ sp, "span_id", 8, &sl, s8)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_id(aTHX_ sp, "span_id", 8, &sl, s8)) |
69 |
12 |
81 |
|
| 189 |
69 |
| n += otel_pb_bytes_size(PB_SPAN_SPAN_ID, sl); |
| 190 |
81 |
▶ | if ((v = otel_h(aTHX_ sp, "trace_state"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "trace_state"))) { |
0 |
81 |
81 |
|
| 191 |
|
| STRLEN l; (void)SvPV_const(v, l); |
| 192 |
0 |
| n += otel_pb_bytes_size(PB_SPAN_TRACE_STATE, l); |
| 193 |
|
| } |
| 194 |
81 |
▶ | if (otel_id(aTHX_ sp, "parent_span_id", 8, &pl, p8)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_id(aTHX_ sp, "parent_span_id", 8, &pl, p8)) |
0 |
81 |
81 |
|
| 195 |
0 |
| n += otel_pb_bytes_size(PB_SPAN_PARENT_SPAN_ID, pl); |
| 196 |
81 |
▶ | if ((v = otel_h(aTHX_ sp, "name"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "name"))) { |
81 |
0 |
81 |
|
| 197 |
|
| STRLEN l; (void)SvPV_const(v, l); |
| 198 |
81 |
| n += otel_pb_bytes_size(PB_SPAN_NAME, l); |
| 199 |
|
| } |
| 200 |
81 |
▶ | if ((v = otel_h(aTHX_ sp, "kind")) && SvIV(v) != OTEL_KIND_UNSPECIFIED) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "kind")) && SvIV(v) != OTEL_KIND_UNSPECIFIED) |
49 |
32 |
81 |
| if ((v = otel_h(aTHX_ sp, "kind")) && SvIV(v) != OTEL_KIND_UNSPECIFIED) |
45 |
4 |
49 |
|
| 201 |
45 |
| n += otel_pb_int32_size(PB_SPAN_KIND, (int)SvIV(v)); |
| 202 |
81 |
▶ | if (otel_h(aTHX_ sp, "start_time_unix_nano")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_h(aTHX_ sp, "start_time_unix_nano")) |
45 |
36 |
81 |
|
| 203 |
45 |
| n += otel_pb_fixed64_size(PB_SPAN_START_TIME); |
| 204 |
81 |
▶ | if (otel_h(aTHX_ sp, "end_time_unix_nano")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_h(aTHX_ sp, "end_time_unix_nano")) |
45 |
36 |
81 |
|
| 205 |
45 |
| n += otel_pb_fixed64_size(PB_SPAN_END_TIME); |
| 206 |
|
| |
| 207 |
81 |
| n += otel_attrs_size(aTHX_ otel_h_hv(aTHX_ sp, "attributes"), |
| 208 |
|
| PB_SPAN_ATTRIBUTES); |
| 209 |
81 |
▶ | if ((v = otel_h(aTHX_ sp, "dropped_attributes_count")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "dropped_attributes_count")) && SvUV(v)) |
0 |
81 |
81 |
| if ((v = otel_h(aTHX_ sp, "dropped_attributes_count")) && SvUV(v)) |
0 |
0 |
0 |
|
| 210 |
0 |
| n += otel_pb_uint64_size(PB_SPAN_DROPPED_ATTRS, SvUV(v)); |
| 211 |
|
| |
| 212 |
81 |
▶ | if ((av = otel_h_av(aTHX_ sp, "events"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((av = otel_h_av(aTHX_ sp, "events"))) { |
13 |
68 |
81 |
|
| 213 |
13 |
| cnt = av_len(av) + 1; |
| 214 |
26 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
13 |
13 |
26 |
|
| 215 |
13 |
| SV **e = av_fetch(av, i, 0); |
| 216 |
13 |
▶ | n += otel_pb_msg_size(PB_SPAN_EVENTS, |
Branch: 1 branch
| Branch | True | False | Total |
| n += otel_pb_msg_size(PB_SPAN_EVENTS, |
13 |
0 |
13 |
|
| 217 |
|
| otel_event_size(aTHX_ otel_hv_of(aTHX_ (e ? *e : NULL)))); |
| 218 |
|
| } |
| 219 |
|
| } |
| 220 |
81 |
▶ | if ((v = otel_h(aTHX_ sp, "dropped_events_count")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "dropped_events_count")) && SvUV(v)) |
0 |
81 |
81 |
| if ((v = otel_h(aTHX_ sp, "dropped_events_count")) && SvUV(v)) |
0 |
0 |
0 |
|
| 221 |
0 |
| n += otel_pb_uint64_size(PB_SPAN_DROPPED_EVENTS, SvUV(v)); |
| 222 |
|
| |
| 223 |
81 |
▶ | if ((av = otel_h_av(aTHX_ sp, "links"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((av = otel_h_av(aTHX_ sp, "links"))) { |
0 |
81 |
81 |
|
| 224 |
0 |
| cnt = av_len(av) + 1; |
| 225 |
0 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
0 |
0 |
0 |
|
| 226 |
0 |
| SV **e = av_fetch(av, i, 0); |
| 227 |
0 |
▶ | n += otel_pb_msg_size(PB_SPAN_LINKS, |
Branch: 1 branch
| Branch | True | False | Total |
| n += otel_pb_msg_size(PB_SPAN_LINKS, |
0 |
0 |
0 |
|
| 228 |
|
| otel_link_size(aTHX_ otel_hv_of(aTHX_ (e ? *e : NULL)))); |
| 229 |
|
| } |
| 230 |
|
| } |
| 231 |
81 |
▶ | if ((v = otel_h(aTHX_ sp, "dropped_links_count")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "dropped_links_count")) && SvUV(v)) |
0 |
81 |
81 |
| if ((v = otel_h(aTHX_ sp, "dropped_links_count")) && SvUV(v)) |
0 |
0 |
0 |
|
| 232 |
0 |
| n += otel_pb_uint64_size(PB_SPAN_DROPPED_LINKS, SvUV(v)); |
| 233 |
|
| |
| 234 |
|
| { |
| 235 |
81 |
| HV *st = otel_h_hv(aTHX_ sp, "status"); |
| 236 |
81 |
| size_t ssz = otel_status_size(aTHX_ st); |
| 237 |
81 |
▶ | if (st && ssz) n += otel_pb_msg_size(PB_SPAN_STATUS, ssz); |
Branch: 2 branches
| Branch | True | False | Total |
| if (st && ssz) n += otel_pb_msg_size(PB_SPAN_STATUS, ssz); |
25 |
56 |
81 |
| if (st && ssz) n += otel_pb_msg_size(PB_SPAN_STATUS, ssz); |
21 |
4 |
25 |
|
| 238 |
|
| } |
| 239 |
81 |
▶ | if ((v = otel_h(aTHX_ sp, "flags")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "flags")) && SvUV(v)) |
32 |
49 |
81 |
| if ((v = otel_h(aTHX_ sp, "flags")) && SvUV(v)) |
32 |
0 |
32 |
|
| 240 |
32 |
| n += otel_pb_uint64_size(PB_SPAN_FLAGS, SvUV(v)); |
| 241 |
81 |
| return n; |
| 242 |
|
| } |
| 243 |
|
| |
| 244 |
19 |
| static void otel_span_write(pTHX_ otel_buf *b, HV *sp) { |
| 245 |
|
| char t16[16], s8[8], p8[8]; |
| 246 |
|
| STRLEN tl, sl, pl; |
| 247 |
|
| const char *id; |
| 248 |
|
| SV *v; |
| 249 |
|
| AV *av; |
| 250 |
|
| SSize_t i, cnt; |
| 251 |
19 |
▶ | if (!sp) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sp) return; |
0 |
19 |
19 |
|
| 252 |
|
| |
| 253 |
19 |
▶ | if ((id = otel_id(aTHX_ sp, "trace_id", 16, &tl, t16))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((id = otel_id(aTHX_ sp, "trace_id", 16, &tl, t16))) |
15 |
4 |
19 |
|
| 254 |
15 |
| otel_pb_bytes(b, PB_SPAN_TRACE_ID, id, tl); |
| 255 |
19 |
▶ | if ((id = otel_id(aTHX_ sp, "span_id", 8, &sl, s8))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((id = otel_id(aTHX_ sp, "span_id", 8, &sl, s8))) |
16 |
3 |
19 |
|
| 256 |
16 |
| otel_pb_bytes(b, PB_SPAN_SPAN_ID, id, sl); |
| 257 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "trace_state"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "trace_state"))) { |
0 |
19 |
19 |
|
| 258 |
0 |
| STRLEN l; const char *s = SvPV_const(v, l); |
| 259 |
0 |
| otel_pb_bytes(b, PB_SPAN_TRACE_STATE, s, l); |
| 260 |
|
| } |
| 261 |
19 |
▶ | if ((id = otel_id(aTHX_ sp, "parent_span_id", 8, &pl, p8))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((id = otel_id(aTHX_ sp, "parent_span_id", 8, &pl, p8))) |
0 |
19 |
19 |
|
| 262 |
0 |
| otel_pb_bytes(b, PB_SPAN_PARENT_SPAN_ID, id, pl); |
| 263 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "name"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "name"))) { |
19 |
0 |
19 |
|
| 264 |
19 |
| STRLEN l; const char *s = SvPV_const(v, l); |
| 265 |
19 |
| otel_pb_bytes(b, PB_SPAN_NAME, s, l); |
| 266 |
|
| } |
| 267 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "kind")) && SvIV(v) != OTEL_KIND_UNSPECIFIED) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "kind")) && SvIV(v) != OTEL_KIND_UNSPECIFIED) |
11 |
8 |
19 |
| if ((v = otel_h(aTHX_ sp, "kind")) && SvIV(v) != OTEL_KIND_UNSPECIFIED) |
10 |
1 |
11 |
|
| 268 |
10 |
| otel_pb_int32(b, PB_SPAN_KIND, (int)SvIV(v)); |
| 269 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "start_time_unix_nano"))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "start_time_unix_nano"))) |
10 |
9 |
19 |
|
| 270 |
10 |
| otel_pb_fixed64(b, PB_SPAN_START_TIME, (U64TYPE)SvUV(v)); |
| 271 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "end_time_unix_nano"))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "end_time_unix_nano"))) |
10 |
9 |
19 |
|
| 272 |
10 |
| otel_pb_fixed64(b, PB_SPAN_END_TIME, (U64TYPE)SvUV(v)); |
| 273 |
|
| |
| 274 |
19 |
| otel_attrs_write(aTHX_ b, otel_h_hv(aTHX_ sp, "attributes"), |
| 275 |
|
| PB_SPAN_ATTRIBUTES); |
| 276 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "dropped_attributes_count")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "dropped_attributes_count")) && SvUV(v)) |
0 |
19 |
19 |
| if ((v = otel_h(aTHX_ sp, "dropped_attributes_count")) && SvUV(v)) |
0 |
0 |
0 |
|
| 277 |
0 |
| otel_pb_uint64(b, PB_SPAN_DROPPED_ATTRS, SvUV(v)); |
| 278 |
|
| |
| 279 |
19 |
▶ | if ((av = otel_h_av(aTHX_ sp, "events"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((av = otel_h_av(aTHX_ sp, "events"))) { |
3 |
16 |
19 |
|
| 280 |
3 |
| cnt = av_len(av) + 1; |
| 281 |
6 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
3 |
3 |
6 |
|
| 282 |
3 |
| SV **e = av_fetch(av, i, 0); |
| 283 |
3 |
▶ | HV *ev = otel_hv_of(aTHX_ (e ? *e : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| HV *ev = otel_hv_of(aTHX_ (e ? *e : NULL)); |
3 |
0 |
3 |
|
| 284 |
3 |
| size_t esz = otel_event_size(aTHX_ ev); |
| 285 |
|
| size_t mark; |
| 286 |
3 |
| otel_pb_msg_head(b, PB_SPAN_EVENTS, esz); |
| 287 |
3 |
| mark = b->len; |
| 288 |
3 |
| otel_event_write(aTHX_ b, ev); |
| 289 |
|
| OTEL_PB_CHECK(b, mark, esz, "Span.Event"); |
| 290 |
|
| } |
| 291 |
|
| } |
| 292 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "dropped_events_count")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "dropped_events_count")) && SvUV(v)) |
0 |
19 |
19 |
| if ((v = otel_h(aTHX_ sp, "dropped_events_count")) && SvUV(v)) |
0 |
0 |
0 |
|
| 293 |
0 |
| otel_pb_uint64(b, PB_SPAN_DROPPED_EVENTS, SvUV(v)); |
| 294 |
|
| |
| 295 |
19 |
▶ | if ((av = otel_h_av(aTHX_ sp, "links"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((av = otel_h_av(aTHX_ sp, "links"))) { |
0 |
19 |
19 |
|
| 296 |
0 |
| cnt = av_len(av) + 1; |
| 297 |
0 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
0 |
0 |
0 |
|
| 298 |
0 |
| SV **e = av_fetch(av, i, 0); |
| 299 |
0 |
▶ | HV *ln = otel_hv_of(aTHX_ (e ? *e : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| HV *ln = otel_hv_of(aTHX_ (e ? *e : NULL)); |
0 |
0 |
0 |
|
| 300 |
0 |
| size_t lsz = otel_link_size(aTHX_ ln); |
| 301 |
|
| size_t mark; |
| 302 |
0 |
| otel_pb_msg_head(b, PB_SPAN_LINKS, lsz); |
| 303 |
0 |
| mark = b->len; |
| 304 |
0 |
| otel_link_write(aTHX_ b, ln); |
| 305 |
|
| OTEL_PB_CHECK(b, mark, lsz, "Span.Link"); |
| 306 |
|
| } |
| 307 |
|
| } |
| 308 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "dropped_links_count")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "dropped_links_count")) && SvUV(v)) |
0 |
19 |
19 |
| if ((v = otel_h(aTHX_ sp, "dropped_links_count")) && SvUV(v)) |
0 |
0 |
0 |
|
| 309 |
0 |
| otel_pb_uint64(b, PB_SPAN_DROPPED_LINKS, SvUV(v)); |
| 310 |
|
| |
| 311 |
|
| { |
| 312 |
19 |
| HV *st = otel_h_hv(aTHX_ sp, "status"); |
| 313 |
19 |
| size_t ssz = otel_status_size(aTHX_ st); |
| 314 |
19 |
▶ | if (st && ssz) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (st && ssz) { |
6 |
13 |
19 |
| if (st && ssz) { |
5 |
1 |
6 |
|
| 315 |
|
| size_t mark; |
| 316 |
5 |
| otel_pb_msg_head(b, PB_SPAN_STATUS, ssz); |
| 317 |
5 |
| mark = b->len; |
| 318 |
5 |
| otel_status_write(aTHX_ b, st); |
| 319 |
|
| OTEL_PB_CHECK(b, mark, ssz, "Span.Status"); |
| 320 |
|
| } |
| 321 |
|
| } |
| 322 |
19 |
▶ | if ((v = otel_h(aTHX_ sp, "flags")) && SvUV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sp, "flags")) && SvUV(v)) |
7 |
12 |
19 |
| if ((v = otel_h(aTHX_ sp, "flags")) && SvUV(v)) |
7 |
0 |
7 |
|
| 323 |
7 |
| otel_pb_uint64(b, PB_SPAN_FLAGS, SvUV(v)); |
| 324 |
|
| } |
| 325 |
|
| |
| 326 |
|
| /* ---- InstrumentationScope ----------------------------------------------- */ |
| 327 |
|
| |
| 328 |
106 |
| static size_t otel_scope_size(pTHX_ HV *sc) { |
| 329 |
106 |
| size_t n = 0; |
| 330 |
|
| SV *v; |
| 331 |
106 |
▶ | if (!sc) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sc) return 0; |
0 |
106 |
106 |
|
| 332 |
106 |
▶ | if ((v = otel_h(aTHX_ sc, "name"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sc, "name"))) { |
66 |
40 |
106 |
|
| 333 |
|
| STRLEN l; (void)SvPV_const(v, l); |
| 334 |
66 |
| n += otel_pb_bytes_size(PB_SCOPE_NAME, l); |
| 335 |
|
| } |
| 336 |
106 |
▶ | if ((v = otel_h(aTHX_ sc, "version"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sc, "version"))) { |
26 |
80 |
106 |
|
| 337 |
|
| STRLEN l; (void)SvPV_const(v, l); |
| 338 |
26 |
| n += otel_pb_bytes_size(PB_SCOPE_VERSION, l); |
| 339 |
|
| } |
| 340 |
106 |
| n += otel_attrs_size(aTHX_ otel_h_hv(aTHX_ sc, "attributes"), |
| 341 |
|
| PB_SCOPE_ATTRIBUTES); |
| 342 |
106 |
| return n; |
| 343 |
|
| } |
| 344 |
|
| |
| 345 |
26 |
| static void otel_scope_write(pTHX_ otel_buf *b, HV *sc) { |
| 346 |
|
| SV *v; |
| 347 |
26 |
▶ | if (!sc) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sc) return; |
0 |
26 |
26 |
|
| 348 |
26 |
▶ | if ((v = otel_h(aTHX_ sc, "name"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sc, "name"))) { |
16 |
10 |
26 |
|
| 349 |
16 |
| STRLEN l; const char *s = SvPV_const(v, l); |
| 350 |
16 |
| otel_pb_bytes(b, PB_SCOPE_NAME, s, l); |
| 351 |
|
| } |
| 352 |
26 |
▶ | if ((v = otel_h(aTHX_ sc, "version"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = otel_h(aTHX_ sc, "version"))) { |
6 |
20 |
26 |
|
| 353 |
6 |
| STRLEN l; const char *s = SvPV_const(v, l); |
| 354 |
6 |
| otel_pb_bytes(b, PB_SCOPE_VERSION, s, l); |
| 355 |
|
| } |
| 356 |
26 |
| otel_attrs_write(aTHX_ b, otel_h_hv(aTHX_ sc, "attributes"), |
| 357 |
|
| PB_SCOPE_ATTRIBUTES); |
| 358 |
|
| } |
| 359 |
|
| |
| 360 |
|
| /* ---- ScopeSpans / Resource / ResourceSpans ------------------------------ */ |
| 361 |
|
| |
| 362 |
50 |
| static size_t otel_scopespans_size(pTHX_ HV *ss) { |
| 363 |
50 |
| size_t n = 0; |
| 364 |
50 |
| HV *sc = otel_h_hv(aTHX_ ss, "scope"); |
| 365 |
50 |
| AV *spans = otel_h_av(aTHX_ ss, "spans"); |
| 366 |
50 |
| SV *url = otel_h(aTHX_ ss, "schema_url"); |
| 367 |
|
| SSize_t i, cnt; |
| 368 |
50 |
▶ | if (sc) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sc) { |
23 |
27 |
50 |
|
| 369 |
23 |
| size_t s = otel_scope_size(aTHX_ sc); |
| 370 |
23 |
| n += otel_pb_msg_size(PB_SCOPESPANS_SCOPE, s); |
| 371 |
|
| } |
| 372 |
50 |
▶ | if (spans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (spans) { |
50 |
0 |
50 |
|
| 373 |
50 |
| cnt = av_len(spans) + 1; |
| 374 |
112 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
62 |
50 |
112 |
|
| 375 |
62 |
| SV **e = av_fetch(spans, i, 0); |
| 376 |
62 |
▶ | n += otel_pb_msg_size(PB_SCOPESPANS_SPANS, |
Branch: 1 branch
| Branch | True | False | Total |
| n += otel_pb_msg_size(PB_SCOPESPANS_SPANS, |
62 |
0 |
62 |
|
| 377 |
|
| otel_span_size(aTHX_ otel_hv_of(aTHX_ (e ? *e : NULL)))); |
| 378 |
|
| } |
| 379 |
|
| } |
| 380 |
50 |
▶ | if (url) { STRLEN l; (void)SvPV_const(url, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (url) { STRLEN l; (void)SvPV_const(url, l); |
9 |
41 |
50 |
|
| 381 |
9 |
| n += otel_pb_bytes_size(PB_SCOPESPANS_SCHEMA_URL, l); } |
| 382 |
50 |
| return n; |
| 383 |
|
| } |
| 384 |
|
| |
| 385 |
16 |
| static void otel_scopespans_write(pTHX_ otel_buf *b, HV *ss) { |
| 386 |
16 |
| HV *sc = otel_h_hv(aTHX_ ss, "scope"); |
| 387 |
16 |
| AV *spans = otel_h_av(aTHX_ ss, "spans"); |
| 388 |
16 |
| SV *url = otel_h(aTHX_ ss, "schema_url"); |
| 389 |
|
| SSize_t i, cnt; |
| 390 |
16 |
▶ | if (sc) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sc) { |
7 |
9 |
16 |
|
| 391 |
7 |
| size_t s = otel_scope_size(aTHX_ sc), mark; |
| 392 |
7 |
| otel_pb_msg_head(b, PB_SCOPESPANS_SCOPE, s); |
| 393 |
7 |
| mark = b->len; |
| 394 |
7 |
| otel_scope_write(aTHX_ b, sc); |
| 395 |
|
| OTEL_PB_CHECK(b, mark, s, "InstrumentationScope"); |
| 396 |
|
| } |
| 397 |
16 |
▶ | if (spans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (spans) { |
16 |
0 |
16 |
|
| 398 |
16 |
| cnt = av_len(spans) + 1; |
| 399 |
35 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
19 |
16 |
35 |
|
| 400 |
19 |
| SV **e = av_fetch(spans, i, 0); |
| 401 |
19 |
▶ | HV *sp = otel_hv_of(aTHX_ (e ? *e : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| HV *sp = otel_hv_of(aTHX_ (e ? *e : NULL)); |
19 |
0 |
19 |
|
| 402 |
19 |
| size_t ssz = otel_span_size(aTHX_ sp), mark; |
| 403 |
19 |
| otel_pb_msg_head(b, PB_SCOPESPANS_SPANS, ssz); |
| 404 |
19 |
| mark = b->len; |
| 405 |
19 |
| otel_span_write(aTHX_ b, sp); |
| 406 |
|
| OTEL_PB_CHECK(b, mark, ssz, "Span"); |
| 407 |
|
| } |
| 408 |
|
| } |
| 409 |
16 |
▶ | if (url) { STRLEN l; const char *s = SvPV_const(url, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (url) { STRLEN l; const char *s = SvPV_const(url, l); |
3 |
13 |
16 |
|
| 410 |
3 |
| otel_pb_bytes(b, PB_SCOPESPANS_SCHEMA_URL, s, l); } |
| 411 |
16 |
| } |
| 412 |
|
| |
| 413 |
80 |
| static size_t otel_resource_size(pTHX_ HV *res) { |
| 414 |
80 |
▶ | if (!res) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!res) return 0; |
0 |
80 |
80 |
|
| 415 |
80 |
| return otel_attrs_size(aTHX_ otel_h_hv(aTHX_ res, "attributes"), |
| 416 |
|
| PB_RESOURCE_ATTRIBUTES); |
| 417 |
|
| } |
| 418 |
26 |
| static void otel_resource_write(pTHX_ otel_buf *b, HV *res) { |
| 419 |
26 |
▶ | if (!res) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!res) return; |
0 |
26 |
26 |
|
| 420 |
26 |
| otel_attrs_write(aTHX_ b, otel_h_hv(aTHX_ res, "attributes"), |
| 421 |
|
| PB_RESOURCE_ATTRIBUTES); |
| 422 |
|
| } |
| 423 |
|
| |
| 424 |
34 |
| static size_t otel_resourcespans_size(pTHX_ HV *rs) { |
| 425 |
34 |
| size_t n = 0; |
| 426 |
34 |
| HV *res = otel_h_hv(aTHX_ rs, "resource"); |
| 427 |
34 |
| AV *sss = otel_h_av(aTHX_ rs, "scope_spans"); |
| 428 |
34 |
| SV *url = otel_h(aTHX_ rs, "schema_url"); |
| 429 |
|
| SSize_t i, cnt; |
| 430 |
34 |
▶ | if (res) |
Branch: 1 branch
| Branch | True | False | Total |
| if (res) |
16 |
18 |
34 |
|
| 431 |
16 |
| n += otel_pb_msg_size(PB_RESOURCESPANS_RESOURCE, |
| 432 |
|
| otel_resource_size(aTHX_ res)); |
| 433 |
34 |
▶ | if (sss) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sss) { |
34 |
0 |
34 |
|
| 434 |
34 |
| cnt = av_len(sss) + 1; |
| 435 |
68 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
34 |
34 |
68 |
|
| 436 |
34 |
| SV **e = av_fetch(sss, i, 0); |
| 437 |
34 |
▶ | n += otel_pb_msg_size(PB_RESOURCESPANS_SCOPE_SPANS, |
Branch: 1 branch
| Branch | True | False | Total |
| n += otel_pb_msg_size(PB_RESOURCESPANS_SCOPE_SPANS, |
34 |
0 |
34 |
|
| 438 |
|
| otel_scopespans_size(aTHX_ otel_hv_of(aTHX_ (e ? *e : NULL)))); |
| 439 |
|
| } |
| 440 |
|
| } |
| 441 |
34 |
▶ | if (url) { STRLEN l; (void)SvPV_const(url, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (url) { STRLEN l; (void)SvPV_const(url, l); |
17 |
17 |
34 |
|
| 442 |
17 |
| n += otel_pb_bytes_size(PB_RESOURCESPANS_SCHEMA_URL, l); } |
| 443 |
34 |
| return n; |
| 444 |
|
| } |
| 445 |
|
| |
| 446 |
16 |
| static void otel_resourcespans_write(pTHX_ otel_buf *b, HV *rs) { |
| 447 |
16 |
| HV *res = otel_h_hv(aTHX_ rs, "resource"); |
| 448 |
16 |
| AV *sss = otel_h_av(aTHX_ rs, "scope_spans"); |
| 449 |
16 |
| SV *url = otel_h(aTHX_ rs, "schema_url"); |
| 450 |
|
| SSize_t i, cnt; |
| 451 |
16 |
▶ | if (res) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res) { |
7 |
9 |
16 |
|
| 452 |
7 |
| size_t s = otel_resource_size(aTHX_ res), mark; |
| 453 |
7 |
| otel_pb_msg_head(b, PB_RESOURCESPANS_RESOURCE, s); |
| 454 |
7 |
| mark = b->len; |
| 455 |
7 |
| otel_resource_write(aTHX_ b, res); |
| 456 |
|
| OTEL_PB_CHECK(b, mark, s, "Resource"); |
| 457 |
|
| } |
| 458 |
16 |
▶ | if (sss) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sss) { |
16 |
0 |
16 |
|
| 459 |
16 |
| cnt = av_len(sss) + 1; |
| 460 |
32 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
16 |
16 |
32 |
|
| 461 |
16 |
| SV **e = av_fetch(sss, i, 0); |
| 462 |
16 |
▶ | HV *ss = otel_hv_of(aTHX_ (e ? *e : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| HV *ss = otel_hv_of(aTHX_ (e ? *e : NULL)); |
16 |
0 |
16 |
|
| 463 |
16 |
| size_t s = otel_scopespans_size(aTHX_ ss), mark; |
| 464 |
16 |
| otel_pb_msg_head(b, PB_RESOURCESPANS_SCOPE_SPANS, s); |
| 465 |
16 |
| mark = b->len; |
| 466 |
16 |
| otel_scopespans_write(aTHX_ b, ss); |
| 467 |
|
| OTEL_PB_CHECK(b, mark, s, "ScopeSpans"); |
| 468 |
|
| } |
| 469 |
|
| } |
| 470 |
16 |
▶ | if (url) { STRLEN l; const char *s = SvPV_const(url, l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (url) { STRLEN l; const char *s = SvPV_const(url, l); |
8 |
8 |
16 |
|
| 471 |
8 |
| otel_pb_bytes(b, PB_RESOURCESPANS_SCHEMA_URL, s, l); } |
| 472 |
16 |
| } |
| 473 |
|
| |
| 474 |
|
| /* ---- ExportTraceServiceRequest ------------------------------------------ * |
| 475 |
|
| * The top of the tree. Takes { resource_spans => [ ... ] } and returns the |
| 476 |
|
| * bytes as a new SV (+1 owned). */ |
| 477 |
15 |
| static SV *otel_encode_traces(pTHX_ HV *payload) { |
| 478 |
|
| otel_buf b; |
| 479 |
15 |
| AV *rss = otel_h_av(aTHX_ payload, "resource_spans"); |
| 480 |
15 |
▶ | SSize_t i, cnt = rss ? av_len(rss) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t i, cnt = rss ? av_len(rss) + 1 : 0; |
15 |
0 |
15 |
|
| 481 |
15 |
| size_t total = 0; |
| 482 |
|
| SV *out; |
| 483 |
|
| |
| 484 |
31 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
16 |
15 |
31 |
|
| 485 |
16 |
| SV **e = av_fetch(rss, i, 0); |
| 486 |
16 |
▶ | total += otel_pb_msg_size(PB_EXPORT_TRACE_RESOURCE_SPANS, |
Branch: 1 branch
| Branch | True | False | Total |
| total += otel_pb_msg_size(PB_EXPORT_TRACE_RESOURCE_SPANS, |
16 |
0 |
16 |
|
| 487 |
|
| otel_resourcespans_size(aTHX_ otel_hv_of(aTHX_ (e ? *e : NULL)))); |
| 488 |
|
| } |
| 489 |
15 |
▶ | otel_buf_init(&b, total ? total : 64); |
Branch: 1 branch
| Branch | True | False | Total |
| otel_buf_init(&b, total ? total : 64); |
15 |
0 |
15 |
|
| 490 |
31 |
▶ | for (i = 0; i < cnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { |
16 |
15 |
31 |
|
| 491 |
16 |
| SV **e = av_fetch(rss, i, 0); |
| 492 |
16 |
▶ | HV *rs = otel_hv_of(aTHX_ (e ? *e : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| HV *rs = otel_hv_of(aTHX_ (e ? *e : NULL)); |
16 |
0 |
16 |
|
| 493 |
16 |
| size_t s = otel_resourcespans_size(aTHX_ rs), mark; |
| 494 |
16 |
| otel_pb_msg_head(&b, PB_EXPORT_TRACE_RESOURCE_SPANS, s); |
| 495 |
16 |
| mark = b.len; |
| 496 |
16 |
| otel_resourcespans_write(aTHX_ &b, rs); |
| 497 |
|
| OTEL_PB_CHECK(&b, mark, s, "ResourceSpans"); |
| 498 |
|
| } |
| 499 |
15 |
| out = newSVpvn(b.buf, b.len); |
| 500 |
15 |
| otel_buf_free(&b); |
| 501 |
15 |
| return out; |
| 502 |
|
| } |
| 503 |
|
| |
| 504 |
|
| #endif /* OTEL_TRACE_H */ |