@0xchain/telemetry 1.1.0-beta.17 → 1.1.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"Sampler.d.ts","sourceRoot":"","sources":["../src/Sampler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIP,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAY,UAAU,EAAoC,MAAM,oBAAoB,CAAC;AAC5F,OAAO,KAAK,EAAgB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG5E,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAoCD,iCAAiC;AACjC,eAAO,MAAM,kCAAkC,GAAI,YAAY,UAAU,KAAG,eA4B3E,CAAC;AAcF,iBAAiB;AACjB,eAAO,MAAM,iBAAiB,GAAI,MAAM,YAAY,EAAE,SAAS,eAAe,YAiC7E,CAAC;AAKF,iBAAiB;AACjB,eAAO,MAAM,oBAAoB,GAC/B,OAAO,YAAY,EAAE,GAAG,SAAS,EACjC,SAAS,eAAe,EACxB,cAAc,MAAM,WASrB,CAAC;AAoBF,iBAAiB;AACjB,eAAO,MAAM,sBAAsB,GAAI,SAAS,gBAAgB,KAAG,OAsClE,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,4BAA4B,GAAI,UAAU,YAAY,KAAG,YAAwB,CAAC;AAE/F,eAAe,sBAAsB,CAAC"}
1
+ {"version":3,"file":"Sampler.d.ts","sourceRoot":"","sources":["../src/Sampler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIP,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAY,UAAU,EAAoC,MAAM,oBAAoB,CAAC;AAC5F,OAAO,KAAK,EAAgB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG5E,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAoCD,iCAAiC;AACjC,eAAO,MAAM,kCAAkC,GAAI,YAAY,UAAU,KAAG,eA4B3E,CAAC;AAcF,iBAAiB;AACjB,eAAO,MAAM,iBAAiB,GAAI,MAAM,YAAY,EAAE,SAAS,eAAe,YAiC7E,CAAC;AAKF,iBAAiB;AACjB,eAAO,MAAM,oBAAoB,GAC/B,OAAO,YAAY,EAAE,GAAG,SAAS,EACjC,SAAS,eAAe,EACxB,cAAc,MAAM,WASrB,CAAC;AAgCF,iBAAiB;AACjB,eAAO,MAAM,sBAAsB,GAAI,SAAS,gBAAgB,KAAG,OA6ClE,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,4BAA4B,GAAI,UAAU,YAAY,KAAG,YAAwB,CAAC;AAE/F,eAAe,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { NodeSDK as F } from "@opentelemetry/sdk-node";
2
- import { OTLPTraceExporter as Y } from "@opentelemetry/exporter-trace-otlp-http";
3
- import { resourceFromAttributes as U } from "@opentelemetry/resources";
4
- import { ATTR_SERVICE_VERSION as G, ATTR_SERVICE_NAME as q } from "@opentelemetry/semantic-conventions";
5
- import { SamplingDecision as d, TraceIdRatioBasedSampler as L, AlwaysOnSampler as B, BatchSpanProcessor as k } from "@opentelemetry/sdk-trace-base";
6
- import { trace as z, TraceFlags as M, propagation as V, context as x, SpanStatusCode as $ } from "@opentelemetry/api";
7
- import { readFile as j } from "node:fs/promises";
8
- import { HttpInstrumentation as Q } from "@opentelemetry/instrumentation-http";
9
- import { UndiciInstrumentation as X } from "@opentelemetry/instrumentation-undici";
10
- import { c as W, m as J, a as K, d as Z } from "./ignore-CMi2r3b2.js";
11
- const tt = "deployment.environment.name", T = (t, e) => {
1
+ import { NodeSDK as U } from "@opentelemetry/sdk-node";
2
+ import { OTLPTraceExporter as G } from "@opentelemetry/exporter-trace-otlp-http";
3
+ import { resourceFromAttributes as q } from "@opentelemetry/resources";
4
+ import { ATTR_SERVICE_VERSION as B, ATTR_SERVICE_NAME as k } from "@opentelemetry/semantic-conventions";
5
+ import { SamplingDecision as l, TraceIdRatioBasedSampler as M, AlwaysOnSampler as z, BatchSpanProcessor as $ } from "@opentelemetry/sdk-trace-base";
6
+ import { trace as j, TraceFlags as O, propagation as D, context as H, SpanStatusCode as Q } from "@opentelemetry/api";
7
+ import { readFile as X } from "node:fs/promises";
8
+ import { HttpInstrumentation as W } from "@opentelemetry/instrumentation-http";
9
+ import { UndiciInstrumentation as J } from "@opentelemetry/instrumentation-undici";
10
+ import { c as K, m as Z, a as tt, d as et } from "./ignore-CMi2r3b2.js";
11
+ const rt = "deployment.environment.name", T = (t, e) => {
12
12
  if (!t) return;
13
13
  const r = t[e.toLowerCase()];
14
14
  if (Array.isArray(r)) {
@@ -23,27 +23,27 @@ const tt = "deployment.environment.name", T = (t, e) => {
23
23
  } catch {
24
24
  return t.split("?")[0] || t;
25
25
  }
26
- }, O = /* @__PURE__ */ new WeakMap();
27
- function et(t) {
28
- const e = W(t.ignore), r = (t.inspectionHeader ?? "x-inspection").toLowerCase(), n = (t.userTypeHeader ?? "x-telemetry-user-type").toLowerCase(), s = (t.requestStartHeader ?? "x-telemetry-start").toLowerCase();
26
+ }, A = /* @__PURE__ */ new WeakMap();
27
+ function nt(t) {
28
+ const e = K(t.ignore), r = (t.inspectionHeader ?? "x-inspection").toLowerCase(), n = (t.userTypeHeader ?? "x-telemetry-user-type").toLowerCase(), s = (t.requestStartHeader ?? "x-telemetry-start").toLowerCase();
29
29
  return [
30
- new Q({
30
+ new W({
31
31
  startIncomingSpanHook: (o) => {
32
- const i = "headers" in o ? o.headers : void 0, a = T(i, r), c = T(i, n), p = T(i, s), u = "method" in o ? o.method : void 0, m = R("url" in o ? o.url : void 0), f = Number(p || Date.now()), E = {
33
- "telemetry.request.start_time_ms": Number.isFinite(f) ? f : Date.now()
32
+ const i = "headers" in o ? o.headers : void 0, a = T(i, r), c = T(i, n), m = T(i, s), p = "method" in o ? o.method : void 0, E = R("url" in o ? o.url : void 0), d = Number(m || Date.now()), u = {
33
+ "telemetry.request.start_time_ms": Number.isFinite(d) ? d : Date.now()
34
34
  };
35
- return m && (E["url.path"] = m), u && (E["http.request.method"] = u), a && (E["telemetry.request.inspection"] = !0, E["http.request.header.x-inspection"] = a), c && (E["enduser.type"] = c, E["telemetry.request.user_type"] = c), E;
35
+ return E && (u["url.path"] = E), p && (u["http.request.method"] = p), a && (u["telemetry.request.inspection"] = !0, u["http.request.header.x-inspection"] = a), c && (u["enduser.type"] = c, u["telemetry.request.user_type"] = c), u;
36
36
  },
37
37
  requestHook: (o, i) => {
38
- const a = "headers" in i ? i.headers : void 0, c = T(a, s), p = Number(c || Date.now());
39
- O.set(o, Number.isFinite(p) ? p : Date.now());
40
- const u = "method" in i && i.method || "GET", m = R("url" in i ? i.url : void 0);
41
- m && o.updateName(`${u} ${m}`);
38
+ const a = "headers" in i ? i.headers : void 0, c = T(a, s), m = Number(c || Date.now());
39
+ A.set(o, Number.isFinite(m) ? m : Date.now());
40
+ const p = "method" in i && i.method || "GET", E = R("url" in i ? i.url : void 0);
41
+ E && o.updateName(`${p} ${E}`);
42
42
  },
43
43
  responseHook: (o, i) => {
44
44
  const a = "statusCode" in i ? i.statusCode : void 0;
45
45
  typeof a == "number" && (o.setAttribute("http.response.status_code", a), o.setAttribute("telemetry.response.status_code", a), a >= 500 && o.setAttribute("telemetry.request.error", !0));
46
- const c = O.get(o);
46
+ const c = A.get(o);
47
47
  typeof c == "number" && o.setAttribute("telemetry.request.duration_ms", Date.now() - c);
48
48
  },
49
49
  ignoreIncomingRequestHook: (o) => {
@@ -55,16 +55,16 @@ function et(t) {
55
55
  return e(R(i));
56
56
  }
57
57
  }),
58
- new X()
58
+ new J()
59
59
  ];
60
60
  }
61
- const S = (t) => {
61
+ const y = (t) => {
62
62
  if (typeof t == "string") return t;
63
63
  if (Array.isArray(t)) {
64
64
  const e = t[0];
65
65
  return typeof e == "string" ? e : void 0;
66
66
  }
67
- }, H = (t) => {
67
+ }, b = (t) => {
68
68
  if (typeof t == "number") return t;
69
69
  if (typeof t == "string") {
70
70
  const e = Number(t);
@@ -72,33 +72,33 @@ const S = (t) => {
72
72
  }
73
73
  if (Array.isArray(t)) {
74
74
  const e = t[0];
75
- return H(e);
75
+ return b(e);
76
76
  }
77
- }, l = (t, e) => {
77
+ }, f = (t, e) => {
78
78
  for (const r of e)
79
79
  if (r in t)
80
80
  return t[r];
81
- }, rt = (t) => {
82
- const e = l(t, ["url.path", "http.target", "http.route"]), r = l(t, ["http.request.method", "http.method"]), n = l(t, ["enduser.type", "telemetry.request.user_type"]), s = l(t, [
81
+ }, ot = (t) => {
82
+ const e = f(t, ["url.path", "http.target", "http.route"]), r = f(t, ["http.request.method", "http.method"]), n = f(t, ["enduser.type", "telemetry.request.user_type"]), s = f(t, [
83
83
  "http.response.status_code",
84
84
  "http.status_code",
85
85
  "telemetry.response.status_code"
86
- ]), o = l(t, [
86
+ ]), o = f(t, [
87
87
  "telemetry.request.inspection",
88
88
  "http.request.header.x-inspection",
89
89
  "x-inspection"
90
90
  ]), i = o === !0 || o === "true" || o === "1" || o === 1;
91
91
  return {
92
- path: S(e),
93
- method: S(r),
94
- userType: S(n),
95
- statusCode: H(s),
92
+ path: y(e),
93
+ method: y(r),
94
+ userType: y(n),
95
+ statusCode: b(s),
96
96
  inspection: i
97
97
  };
98
- }, A = (t, e) => !t || !(e != null && e.length) ? !1 : e.some((r) => r.toLowerCase() === t.toLowerCase()), nt = (t, e) => !t || !(e != null && e.length) ? !1 : e.some((r) => J(r, t)), ot = (t, e) => {
98
+ }, w = (t, e) => !t || !(e != null && e.length) ? !1 : e.some((r) => r.toLowerCase() === t.toLowerCase()), st = (t, e) => !t || !(e != null && e.length) ? !1 : e.some((r) => Z(r, t)), it = (t, e) => {
99
99
  const r = t.when;
100
100
  if (!r) return !0;
101
- if (r.inspection !== void 0 && r.inspection !== e.inspection || r.path && !nt(e.path, r.path) || r.method && !A(e.method, r.method) || r.userType && !A(e.userType, r.userType))
101
+ if (r.inspection !== void 0 && r.inspection !== e.inspection || r.path && !st(e.path, r.path) || r.method && !w(e.method, r.method) || r.userType && !w(e.userType, r.userType))
102
102
  return !1;
103
103
  if (r.statusCode && typeof e.statusCode == "number") {
104
104
  if (!r.statusCode.includes(e.statusCode))
@@ -106,46 +106,52 @@ const S = (t) => {
106
106
  } else if (r.statusCode && r.statusCode.length)
107
107
  return !1;
108
108
  return !(typeof r.minStatusCode == "number" && (typeof e.statusCode != "number" || e.statusCode < r.minStatusCode) || typeof r.maxStatusCode == "number" && (typeof e.statusCode != "number" || e.statusCode > r.maxStatusCode));
109
- }, y = (t) => Math.max(0, Math.min(1, t)), st = (t, e, r) => {
110
- if (!(t != null && t.length)) return y(r);
109
+ }, N = (t) => Math.max(0, Math.min(1, t)), at = (t, e, r) => {
110
+ if (!(t != null && t.length)) return N(r);
111
111
  for (const n of t)
112
- if (ot(n, e))
113
- return y(n.ratio);
114
- return y(r);
115
- }, w = /* @__PURE__ */ new Map(), it = (t) => {
112
+ if (it(n, e))
113
+ return N(n.ratio);
114
+ return N(r);
115
+ }, I = /* @__PURE__ */ new Map(), ct = (t) => {
116
116
  if (t <= 0)
117
- return new L(0);
117
+ return new M(0);
118
118
  if (t >= 1)
119
- return new B();
120
- const e = Number(t.toFixed(6)), r = w.get(e);
119
+ return new z();
120
+ const e = Number(t.toFixed(6)), r = I.get(e);
121
121
  if (r) return r;
122
- const n = new L(e);
123
- return w.set(e, n), n;
124
- }, at = (t) => {
125
- let e, r;
122
+ const n = new M(e);
123
+ return I.set(e, n), n;
124
+ }, P = (t, e) => (t !== e.ignore && (e.ignore = t, e.matcher = tt(t)), e.matcher), ut = (t) => {
125
+ const e = {};
126
126
  return {
127
- shouldSample(n, s, o, i, a, c) {
128
- const p = z.getSpanContext(n);
129
- if (p)
130
- return (p.traceFlags & M.SAMPLED) === M.SAMPLED ? { decision: d.RECORD_AND_SAMPLED } : { decision: d.NOT_RECORD };
131
- const u = t.getConfig();
132
- if (u.ignore !== e && (e = u.ignore, r = K(u.ignore)), r != null && r(o))
133
- return { decision: d.NOT_RECORD };
134
- const m = rt(a);
135
- if (m.inspection)
136
- return { decision: d.RECORD_AND_SAMPLED };
137
- const f = st(
138
- u.samplingRules,
139
- m,
140
- u.defaultSamplingRatio ?? 0.01
127
+ shouldSample(r, n, s, o, i, a) {
128
+ const c = j.getSpanContext(r);
129
+ if (c) {
130
+ if (c.isRemote) {
131
+ const u = t.getConfig(), S = P(u.ignore, e);
132
+ if (S != null && S(s))
133
+ return { decision: l.NOT_RECORD };
134
+ }
135
+ return (c.traceFlags & O.SAMPLED) === O.SAMPLED ? { decision: l.RECORD_AND_SAMPLED } : { decision: l.NOT_RECORD };
136
+ }
137
+ const m = t.getConfig(), p = P(m.ignore, e);
138
+ if (p != null && p(s))
139
+ return { decision: l.NOT_RECORD };
140
+ const E = ot(i);
141
+ if (E.inspection)
142
+ return { decision: l.RECORD_AND_SAMPLED };
143
+ const d = at(
144
+ m.samplingRules,
145
+ E,
146
+ m.defaultSamplingRatio ?? 0.01
141
147
  );
142
- return it(f).shouldSample(n, s, o, i, a, c);
148
+ return ct(d).shouldSample(r, n, s, o, i, a);
143
149
  },
144
150
  toString: () => "RuleBasedSampler"
145
151
  };
146
- }, ct = (t) => t;
152
+ }, mt = (t) => t;
147
153
  let _, h;
148
- const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.split(",").map((e) => e.trim()).filter(Boolean)) ?? [], ut = (t) => {
154
+ const g = (t) => Array.from(new Set(t)), C = (t) => (t == null ? void 0 : t.split(",").map((e) => e.trim()).filter(Boolean)) ?? [], pt = (t) => {
149
155
  if (!t) return;
150
156
  const e = {};
151
157
  for (const r of t.split(",")) {
@@ -153,22 +159,22 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
153
159
  o && (e[o] = s.join("=").trim());
154
160
  }
155
161
  return e;
156
- }, C = (t) => {
162
+ }, L = (t) => {
157
163
  if (t)
158
164
  try {
159
165
  return JSON.parse(t);
160
166
  } catch {
161
167
  return;
162
168
  }
163
- }, mt = async (t) => {
169
+ }, Et = async (t) => {
164
170
  if (t)
165
171
  try {
166
- const e = await j(t, "utf8");
167
- return C(e);
172
+ const e = await X(t, "utf8");
173
+ return L(e);
168
174
  } catch {
169
175
  return;
170
176
  }
171
- }, D = (t, e) => {
177
+ }, v = (t, e) => {
172
178
  const r = g([...(t == null ? void 0 : t.paths) ?? [], ...(e == null ? void 0 : e.paths) ?? []]), n = g([
173
179
  ...(t == null ? void 0 : t.extensions) ?? [],
174
180
  ...(e == null ? void 0 : e.extensions) ?? []
@@ -179,20 +185,20 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
179
185
  methods: s.length ? s : void 0,
180
186
  spanNames: o.length ? o : void 0
181
187
  };
182
- }, pt = (t) => {
188
+ }, ht = (t) => {
183
189
  if (t != null && t.length)
184
190
  return t.map((e) => ({
185
191
  ...e,
186
192
  ratio: Number.isFinite(e.ratio) ? Math.max(0, Math.min(1, e.ratio)) : 0
187
193
  })).filter((e) => e.ratio >= 0);
188
- }, Et = async (t = process.env) => {
189
- const e = await mt(t.TELEMETRY_CONFIG_FILE), r = N(t.TELEMETRY_IGNORE_PATHS), n = N(t.TELEMETRY_IGNORE_EXTENSIONS), s = N(t.TELEMETRY_IGNORE_METHODS), o = C(t.TELEMETRY_SAMPLING_RULES), i = typeof (e == null ? void 0 : e.samplingRules) == "string" ? C(e.samplingRules) : e == null ? void 0 : e.samplingRules, a = {
194
+ }, lt = async (t = process.env) => {
195
+ const e = await Et(t.TELEMETRY_CONFIG_FILE), r = C(t.TELEMETRY_IGNORE_PATHS), n = C(t.TELEMETRY_IGNORE_EXTENSIONS), s = C(t.TELEMETRY_IGNORE_METHODS), o = L(t.TELEMETRY_SAMPLING_RULES), i = typeof (e == null ? void 0 : e.samplingRules) == "string" ? L(e.samplingRules) : e == null ? void 0 : e.samplingRules, a = {
190
196
  serviceName: t.OTEL_SERVICE_NAME || t.TELEMETRY_SERVICE_NAME,
191
197
  serviceVersion: t.OTEL_SERVICE_VERSION || t.TELEMETRY_SERVICE_VERSION,
192
198
  environment: t.OTEL_RESOURCE_ATTRIBUTES || t.TELEMETRY_ENVIRONMENT || (t.VERCEL ? t.VERCEL_ENV : void 0),
193
199
  defaultSamplingRatio: t.TELEMETRY_SAMPLING_RATIO ? Number(t.TELEMETRY_SAMPLING_RATIO) : void 0,
194
200
  url: t.OTEL_EXPORTER_OTLP_ENDPOINT || t.TELEMETRY_OTLP_ENDPOINT,
195
- headers: ut(t.OTEL_EXPORTER_OTLP_HEADERS || t.TELEMETRY_OTLP_HEADERS),
201
+ headers: pt(t.OTEL_EXPORTER_OTLP_HEADERS || t.TELEMETRY_OTLP_HEADERS),
196
202
  inspectionHeader: t.TELEMETRY_INSPECTION_HEADER,
197
203
  userTypeHeader: t.TELEMETRY_USER_TYPE_HEADER,
198
204
  requestStartHeader: t.TELEMETRY_REQUEST_START_HEADER,
@@ -204,7 +210,7 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
204
210
  } : void 0
205
211
  };
206
212
  return e && typeof e == "object" ? { ...e, ...a } : a;
207
- }, ht = (t) => {
213
+ }, ft = (t) => {
208
214
  if (!t) return process.env.NODE_ENV || "development";
209
215
  if (t.includes("deployment.environment")) {
210
216
  const r = t.split(",").find((s) => s.includes("deployment.environment"));
@@ -213,7 +219,7 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
213
219
  return (n == null ? void 0 : n.trim()) || t;
214
220
  }
215
221
  return t;
216
- }, lt = (t, e) => {
222
+ }, dt = (t, e) => {
217
223
  var n, s;
218
224
  const r = [
219
225
  { name: "inspection", ratio: 1, when: { inspection: !0 } },
@@ -242,8 +248,8 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
242
248
  when: { userType: [o] }
243
249
  });
244
250
  return r.push({ name: "default", ratio: e }), r;
245
- }, b = (t) => {
246
- const e = ht(t.environment), r = D(Z, t.ignore), n = typeof t.defaultSamplingRatio == "number" ? Math.max(0, Math.min(1, t.defaultSamplingRatio)) : 0.01, s = pt(t.samplingRules) ?? lt(t.layeredSampling, n);
251
+ }, F = (t) => {
252
+ const e = ft(t.environment), r = v(et, t.ignore), n = typeof t.defaultSamplingRatio == "number" ? Math.max(0, Math.min(1, t.defaultSamplingRatio)) : 0.01, s = ht(t.samplingRules) ?? dt(t.layeredSampling, n);
247
253
  return {
248
254
  ...t,
249
255
  serviceName: t.serviceName || "unknown-service",
@@ -260,32 +266,32 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
260
266
  maxExportBatchSize: t.maxExportBatchSize ?? 512,
261
267
  exporterTimeoutMillis: t.exporterTimeoutMillis ?? 3e4
262
268
  };
263
- }, v = async (t = {}, e = process.env) => {
264
- const r = await Et(e);
265
- return b({ ...r, ...t });
266
- }, ft = async (t) => {
267
- let e = await v(t);
269
+ }, Y = async (t = {}, e = process.env) => {
270
+ const r = await lt(e);
271
+ return F({ ...r, ...t });
272
+ }, Tt = async (t) => {
273
+ let e = await Y(t);
268
274
  return {
269
275
  getConfig: () => e,
270
276
  updateConfig: (r) => {
271
- e = b({
277
+ e = F({
272
278
  ...e,
273
279
  ...r,
274
- ignore: D(e.ignore, r.ignore)
280
+ ignore: v(e.ignore, r.ignore)
275
281
  });
276
282
  }
277
283
  };
278
- }, dt = (t) => t[0] * 1e3 + t[1] / 1e6, Tt = (t, e) => {
284
+ }, Rt = (t) => t[0] * 1e3 + t[1] / 1e6, gt = (t, e) => {
279
285
  for (const r of e) {
280
286
  const n = t.attributes[r];
281
287
  if (typeof n == "number") return n;
282
288
  }
283
- }, Rt = (t) => {
289
+ }, _t = (t) => {
284
290
  const e = t.events.find((n) => n.name === "exception");
285
291
  if (!(e != null && e.attributes)) return;
286
292
  const r = e.attributes["exception.message"];
287
293
  return typeof r == "string" ? r : void 0;
288
- }, I = /^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$/, P = (t) => {
294
+ }, V = /^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$/, x = (t) => {
289
295
  for (const r of ["url.path", "http.target", "http.route", "next.route"]) {
290
296
  const n = t[r];
291
297
  if (n && typeof n == "string") return n;
@@ -297,67 +303,67 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
297
303
  } catch {
298
304
  return e.split("?")[0];
299
305
  }
300
- }, gt = () => ({
306
+ }, St = () => ({
301
307
  onStart: (t) => {
302
308
  const e = t, r = e.name;
303
- if (!r || !I.test(r)) return;
304
- const n = P(e.attributes);
309
+ if (!r || !V.test(r)) return;
310
+ const n = x(e.attributes);
305
311
  n && t.updateName(`${r} ${n}`);
306
312
  },
307
313
  onEnd: (t) => {
308
314
  const e = t.name;
309
- if (!e || !I.test(e)) return;
310
- const r = P(t.attributes);
315
+ if (!e || !V.test(e)) return;
316
+ const r = x(t.attributes);
311
317
  if (!r) return;
312
318
  const n = t.attributes["http.request.method"] ?? t.attributes["http.method"], s = typeof n == "string" ? n : e;
313
319
  t.name = `${s} ${r}`;
314
320
  },
315
321
  shutdown: () => Promise.resolve(),
316
322
  forceFlush: () => Promise.resolve()
317
- }), _t = () => ({
323
+ }), yt = () => ({
318
324
  onStart: () => {
319
325
  },
320
326
  onEnd: (t) => {
321
- const e = dt(t.duration);
327
+ const e = Rt(t.duration);
322
328
  t.attributes["telemetry.request.duration_ms"] = Math.round(e), typeof t.attributes["telemetry.request.start_time_ms"] != "number" && (t.attributes["telemetry.request.start_time_ms"] = Date.now() - Math.round(e));
323
- const r = Tt(t, [
329
+ const r = gt(t, [
324
330
  "http.response.status_code",
325
331
  "http.status_code",
326
332
  "telemetry.response.status_code"
327
333
  ]);
328
- if (typeof r == "number" && (t.attributes["telemetry.response.status_code"] = r), t.status.code === $.ERROR || typeof r == "number" && r >= 500) {
334
+ if (typeof r == "number" && (t.attributes["telemetry.response.status_code"] = r), t.status.code === Q.ERROR || typeof r == "number" && r >= 500) {
329
335
  t.attributes["telemetry.request.error"] = !0;
330
- const s = t.status.message || Rt(t);
336
+ const s = t.status.message || _t(t);
331
337
  s && (t.attributes["telemetry.request.error_message"] = s);
332
338
  }
333
339
  },
334
340
  shutdown: () => Promise.resolve(),
335
341
  forceFlush: () => Promise.resolve()
336
- }), Pt = async (t) => {
337
- const e = await v(t);
338
- h = await ft(e);
342
+ }), xt = async (t) => {
343
+ const e = await Y(t);
344
+ h = await Tt(e);
339
345
  const r = process.env, n = {
340
- [q]: e.serviceName,
341
- [G]: e.serviceVersion || "1.0.0",
342
- [tt]: e.environment || r.VERCEL_ENV || r.NODE_ENV || "development"
346
+ [k]: e.serviceName,
347
+ [B]: e.serviceVersion || "1.0.0",
348
+ [rt]: e.environment || r.VERCEL_ENV || r.NODE_ENV || "development"
343
349
  };
344
350
  r.VERCEL && (r.VERCEL_REGION && (n["vercel.region"] = r.VERCEL_REGION), r.NEXT_RUNTIME && (n["vercel.runtime"] = r.NEXT_RUNTIME), r.VERCEL_GIT_COMMIT_SHA && (n["vercel.sha"] = r.VERCEL_GIT_COMMIT_SHA), r.VERCEL_URL && (n["vercel.host"] = r.VERCEL_URL), r.VERCEL_BRANCH_URL && (n["vercel.branch_host"] = r.VERCEL_BRANCH_URL), r.VERCEL_DEPLOYMENT_ID && (n["vercel.deployment_id"] = r.VERCEL_DEPLOYMENT_ID));
345
- const s = U(n), o = new Y(e), i = ct(o), a = [
346
- gt(),
347
- _t(),
348
- new k(i, {
351
+ const s = q(n), o = new G(e), i = mt(o), a = [
352
+ St(),
353
+ yt(),
354
+ new $(i, {
349
355
  scheduledDelayMillis: e.scheduledDelayMillis,
350
356
  maxQueueSize: e.maxQueueSize,
351
357
  maxExportBatchSize: e.maxExportBatchSize,
352
358
  exportTimeoutMillis: e.exporterTimeoutMillis
353
359
  })
354
360
  ];
355
- _ = new F({
361
+ _ = new U({
356
362
  serviceName: e.serviceName,
357
363
  resource: s,
358
364
  spanProcessors: a,
359
- sampler: at(h),
360
- instrumentations: et(e)
365
+ sampler: ut(h),
366
+ instrumentations: nt(e)
361
367
  });
362
368
  try {
363
369
  await _.start();
@@ -365,31 +371,31 @@ const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.spli
365
371
  console.warn("Telemetry start failed:", c);
366
372
  }
367
373
  return h;
368
- }, Vt = (t) => {
374
+ }, Dt = (t) => {
369
375
  h == null || h.updateConfig(t);
370
- }, xt = (t) => (V.inject(x.active(), t), t), Ht = (t = fetch) => async (e, r) => {
376
+ }, Ht = (t) => (D.inject(H.active(), t), t), bt = (t = fetch) => async (e, r) => {
371
377
  const n = (r == null ? void 0 : r.headers) ?? (e instanceof Request ? e.headers : void 0), s = new Headers(n);
372
- return V.inject(x.active(), s, {
378
+ return D.inject(H.active(), s, {
373
379
  set: (o, i, a) => {
374
380
  o.set(i, a);
375
381
  }
376
382
  }), t(e, { ...r, headers: s });
377
- }, Dt = async () => {
383
+ }, vt = async () => {
378
384
  _ && await _.shutdown();
379
385
  };
380
386
  export {
381
- rt as buildSamplingContextFromAttributes,
382
- W as createIgnoreMatcher,
383
- Ht as createPropagatingFetch,
384
- K as createSpanNameMatcher,
385
- ft as createTelemetryRuntime,
386
- Z as defaultIgnoreConfig,
387
- xt as injectTraceHeaders,
388
- Et as loadTelemetryConfigFromEnv,
389
- ot as matchSamplingRule,
390
- st as resolveSamplingRatio,
391
- v as resolveTelemetryConfig,
392
- Dt as shutdownTelemetry,
393
- Pt as startTelemetry,
394
- Vt as updateTelemetryConfig
387
+ ot as buildSamplingContextFromAttributes,
388
+ K as createIgnoreMatcher,
389
+ bt as createPropagatingFetch,
390
+ tt as createSpanNameMatcher,
391
+ Tt as createTelemetryRuntime,
392
+ et as defaultIgnoreConfig,
393
+ Ht as injectTraceHeaders,
394
+ lt as loadTelemetryConfigFromEnv,
395
+ it as matchSamplingRule,
396
+ at as resolveSamplingRatio,
397
+ Y as resolveTelemetryConfig,
398
+ vt as shutdownTelemetry,
399
+ xt as startTelemetry,
400
+ Dt as updateTelemetryConfig
395
401
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xchain/telemetry",
3
- "version": "1.1.0-beta.17",
3
+ "version": "1.1.0-beta.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",