@0xchain/telemetry 1.1.0-beta.16 → 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;AACv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ACxB,OAAO,EACL,kCAAkC,EAClC,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,GACpB,CAAC;AA8EF,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,GACrC,MAAK,MAAM,CAAC,UAAwB,KACnC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAuClC,CAAC;AAiGF,wBAAwB;AACxB,eAAO,MAAM,sBAAsB,GACjC,UAAS,OAAO,CAAC,eAAe,CAAM,EACtC,MAAK,MAAM,CAAC,UAAwB,KACnC,OAAO,CAAC,eAAe,CAGzB,CAAC;AAEF,oBAAoB;AACpB,eAAO,MAAM,sBAAsB,GACjC,eAAe,OAAO,CAAC,eAAe,CAAC,KACtC,OAAO,CAAC,gBAAgB,CAY1B,CAAC;AAuHF,2BAA2B;AAC3B,eAAO,MAAM,cAAc,GAAU,SAAS,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,8BAgDvF,CAAC;AAEF,yBAAyB;AACzB,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,CAAC,eAAe,CAAC,SAEtE,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,2BAGjE,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,sBAAsB,GAAI,YAAW,OAAO,KAAa,MACtD,OAAO,WAAW,GAAG,GAAG,EAAE,OAAO,WAAW,sBAY3D,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,iBAAiB,qBAI7B,CAAC"}
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { NodeSDK as b } from "@opentelemetry/sdk-node";
2
- import { OTLPTraceExporter as v } from "@opentelemetry/exporter-trace-otlp-http";
3
- import { resourceFromAttributes as F } from "@opentelemetry/resources";
4
- import { ATTR_SERVICE_VERSION as Y, ATTR_SERVICE_NAME as U } from "@opentelemetry/semantic-conventions";
5
- import { SamplingDecision as d, TraceIdRatioBasedSampler as L, AlwaysOnSampler as G, BatchSpanProcessor as B } from "@opentelemetry/sdk-trace-base";
6
- import { trace as q, TraceFlags as M, propagation as I, context as V, SpanStatusCode as z } from "@opentelemetry/api";
7
- import { readFile as k } from "node:fs/promises";
8
- import { HttpInstrumentation as j } from "@opentelemetry/instrumentation-http";
9
- import { UndiciInstrumentation as $ } from "@opentelemetry/instrumentation-undici";
10
- import { c as Q, m as X, a as W, d as J } from "./ignore-CMi2r3b2.js";
11
- const K = "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 K = "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 Z(t) {
28
- const e = Q(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 j({
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 Z(t) {
55
55
  return e(R(i));
56
56
  }
57
57
  }),
58
- new $()
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
- }, P = (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 P(e);
75
+ return b(e);
76
76
  }
77
- }, h = (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
- }, tt = (t) => {
82
- const e = h(t, ["url.path", "http.target", "http.route"]), r = h(t, ["http.request.method", "http.method"]), n = h(t, ["enduser.type", "telemetry.request.user_type"]), s = h(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 = h(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: P(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()), et = (t, e) => !t || !(e != null && e.length) ? !1 : e.some((r) => X(r, t)), rt = (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 && !et(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)), nt = (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 (rt(n, e))
113
- return y(n.ratio);
114
- return y(r);
115
- }, w = /* @__PURE__ */ new Map(), ot = (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 G();
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
- }, st = (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 = q.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 = W(u.ignore)), r != null && r(o))
133
- return { decision: d.NOT_RECORD };
134
- const m = tt(a);
135
- if (m.inspection)
136
- return { decision: d.RECORD_AND_SAMPLED };
137
- const f = nt(
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 ot(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
- }, it = (t) => t;
147
- let _, l;
148
- const g = (t) => Array.from(new Set(t)), N = (t) => (t == null ? void 0 : t.split(",").map((e) => e.trim()).filter(Boolean)) ?? [], at = (t) => {
152
+ }, mt = (t) => t;
153
+ let _, h;
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
- }, ct = async (t) => {
169
+ }, Et = async (t) => {
164
170
  if (t)
165
171
  try {
166
- const e = await k(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
- }, x = (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
- }, ut = (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
- }, mt = async (t = process.env) => {
189
- const e = await ct(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: at(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
- }, pt = (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
- }, Et = (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
- }, H = (t) => {
246
- const e = pt(t.environment), r = x(J, t.ignore), n = typeof t.defaultSamplingRatio == "number" ? Math.max(0, Math.min(1, t.defaultSamplingRatio)) : 0.01, s = ut(t.samplingRules) ?? Et(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,118 +266,136 @@ 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
- }, D = async (t = {}, e = process.env) => {
264
- const r = await mt(e);
265
- return H({ ...r, ...t });
266
- }, lt = async (t) => {
267
- let e = await D(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 = H({
277
+ e = F({
272
278
  ...e,
273
279
  ...r,
274
- ignore: x(e.ignore, r.ignore)
280
+ ignore: v(e.ignore, r.ignore)
275
281
  });
276
282
  }
277
283
  };
278
- }, ht = (t) => t[0] * 1e3 + t[1] / 1e6, ft = (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
- }, dt = (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
- }, Tt = /^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$/, Rt = () => ({
294
+ }, V = /^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$/, x = (t) => {
295
+ for (const r of ["url.path", "http.target", "http.route", "next.route"]) {
296
+ const n = t[r];
297
+ if (n && typeof n == "string") return n;
298
+ }
299
+ const e = t["http.url"] ?? t["url.full"];
300
+ if (e && typeof e == "string")
301
+ try {
302
+ return new URL(e).pathname;
303
+ } catch {
304
+ return e.split("?")[0];
305
+ }
306
+ }, St = () => ({
289
307
  onStart: (t) => {
290
308
  const e = t, r = e.name;
291
- if (!r || !Tt.test(r)) return;
292
- const n = e.attributes, s = n["url.path"] ?? n["http.target"] ?? n["http.route"] ?? n["next.route"];
293
- s && typeof s == "string" && t.updateName(`${r} ${s}`);
309
+ if (!r || !V.test(r)) return;
310
+ const n = x(e.attributes);
311
+ n && t.updateName(`${r} ${n}`);
294
312
  },
295
- onEnd: () => {
313
+ onEnd: (t) => {
314
+ const e = t.name;
315
+ if (!e || !V.test(e)) return;
316
+ const r = x(t.attributes);
317
+ if (!r) return;
318
+ const n = t.attributes["http.request.method"] ?? t.attributes["http.method"], s = typeof n == "string" ? n : e;
319
+ t.name = `${s} ${r}`;
296
320
  },
297
321
  shutdown: () => Promise.resolve(),
298
322
  forceFlush: () => Promise.resolve()
299
- }), gt = () => ({
323
+ }), yt = () => ({
300
324
  onStart: () => {
301
325
  },
302
326
  onEnd: (t) => {
303
- const e = ht(t.duration);
327
+ const e = Rt(t.duration);
304
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));
305
- const r = ft(t, [
329
+ const r = gt(t, [
306
330
  "http.response.status_code",
307
331
  "http.status_code",
308
332
  "telemetry.response.status_code"
309
333
  ]);
310
- if (typeof r == "number" && (t.attributes["telemetry.response.status_code"] = r), t.status.code === z.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) {
311
335
  t.attributes["telemetry.request.error"] = !0;
312
- const s = t.status.message || dt(t);
336
+ const s = t.status.message || _t(t);
313
337
  s && (t.attributes["telemetry.request.error_message"] = s);
314
338
  }
315
339
  },
316
340
  shutdown: () => Promise.resolve(),
317
341
  forceFlush: () => Promise.resolve()
318
- }), It = async (t) => {
319
- const e = await D(t);
320
- l = await lt(e);
342
+ }), xt = async (t) => {
343
+ const e = await Y(t);
344
+ h = await Tt(e);
321
345
  const r = process.env, n = {
322
- [U]: e.serviceName,
323
- [Y]: e.serviceVersion || "1.0.0",
324
- [K]: 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"
325
349
  };
326
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));
327
- const s = F(n), o = new v(e), i = it(o), a = [
328
- Rt(),
329
- gt(),
330
- new B(i, {
351
+ const s = q(n), o = new G(e), i = mt(o), a = [
352
+ St(),
353
+ yt(),
354
+ new $(i, {
331
355
  scheduledDelayMillis: e.scheduledDelayMillis,
332
356
  maxQueueSize: e.maxQueueSize,
333
357
  maxExportBatchSize: e.maxExportBatchSize,
334
358
  exportTimeoutMillis: e.exporterTimeoutMillis
335
359
  })
336
360
  ];
337
- _ = new b({
361
+ _ = new U({
338
362
  serviceName: e.serviceName,
339
363
  resource: s,
340
364
  spanProcessors: a,
341
- sampler: st(l),
342
- instrumentations: Z(e)
365
+ sampler: ut(h),
366
+ instrumentations: nt(e)
343
367
  });
344
368
  try {
345
369
  await _.start();
346
370
  } catch (c) {
347
371
  console.warn("Telemetry start failed:", c);
348
372
  }
349
- return l;
350
- }, Vt = (t) => {
351
- l == null || l.updateConfig(t);
352
- }, Pt = (t) => (I.inject(V.active(), t), t), xt = (t = fetch) => async (e, r) => {
373
+ return h;
374
+ }, Dt = (t) => {
375
+ h == null || h.updateConfig(t);
376
+ }, Ht = (t) => (D.inject(H.active(), t), t), bt = (t = fetch) => async (e, r) => {
353
377
  const n = (r == null ? void 0 : r.headers) ?? (e instanceof Request ? e.headers : void 0), s = new Headers(n);
354
- return I.inject(V.active(), s, {
378
+ return D.inject(H.active(), s, {
355
379
  set: (o, i, a) => {
356
380
  o.set(i, a);
357
381
  }
358
382
  }), t(e, { ...r, headers: s });
359
- }, Ht = async () => {
383
+ }, vt = async () => {
360
384
  _ && await _.shutdown();
361
385
  };
362
386
  export {
363
- tt as buildSamplingContextFromAttributes,
364
- Q as createIgnoreMatcher,
365
- xt as createPropagatingFetch,
366
- W as createSpanNameMatcher,
367
- lt as createTelemetryRuntime,
368
- J as defaultIgnoreConfig,
369
- Pt as injectTraceHeaders,
370
- mt as loadTelemetryConfigFromEnv,
371
- rt as matchSamplingRule,
372
- nt as resolveSamplingRatio,
373
- D as resolveTelemetryConfig,
374
- Ht as shutdownTelemetry,
375
- It as startTelemetry,
376
- 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
377
401
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xchain/telemetry",
3
- "version": "1.1.0-beta.16",
3
+ "version": "1.1.0-beta.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",