@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.
- package/dist/Sampler.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +157 -133
- package/package.json +1 -1
package/dist/Sampler.d.ts.map
CHANGED
|
@@ -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;
|
|
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,OA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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
|
|
2
|
-
import { OTLPTraceExporter as
|
|
3
|
-
import { resourceFromAttributes as
|
|
4
|
-
import { ATTR_SERVICE_VERSION as
|
|
5
|
-
import { SamplingDecision as
|
|
6
|
-
import { trace as
|
|
7
|
-
import { readFile as
|
|
8
|
-
import { HttpInstrumentation as
|
|
9
|
-
import { UndiciInstrumentation as
|
|
10
|
-
import { c as
|
|
11
|
-
const
|
|
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
|
-
},
|
|
27
|
-
function
|
|
28
|
-
const e =
|
|
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
|
|
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),
|
|
33
|
-
"telemetry.request.start_time_ms": Number.isFinite(
|
|
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
|
|
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),
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
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 =
|
|
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
|
|
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
|
-
},
|
|
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
|
|
75
|
+
return b(e);
|
|
76
76
|
}
|
|
77
|
-
},
|
|
77
|
+
}, f = (t, e) => {
|
|
78
78
|
for (const r of e)
|
|
79
79
|
if (r in t)
|
|
80
80
|
return t[r];
|
|
81
|
-
},
|
|
82
|
-
const e =
|
|
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 =
|
|
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:
|
|
93
|
-
method:
|
|
94
|
-
userType:
|
|
95
|
-
statusCode:
|
|
92
|
+
path: y(e),
|
|
93
|
+
method: y(r),
|
|
94
|
+
userType: y(n),
|
|
95
|
+
statusCode: b(s),
|
|
96
96
|
inspection: i
|
|
97
97
|
};
|
|
98
|
-
},
|
|
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 && !
|
|
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
|
-
},
|
|
110
|
-
if (!(t != null && t.length)) return
|
|
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 (
|
|
113
|
-
return
|
|
114
|
-
return
|
|
115
|
-
},
|
|
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
|
|
117
|
+
return new M(0);
|
|
118
118
|
if (t >= 1)
|
|
119
|
-
return new
|
|
120
|
-
const e = Number(t.toFixed(6)), r =
|
|
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
|
|
123
|
-
return
|
|
124
|
-
},
|
|
125
|
-
|
|
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
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
|
148
|
+
return ct(d).shouldSample(r, n, s, o, i, a);
|
|
143
149
|
},
|
|
144
150
|
toString: () => "RuleBasedSampler"
|
|
145
151
|
};
|
|
146
|
-
},
|
|
147
|
-
let _,
|
|
148
|
-
const g = (t) => Array.from(new Set(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
|
-
},
|
|
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
|
-
},
|
|
169
|
+
}, Et = async (t) => {
|
|
164
170
|
if (t)
|
|
165
171
|
try {
|
|
166
|
-
const e = await
|
|
167
|
-
return
|
|
172
|
+
const e = await X(t, "utf8");
|
|
173
|
+
return L(e);
|
|
168
174
|
} catch {
|
|
169
175
|
return;
|
|
170
176
|
}
|
|
171
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
189
|
-
const e = await
|
|
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:
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
246
|
-
const e =
|
|
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
|
-
},
|
|
264
|
-
const r = await
|
|
265
|
-
return
|
|
266
|
-
},
|
|
267
|
-
let e = await
|
|
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 =
|
|
277
|
+
e = F({
|
|
272
278
|
...e,
|
|
273
279
|
...r,
|
|
274
|
-
ignore:
|
|
280
|
+
ignore: v(e.ignore, r.ignore)
|
|
275
281
|
});
|
|
276
282
|
}
|
|
277
283
|
};
|
|
278
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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 || !
|
|
292
|
-
const n = e.attributes
|
|
293
|
-
|
|
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
|
-
}),
|
|
323
|
+
}), yt = () => ({
|
|
300
324
|
onStart: () => {
|
|
301
325
|
},
|
|
302
326
|
onEnd: (t) => {
|
|
303
|
-
const e =
|
|
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 =
|
|
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 ===
|
|
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 ||
|
|
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
|
-
}),
|
|
319
|
-
const e = await
|
|
320
|
-
|
|
342
|
+
}), xt = async (t) => {
|
|
343
|
+
const e = await Y(t);
|
|
344
|
+
h = await Tt(e);
|
|
321
345
|
const r = process.env, n = {
|
|
322
|
-
[
|
|
323
|
-
[
|
|
324
|
-
[
|
|
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 =
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
new
|
|
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
|
|
361
|
+
_ = new U({
|
|
338
362
|
serviceName: e.serviceName,
|
|
339
363
|
resource: s,
|
|
340
364
|
spanProcessors: a,
|
|
341
|
-
sampler:
|
|
342
|
-
instrumentations:
|
|
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
|
|
350
|
-
},
|
|
351
|
-
|
|
352
|
-
},
|
|
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
|
|
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
|
-
},
|
|
383
|
+
}, vt = async () => {
|
|
360
384
|
_ && await _.shutdown();
|
|
361
385
|
};
|
|
362
386
|
export {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
};
|