@0xchain/telemetry 1.1.0-beta.8 → 1.1.0-beta.80
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/LICENSE +21 -0
- package/README.md +105 -95
- package/dist/Instrumentations.d.ts +4 -2
- package/dist/Instrumentations.d.ts.map +1 -1
- package/dist/Sampler.d.ts +2 -2
- package/dist/Sampler.d.ts.map +1 -1
- package/dist/ignore-BvHZTNsF.js +151 -0
- package/dist/ignore.d.ts +3 -1
- package/dist/ignore.d.ts.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +609 -0
- package/dist/instrumentation.d.ts +4 -0
- package/dist/instrumentation.d.ts.map +1 -0
- package/dist/instrumentation.js +8 -0
- package/dist/middleware.d.ts +24 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +43 -0
- package/dist/next.d.ts +20 -6
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +43 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +40 -10
- package/dist/index +0 -442
- package/dist/next +0 -30
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { c as createIgnoreMatcher } from "./ignore-BvHZTNsF.js";
|
|
3
|
+
const defaultTelemetryMiddlewareConfig = {
|
|
4
|
+
matcher: [
|
|
5
|
+
"/((?!_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml|.*\\.(?:css|js|mjs|cjs|png|jpg|jpeg|gif|svg|ico|webp|avif|woff|woff2|ttf|eot|map|txt|xml)).*)"
|
|
6
|
+
]
|
|
7
|
+
};
|
|
8
|
+
const withTelemetryMiddleware = (middleware, options = {}) => {
|
|
9
|
+
const shouldIgnore = createIgnoreMatcher(options.ignore);
|
|
10
|
+
const requestStartHeader = (options.requestStartHeader ?? "x-telemetry-start").toLowerCase();
|
|
11
|
+
const userTypeHeader = (options.userTypeHeader ?? "x-telemetry-user-type").toLowerCase();
|
|
12
|
+
const resolveUserType = options.resolveUserType;
|
|
13
|
+
return async (request, event) => {
|
|
14
|
+
const pathname = request.nextUrl.pathname;
|
|
15
|
+
if (shouldIgnore(pathname, request.method)) {
|
|
16
|
+
return middleware(request, event);
|
|
17
|
+
}
|
|
18
|
+
const headers = new Headers(request.headers);
|
|
19
|
+
const userType = resolveUserType?.(request) || headers.get(userTypeHeader);
|
|
20
|
+
if (userType) headers.set(userTypeHeader, userType);
|
|
21
|
+
headers.set(requestStartHeader, String(Date.now()));
|
|
22
|
+
const wrappedRequest = new NextRequest(request, {
|
|
23
|
+
headers
|
|
24
|
+
});
|
|
25
|
+
const response = await middleware(wrappedRequest, event);
|
|
26
|
+
if (!response) {
|
|
27
|
+
return NextResponse.next({
|
|
28
|
+
request: {
|
|
29
|
+
headers
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return response;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const createTelemetryMiddleware = (options = {}) => {
|
|
37
|
+
return withTelemetryMiddleware(() => NextResponse.next(), options);
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
createTelemetryMiddleware,
|
|
41
|
+
defaultTelemetryMiddlewareConfig,
|
|
42
|
+
withTelemetryMiddleware
|
|
43
|
+
};
|
package/dist/next.d.ts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import {
|
|
1
|
+
import { NextResponse, NextRequest, NextFetchEvent } from 'next/server';
|
|
2
|
+
import { TelemetryMiddlewareOptions } from './types';
|
|
3
3
|
export declare const defaultTelemetryMiddlewareConfig: {
|
|
4
4
|
matcher: string[];
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
/**
|
|
9
|
-
|
|
6
|
+
export type NextMiddlewareResult = NextResponse | Response | null | undefined | void;
|
|
7
|
+
export type NextMiddleware = (request: NextRequest, event: NextFetchEvent) => NextMiddlewareResult | Promise<NextMiddlewareResult>;
|
|
8
|
+
/**
|
|
9
|
+
* Higher-order function to wrap existing middleware with telemetry support.
|
|
10
|
+
* This is less invasive than creating a separate middleware factory.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* export const middleware = withTelemetryMiddleware(async (req) => {
|
|
14
|
+
* // your existing middleware logic
|
|
15
|
+
* return NextResponse.next();
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
export declare const withTelemetryMiddleware: (middleware: NextMiddleware, options?: TelemetryMiddlewareOptions) => NextMiddleware;
|
|
19
|
+
/**
|
|
20
|
+
* Simplified Telemetry Middleware Creator (Factory Pattern)
|
|
21
|
+
* For users who don't have existing middleware or prefer this style.
|
|
22
|
+
*/
|
|
23
|
+
export declare const createTelemetryMiddleware: (options?: TelemetryMiddlewareOptions) => NextMiddleware;
|
|
10
24
|
//# sourceMappingURL=next.d.ts.map
|
package/dist/next.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAE1D,eAAO,MAAM,gCAAgC;;CAI5C,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;AAErF,MAAM,MAAM,cAAc,GAAG,CAC3B,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,cAAc,KAClB,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAE1D;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,GAClC,YAAY,cAAc,EAC1B,UAAS,0BAA+B,KACvC,cAqCF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GAAI,UAAS,0BAA+B,mBAGjF,CAAC"}
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { c as createIgnoreMatcher } from "./ignore-BvHZTNsF.js";
|
|
3
|
+
const defaultTelemetryMiddlewareConfig = {
|
|
4
|
+
matcher: [
|
|
5
|
+
"/((?!_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml|.*\\.(?:css|js|mjs|cjs|png|jpg|jpeg|gif|svg|ico|webp|avif|woff|woff2|ttf|eot|map|txt|xml)).*)"
|
|
6
|
+
]
|
|
7
|
+
};
|
|
8
|
+
const withTelemetryMiddleware = (middleware, options = {}) => {
|
|
9
|
+
const shouldIgnore = createIgnoreMatcher(options.ignore);
|
|
10
|
+
const requestStartHeader = (options.requestStartHeader ?? "x-telemetry-start").toLowerCase();
|
|
11
|
+
const userTypeHeader = (options.userTypeHeader ?? "x-telemetry-user-type").toLowerCase();
|
|
12
|
+
const resolveUserType = options.resolveUserType;
|
|
13
|
+
return async (request, event) => {
|
|
14
|
+
const pathname = request.nextUrl.pathname;
|
|
15
|
+
if (shouldIgnore(pathname, request.method)) {
|
|
16
|
+
return middleware(request, event);
|
|
17
|
+
}
|
|
18
|
+
const headers = new Headers(request.headers);
|
|
19
|
+
const userType = resolveUserType?.(request) || headers.get(userTypeHeader);
|
|
20
|
+
if (userType) headers.set(userTypeHeader, userType);
|
|
21
|
+
headers.set(requestStartHeader, String(Date.now()));
|
|
22
|
+
const wrappedRequest = new NextRequest(request, {
|
|
23
|
+
headers
|
|
24
|
+
});
|
|
25
|
+
const response = await middleware(wrappedRequest, event);
|
|
26
|
+
if (!response) {
|
|
27
|
+
return NextResponse.next({
|
|
28
|
+
request: {
|
|
29
|
+
headers
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return response;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const createTelemetryMiddleware = (options = {}) => {
|
|
37
|
+
return withTelemetryMiddleware(() => NextResponse.next(), options);
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
createTelemetryMiddleware,
|
|
41
|
+
defaultTelemetryMiddlewareConfig,
|
|
42
|
+
withTelemetryMiddleware
|
|
43
|
+
};
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1C,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1C,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,uDAAuD;IACvD,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,qBAAqB,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,eAAgB,SAAQ,0BAA0B;IACjE,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,eAAe,CAAC;IACjC,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC;CAC3D;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,aAAa,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC;CACtF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xchain/telemetry",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.80",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -12,9 +12,22 @@
|
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
+
"./middleware": {
|
|
16
|
+
"types": "./dist/middleware.d.ts",
|
|
17
|
+
"import": "./dist/middleware.js",
|
|
18
|
+
"require": "./dist/middleware.js",
|
|
19
|
+
"default": "./dist/middleware.js"
|
|
20
|
+
},
|
|
21
|
+
"./instrumentation": {
|
|
22
|
+
"types": "./dist/instrumentation.d.ts",
|
|
23
|
+
"import": "./dist/instrumentation.js",
|
|
24
|
+
"require": "./dist/instrumentation.js",
|
|
25
|
+
"default": "./dist/instrumentation.js"
|
|
26
|
+
},
|
|
15
27
|
"./next": {
|
|
16
28
|
"types": "./dist/next.d.ts",
|
|
17
29
|
"import": "./dist/next.js",
|
|
30
|
+
"require": "./dist/next.js",
|
|
18
31
|
"default": "./dist/next.js"
|
|
19
32
|
}
|
|
20
33
|
},
|
|
@@ -22,18 +35,35 @@
|
|
|
22
35
|
"dist",
|
|
23
36
|
"!**/*.tsbuildinfo"
|
|
24
37
|
],
|
|
25
|
-
"
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@opentelemetry/api": "1.9.0",
|
|
40
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.212.0",
|
|
41
|
+
"@opentelemetry/instrumentation-http": "0.212.0",
|
|
42
|
+
"@opentelemetry/instrumentation-undici": "0.22.0",
|
|
43
|
+
"@opentelemetry/otlp-exporter-base": "0.212.0",
|
|
44
|
+
"@opentelemetry/resources": "2.5.1",
|
|
45
|
+
"@opentelemetry/sdk-node": "0.212.0",
|
|
46
|
+
"@opentelemetry/sdk-trace-base": "2.5.1",
|
|
47
|
+
"@opentelemetry/semantic-conventions": "1.40.0",
|
|
48
|
+
"next": "16.1.6"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
26
51
|
"@opentelemetry/api": "1.9.0",
|
|
27
|
-
"@opentelemetry/
|
|
28
|
-
"@opentelemetry/
|
|
29
|
-
"@opentelemetry/instrumentation-undici": "0.
|
|
30
|
-
"@opentelemetry/otlp-exporter-base": "0.
|
|
31
|
-
"@opentelemetry/resources": "2.5.
|
|
32
|
-
"@opentelemetry/sdk-node": "0.
|
|
33
|
-
"@opentelemetry/sdk-trace-base": "2.5.
|
|
34
|
-
"@opentelemetry/semantic-conventions": "1.
|
|
52
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.212.0",
|
|
53
|
+
"@opentelemetry/instrumentation-http": "0.212.0",
|
|
54
|
+
"@opentelemetry/instrumentation-undici": "0.22.0",
|
|
55
|
+
"@opentelemetry/otlp-exporter-base": "0.212.0",
|
|
56
|
+
"@opentelemetry/resources": "2.5.1",
|
|
57
|
+
"@opentelemetry/sdk-node": "0.212.0",
|
|
58
|
+
"@opentelemetry/sdk-trace-base": "2.5.1",
|
|
59
|
+
"@opentelemetry/semantic-conventions": "1.40.0",
|
|
35
60
|
"next": "16.1.6"
|
|
36
61
|
},
|
|
62
|
+
"nx": {
|
|
63
|
+
"tags": [
|
|
64
|
+
"type:util"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
37
67
|
"publishConfig": {
|
|
38
68
|
"access": "public"
|
|
39
69
|
}
|
package/dist/index
DELETED
|
@@ -1,442 +0,0 @@
|
|
|
1
|
-
import { NodeSDK as q } from "@opentelemetry/sdk-node";
|
|
2
|
-
import { OTLPTraceExporter as z } from "@opentelemetry/exporter-trace-otlp-http";
|
|
3
|
-
import { resourceFromAttributes as j } from "@opentelemetry/resources";
|
|
4
|
-
import { ATTR_SERVICE_VERSION as U, ATTR_SERVICE_NAME as k } from "@opentelemetry/semantic-conventions";
|
|
5
|
-
import { SamplingDecision as f, TraceIdRatioBasedSampler as L, AlwaysOnSampler as B, BatchSpanProcessor as G } from "@opentelemetry/sdk-trace-base";
|
|
6
|
-
import { trace as W, TraceFlags as A, context as x, SpanKind as $, propagation as D, SpanStatusCode as Q } from "@opentelemetry/api";
|
|
7
|
-
import { readFileSync as K } from "node:fs";
|
|
8
|
-
import { getNodeAutoInstrumentations as X } from "@opentelemetry/auto-instrumentations-node";
|
|
9
|
-
import { UndiciInstrumentation as J } from "@opentelemetry/instrumentation-undici";
|
|
10
|
-
const Z = "deployment.environment.name", tt = [
|
|
11
|
-
"/health",
|
|
12
|
-
"/metrics",
|
|
13
|
-
"/readyz",
|
|
14
|
-
"/livez",
|
|
15
|
-
"/favicon.ico",
|
|
16
|
-
"/robots.txt",
|
|
17
|
-
"/sitemap.xml",
|
|
18
|
-
"/_next",
|
|
19
|
-
"/__nextjs_",
|
|
20
|
-
"/.well-known"
|
|
21
|
-
], et = [
|
|
22
|
-
".css",
|
|
23
|
-
".js",
|
|
24
|
-
".mjs",
|
|
25
|
-
".cjs",
|
|
26
|
-
".png",
|
|
27
|
-
".jpg",
|
|
28
|
-
".jpeg",
|
|
29
|
-
".gif",
|
|
30
|
-
".svg",
|
|
31
|
-
".ico",
|
|
32
|
-
".webp",
|
|
33
|
-
".avif",
|
|
34
|
-
".woff",
|
|
35
|
-
".woff2",
|
|
36
|
-
".ttf",
|
|
37
|
-
".eot",
|
|
38
|
-
".map",
|
|
39
|
-
".txt",
|
|
40
|
-
".xml"
|
|
41
|
-
], E = {
|
|
42
|
-
paths: tt,
|
|
43
|
-
extensions: et,
|
|
44
|
-
methods: ["HEAD", "OPTIONS"]
|
|
45
|
-
}, rt = (t) => t.map((e) => {
|
|
46
|
-
const r = e.trim().toLowerCase();
|
|
47
|
-
return r && (r.startsWith(".") ? r : `.${r}`);
|
|
48
|
-
}), st = (t) => t.replace(/[.+^${}()|[\]\\]/g, "\\$&"), b = (t, e) => {
|
|
49
|
-
if (t instanceof RegExp)
|
|
50
|
-
return t.test(e);
|
|
51
|
-
const r = t.trim();
|
|
52
|
-
if (!r) return !1;
|
|
53
|
-
if (r.includes("*")) {
|
|
54
|
-
const n = `^${st(r).replace(/\\\*\\\*/g, ".*").replace(/\\\*/g, "[^/]*")}$`;
|
|
55
|
-
return new RegExp(n).test(e);
|
|
56
|
-
}
|
|
57
|
-
return e === r ? !0 : r.endsWith("/") ? e.startsWith(r) : e.startsWith(`${r}/`) || e.startsWith(r);
|
|
58
|
-
}, nt = (t, e) => {
|
|
59
|
-
const r = e.toLowerCase();
|
|
60
|
-
return t.some((s) => s && r.endsWith(s));
|
|
61
|
-
}, ot = (t) => {
|
|
62
|
-
var o, n, i;
|
|
63
|
-
const e = (o = t == null ? void 0 : t.paths) != null && o.length ? t.paths : E.paths, r = (n = t == null ? void 0 : t.extensions) != null && n.length ? rt(t.extensions) : E.extensions, s = (i = t == null ? void 0 : t.methods) != null && i.length ? t.methods.map((a) => a.toUpperCase()) : E.methods;
|
|
64
|
-
return (a, u) => u && s.includes(u.toUpperCase()) ? !0 : a ? nt(r, a) ? !0 : e.some((c) => b(c, a)) : !1;
|
|
65
|
-
}, h = (t, e) => {
|
|
66
|
-
if (!t) return;
|
|
67
|
-
const r = t[e.toLowerCase()];
|
|
68
|
-
if (Array.isArray(r)) {
|
|
69
|
-
const s = r[0];
|
|
70
|
-
return typeof s == "string" ? s : void 0;
|
|
71
|
-
}
|
|
72
|
-
return typeof r == "string" ? r : void 0;
|
|
73
|
-
}, T = (t) => {
|
|
74
|
-
if (!t) return "";
|
|
75
|
-
try {
|
|
76
|
-
return t.startsWith("http://") || t.startsWith("https://") ? new URL(t).pathname : new URL(t, "http://localhost").pathname;
|
|
77
|
-
} catch {
|
|
78
|
-
return t.split("?")[0] || t;
|
|
79
|
-
}
|
|
80
|
-
}, O = /* @__PURE__ */ new WeakMap();
|
|
81
|
-
function it(t) {
|
|
82
|
-
const e = ot(t.ignore), r = (t.inspectionHeader ?? "x-inspection").toLowerCase(), s = (t.userTypeHeader ?? "x-telemetry-user-type").toLowerCase(), o = (t.requestStartHeader ?? "x-telemetry-start").toLowerCase();
|
|
83
|
-
return [
|
|
84
|
-
X({
|
|
85
|
-
"@opentelemetry/instrumentation-grpc": {
|
|
86
|
-
enabled: !1
|
|
87
|
-
},
|
|
88
|
-
"@opentelemetry/instrumentation-http": {
|
|
89
|
-
enabled: !0,
|
|
90
|
-
startIncomingSpanHook: (n) => {
|
|
91
|
-
const i = "headers" in n ? n.headers : void 0, a = h(i, r), u = h(i, s), c = h(i, o), d = "method" in n ? n.method : void 0, M = T("url" in n ? n.url : void 0), w = Number(c || Date.now()), m = {
|
|
92
|
-
"telemetry.request.start_time_ms": Number.isFinite(w) ? w : Date.now()
|
|
93
|
-
};
|
|
94
|
-
return M && (m["url.path"] = M), d && (m["http.request.method"] = d), a && (m["telemetry.request.inspection"] = !0, m["http.request.header.x-inspection"] = a), u && (m["enduser.type"] = u, m["telemetry.request.user_type"] = u), m;
|
|
95
|
-
},
|
|
96
|
-
requestHook: (n, i) => {
|
|
97
|
-
const a = "headers" in i ? i.headers : void 0, u = h(a, o), c = Number(u || Date.now());
|
|
98
|
-
O.set(n, Number.isFinite(c) ? c : Date.now());
|
|
99
|
-
},
|
|
100
|
-
responseHook: (n, i) => {
|
|
101
|
-
const a = "statusCode" in i ? i.statusCode : void 0;
|
|
102
|
-
typeof a == "number" && (n.setAttribute("http.response.status_code", a), n.setAttribute("telemetry.response.status_code", a), a >= 500 && n.setAttribute("telemetry.request.error", !0));
|
|
103
|
-
const u = O.get(n);
|
|
104
|
-
typeof u == "number" && n.setAttribute("telemetry.request.duration_ms", Date.now() - u);
|
|
105
|
-
},
|
|
106
|
-
ignoreIncomingRequestHook: (n) => {
|
|
107
|
-
const i = "url" in n ? n.url : void 0, a = T(i), u = "method" in n ? n.method : void 0;
|
|
108
|
-
return e(a, u);
|
|
109
|
-
},
|
|
110
|
-
ignoreOutgoingRequestHook: (n) => {
|
|
111
|
-
const i = typeof n == "string" ? n : n.path || "";
|
|
112
|
-
return e(T(i));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}),
|
|
116
|
-
new J()
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
const R = (t) => {
|
|
120
|
-
if (typeof t == "string") return t;
|
|
121
|
-
if (Array.isArray(t)) {
|
|
122
|
-
const e = t[0];
|
|
123
|
-
return typeof e == "string" ? e : void 0;
|
|
124
|
-
}
|
|
125
|
-
}, H = (t) => {
|
|
126
|
-
if (typeof t == "number") return t;
|
|
127
|
-
if (typeof t == "string") {
|
|
128
|
-
const e = Number(t);
|
|
129
|
-
return Number.isFinite(e) ? e : void 0;
|
|
130
|
-
}
|
|
131
|
-
if (Array.isArray(t)) {
|
|
132
|
-
const e = t[0];
|
|
133
|
-
return H(e);
|
|
134
|
-
}
|
|
135
|
-
}, l = (t, e) => {
|
|
136
|
-
for (const r of e)
|
|
137
|
-
if (r in t)
|
|
138
|
-
return t[r];
|
|
139
|
-
}, V = (t) => {
|
|
140
|
-
const e = l(t, ["url.path", "http.target", "http.route"]), r = l(t, ["http.request.method", "http.method"]), s = l(t, ["enduser.type", "telemetry.request.user_type"]), o = l(t, [
|
|
141
|
-
"http.response.status_code",
|
|
142
|
-
"http.status_code",
|
|
143
|
-
"telemetry.response.status_code"
|
|
144
|
-
]), n = l(t, [
|
|
145
|
-
"telemetry.request.inspection",
|
|
146
|
-
"http.request.header.x-inspection",
|
|
147
|
-
"x-inspection"
|
|
148
|
-
]), i = n === !0 || n === "true" || n === "1" || n === 1;
|
|
149
|
-
return {
|
|
150
|
-
path: R(e),
|
|
151
|
-
method: R(r),
|
|
152
|
-
userType: R(s),
|
|
153
|
-
statusCode: H(o),
|
|
154
|
-
inspection: i
|
|
155
|
-
};
|
|
156
|
-
}, I = (t, e) => !t || !(e != null && e.length) ? !1 : e.some((r) => r.toLowerCase() === t.toLowerCase()), at = (t, e) => !t || !(e != null && e.length) ? !1 : e.some((r) => b(r, t)), ut = (t, e) => {
|
|
157
|
-
const r = t.when;
|
|
158
|
-
if (!r) return !0;
|
|
159
|
-
if (r.inspection !== void 0 && r.inspection !== e.inspection || r.path && !at(e.path, r.path) || r.method && !I(e.method, r.method) || r.userType && !I(e.userType, r.userType))
|
|
160
|
-
return !1;
|
|
161
|
-
if (r.statusCode && typeof e.statusCode == "number") {
|
|
162
|
-
if (!r.statusCode.includes(e.statusCode))
|
|
163
|
-
return !1;
|
|
164
|
-
} else if (r.statusCode && r.statusCode.length)
|
|
165
|
-
return !1;
|
|
166
|
-
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));
|
|
167
|
-
}, S = (t) => Math.max(0, Math.min(1, t)), v = (t, e, r) => {
|
|
168
|
-
if (!(t != null && t.length)) return S(r);
|
|
169
|
-
for (const s of t)
|
|
170
|
-
if (ut(s, e))
|
|
171
|
-
return S(s.ratio);
|
|
172
|
-
return S(r);
|
|
173
|
-
}, P = /* @__PURE__ */ new Map(), F = (t) => {
|
|
174
|
-
if (t <= 0)
|
|
175
|
-
return new L(0);
|
|
176
|
-
if (t >= 1)
|
|
177
|
-
return new B();
|
|
178
|
-
const e = Number(t.toFixed(6)), r = P.get(e);
|
|
179
|
-
if (r) return r;
|
|
180
|
-
const s = new L(e);
|
|
181
|
-
return P.set(e, s), s;
|
|
182
|
-
}, ct = (t) => ({
|
|
183
|
-
shouldSample(e, r, s, o, n, i) {
|
|
184
|
-
const a = W.getSpanContext(e);
|
|
185
|
-
if (a)
|
|
186
|
-
return (a.traceFlags & A.SAMPLED) === A.SAMPLED ? { decision: f.RECORD_AND_SAMPLED } : { decision: f.NOT_RECORD };
|
|
187
|
-
const u = t.getConfig(), c = V(n);
|
|
188
|
-
if (c.inspection)
|
|
189
|
-
return { decision: f.RECORD_AND_SAMPLED };
|
|
190
|
-
const d = v(
|
|
191
|
-
u.samplingRules,
|
|
192
|
-
c,
|
|
193
|
-
u.defaultSamplingRatio ?? 0.01
|
|
194
|
-
);
|
|
195
|
-
return F(d).shouldSample(e, r, s, o, n, i);
|
|
196
|
-
},
|
|
197
|
-
toString: () => "RuleBasedSampler"
|
|
198
|
-
}), mt = (t, e, r) => {
|
|
199
|
-
const s = t.getConfig(), o = V(e);
|
|
200
|
-
if (o.inspection) return !0;
|
|
201
|
-
const n = v(
|
|
202
|
-
s.samplingRules,
|
|
203
|
-
o,
|
|
204
|
-
s.defaultSamplingRatio ?? 0.01
|
|
205
|
-
);
|
|
206
|
-
return F(n).shouldSample(
|
|
207
|
-
x.active(),
|
|
208
|
-
r,
|
|
209
|
-
"export",
|
|
210
|
-
$.INTERNAL,
|
|
211
|
-
e,
|
|
212
|
-
[]
|
|
213
|
-
).decision === f.RECORD_AND_SAMPLED;
|
|
214
|
-
}, pt = (t, e) => ({
|
|
215
|
-
export: (r, s) => {
|
|
216
|
-
const o = r.filter(
|
|
217
|
-
(n) => mt(e, n.attributes, n.spanContext().traceId)
|
|
218
|
-
);
|
|
219
|
-
if (!o.length) {
|
|
220
|
-
s({ code: 0 });
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
t.export(o, s);
|
|
224
|
-
},
|
|
225
|
-
shutdown: () => t.shutdown(),
|
|
226
|
-
forceFlush: () => {
|
|
227
|
-
var r;
|
|
228
|
-
return ((r = t.forceFlush) == null ? void 0 : r.call(t)) ?? Promise.resolve();
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
let g, p;
|
|
232
|
-
const _ = (t) => Array.from(new Set(t)), y = (t) => (t == null ? void 0 : t.split(",").map((e) => e.trim()).filter(Boolean)) ?? [], lt = (t) => {
|
|
233
|
-
if (!t) return;
|
|
234
|
-
const e = {};
|
|
235
|
-
for (const r of t.split(",")) {
|
|
236
|
-
const [s, ...o] = r.split("="), n = s == null ? void 0 : s.trim();
|
|
237
|
-
n && (e[n] = o.join("=").trim());
|
|
238
|
-
}
|
|
239
|
-
return e;
|
|
240
|
-
}, C = (t) => {
|
|
241
|
-
if (t)
|
|
242
|
-
try {
|
|
243
|
-
return JSON.parse(t);
|
|
244
|
-
} catch {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
}, dt = (t) => {
|
|
248
|
-
if (t)
|
|
249
|
-
try {
|
|
250
|
-
const e = K(t, "utf8");
|
|
251
|
-
return C(e);
|
|
252
|
-
} catch {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
}, Y = (t, e) => {
|
|
256
|
-
const r = _([...(t == null ? void 0 : t.paths) ?? [], ...(e == null ? void 0 : e.paths) ?? []]), s = _([
|
|
257
|
-
...(t == null ? void 0 : t.extensions) ?? [],
|
|
258
|
-
...(e == null ? void 0 : e.extensions) ?? []
|
|
259
|
-
]), o = _([...(t == null ? void 0 : t.methods) ?? [], ...(e == null ? void 0 : e.methods) ?? []]);
|
|
260
|
-
return {
|
|
261
|
-
paths: r.length ? r : void 0,
|
|
262
|
-
extensions: s.length ? s : void 0,
|
|
263
|
-
methods: o.length ? o : void 0
|
|
264
|
-
};
|
|
265
|
-
}, ht = (t) => {
|
|
266
|
-
if (t != null && t.length)
|
|
267
|
-
return t.map((e) => ({
|
|
268
|
-
...e,
|
|
269
|
-
ratio: Number.isFinite(e.ratio) ? Math.max(0, Math.min(1, e.ratio)) : 0
|
|
270
|
-
})).filter((e) => e.ratio >= 0);
|
|
271
|
-
}, ft = (t = process.env) => {
|
|
272
|
-
const e = dt(t.TELEMETRY_CONFIG_FILE), r = y(t.TELEMETRY_IGNORE_PATHS), s = y(t.TELEMETRY_IGNORE_EXTENSIONS), o = y(t.TELEMETRY_IGNORE_METHODS), n = C(t.TELEMETRY_SAMPLING_RULES), i = typeof (e == null ? void 0 : e.samplingRules) == "string" ? C(e.samplingRules) : e == null ? void 0 : e.samplingRules, a = {
|
|
273
|
-
serviceName: t.OTEL_SERVICE_NAME || t.TELEMETRY_SERVICE_NAME,
|
|
274
|
-
serviceVersion: t.OTEL_SERVICE_VERSION || t.TELEMETRY_SERVICE_VERSION,
|
|
275
|
-
environment: t.OTEL_RESOURCE_ATTRIBUTES || t.TELEMETRY_ENVIRONMENT,
|
|
276
|
-
defaultSamplingRatio: t.TELEMETRY_SAMPLING_RATIO ? Number(t.TELEMETRY_SAMPLING_RATIO) : void 0,
|
|
277
|
-
url: t.OTEL_EXPORTER_OTLP_ENDPOINT || t.TELEMETRY_OTLP_ENDPOINT,
|
|
278
|
-
headers: lt(t.OTEL_EXPORTER_OTLP_HEADERS || t.TELEMETRY_OTLP_HEADERS),
|
|
279
|
-
inspectionHeader: t.TELEMETRY_INSPECTION_HEADER,
|
|
280
|
-
userTypeHeader: t.TELEMETRY_USER_TYPE_HEADER,
|
|
281
|
-
requestStartHeader: t.TELEMETRY_REQUEST_START_HEADER,
|
|
282
|
-
samplingRules: n || i,
|
|
283
|
-
ignore: r.length || s.length || o.length ? {
|
|
284
|
-
paths: r.length ? r : void 0,
|
|
285
|
-
extensions: s.length ? s : void 0,
|
|
286
|
-
methods: o.length ? o : void 0
|
|
287
|
-
} : void 0
|
|
288
|
-
};
|
|
289
|
-
return e && typeof e == "object" ? { ...e, ...a } : a;
|
|
290
|
-
}, Et = (t) => {
|
|
291
|
-
if (!t) return process.env.NODE_ENV || "development";
|
|
292
|
-
if (t.includes("deployment.environment")) {
|
|
293
|
-
const r = t.split(",").find((o) => o.includes("deployment.environment"));
|
|
294
|
-
if (!r) return t;
|
|
295
|
-
const [, s] = r.split("=");
|
|
296
|
-
return (s == null ? void 0 : s.trim()) || t;
|
|
297
|
-
}
|
|
298
|
-
return t;
|
|
299
|
-
}, gt = (t, e) => {
|
|
300
|
-
var s, o;
|
|
301
|
-
const r = [
|
|
302
|
-
{ name: "inspection", ratio: 1, when: { inspection: !0 } },
|
|
303
|
-
{ name: "error", ratio: 1, when: { minStatusCode: 500 } }
|
|
304
|
-
];
|
|
305
|
-
if ((s = t == null ? void 0 : t.criticalPaths) != null && s.length && r.push({
|
|
306
|
-
name: "critical-path",
|
|
307
|
-
ratio: 1,
|
|
308
|
-
when: { path: t.criticalPaths }
|
|
309
|
-
}), (o = t == null ? void 0 : t.criticalUserTypes) != null && o.length && r.push({
|
|
310
|
-
name: "critical-user",
|
|
311
|
-
ratio: 1,
|
|
312
|
-
when: { userType: t.criticalUserTypes }
|
|
313
|
-
}), t != null && t.pathSampling)
|
|
314
|
-
for (const [n, i] of Object.entries(t.pathSampling))
|
|
315
|
-
r.push({
|
|
316
|
-
name: `path:${n}`,
|
|
317
|
-
ratio: i,
|
|
318
|
-
when: { path: [n] }
|
|
319
|
-
});
|
|
320
|
-
if (t != null && t.userTypeSampling)
|
|
321
|
-
for (const [n, i] of Object.entries(t.userTypeSampling))
|
|
322
|
-
r.push({
|
|
323
|
-
name: `user:${n}`,
|
|
324
|
-
ratio: i,
|
|
325
|
-
when: { userType: [n] }
|
|
326
|
-
});
|
|
327
|
-
return r.push({ name: "default", ratio: e }), r;
|
|
328
|
-
}, N = (t = {}, e = process.env) => {
|
|
329
|
-
const s = { ...ft(e), ...t }, o = Et(s.environment), n = Y(E, s.ignore), i = typeof s.defaultSamplingRatio == "number" ? Math.max(0, Math.min(1, s.defaultSamplingRatio)) : 0.01, a = ht(s.samplingRules) ?? gt(s.layeredSampling, i);
|
|
330
|
-
return {
|
|
331
|
-
...s,
|
|
332
|
-
serviceName: s.serviceName || "unknown-service",
|
|
333
|
-
serviceVersion: s.serviceVersion,
|
|
334
|
-
environment: o,
|
|
335
|
-
defaultSamplingRatio: i,
|
|
336
|
-
ignore: n,
|
|
337
|
-
samplingRules: a,
|
|
338
|
-
inspectionHeader: s.inspectionHeader ?? "x-inspection",
|
|
339
|
-
userTypeHeader: s.userTypeHeader ?? "x-telemetry-user-type",
|
|
340
|
-
requestStartHeader: s.requestStartHeader ?? "x-telemetry-start",
|
|
341
|
-
scheduledDelayMillis: s.scheduledDelayMillis ?? 1e3,
|
|
342
|
-
maxQueueSize: s.maxQueueSize ?? 2048,
|
|
343
|
-
maxExportBatchSize: s.maxExportBatchSize ?? 512,
|
|
344
|
-
exporterTimeoutMillis: s.exporterTimeoutMillis ?? 3e4
|
|
345
|
-
};
|
|
346
|
-
}, Tt = (t) => {
|
|
347
|
-
let e = N(t);
|
|
348
|
-
return {
|
|
349
|
-
getConfig: () => e,
|
|
350
|
-
updateConfig: (r) => {
|
|
351
|
-
e = N({
|
|
352
|
-
...e,
|
|
353
|
-
...r,
|
|
354
|
-
ignore: Y(e.ignore, r.ignore)
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
}, Rt = (t) => t[0] * 1e3 + t[1] / 1e6, St = (t, e) => {
|
|
359
|
-
for (const r of e) {
|
|
360
|
-
const s = t.attributes[r];
|
|
361
|
-
if (typeof s == "number") return s;
|
|
362
|
-
}
|
|
363
|
-
}, _t = (t) => {
|
|
364
|
-
const e = t.events.find((s) => s.name === "exception");
|
|
365
|
-
if (!(e != null && e.attributes)) return;
|
|
366
|
-
const r = e.attributes["exception.message"];
|
|
367
|
-
return typeof r == "string" ? r : void 0;
|
|
368
|
-
}, yt = () => ({
|
|
369
|
-
onStart: () => {
|
|
370
|
-
},
|
|
371
|
-
onEnd: (t) => {
|
|
372
|
-
const e = Rt(t.duration);
|
|
373
|
-
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));
|
|
374
|
-
const r = St(t, [
|
|
375
|
-
"http.response.status_code",
|
|
376
|
-
"http.status_code",
|
|
377
|
-
"telemetry.response.status_code"
|
|
378
|
-
]);
|
|
379
|
-
if (typeof r == "number" && (t.attributes["telemetry.response.status_code"] = r), t.status.code === Q.ERROR || typeof r == "number" && r >= 500) {
|
|
380
|
-
t.attributes["telemetry.request.error"] = !0;
|
|
381
|
-
const o = t.status.message || _t(t);
|
|
382
|
-
o && (t.attributes["telemetry.request.error_message"] = o);
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
shutdown: () => Promise.resolve(),
|
|
386
|
-
forceFlush: () => Promise.resolve()
|
|
387
|
-
}), Pt = async (t) => {
|
|
388
|
-
const e = N(t);
|
|
389
|
-
p = Tt(e);
|
|
390
|
-
const r = j({
|
|
391
|
-
[k]: e.serviceName,
|
|
392
|
-
[U]: e.serviceVersion || "1.0.0",
|
|
393
|
-
[Z]: e.environment || "development"
|
|
394
|
-
}), s = new z(e), o = pt(s, p), n = [
|
|
395
|
-
yt(),
|
|
396
|
-
new G(o, {
|
|
397
|
-
scheduledDelayMillis: e.scheduledDelayMillis,
|
|
398
|
-
maxQueueSize: e.maxQueueSize,
|
|
399
|
-
maxExportBatchSize: e.maxExportBatchSize,
|
|
400
|
-
exportTimeoutMillis: e.exporterTimeoutMillis
|
|
401
|
-
})
|
|
402
|
-
];
|
|
403
|
-
g = new q({
|
|
404
|
-
serviceName: e.serviceName,
|
|
405
|
-
resource: r,
|
|
406
|
-
spanProcessors: n,
|
|
407
|
-
sampler: ct(p),
|
|
408
|
-
instrumentations: it(e)
|
|
409
|
-
});
|
|
410
|
-
try {
|
|
411
|
-
await g.start();
|
|
412
|
-
} catch (i) {
|
|
413
|
-
console.warn("Telemetry start failed:", i);
|
|
414
|
-
}
|
|
415
|
-
return p;
|
|
416
|
-
}, Dt = (t) => {
|
|
417
|
-
p == null || p.updateConfig(t);
|
|
418
|
-
}, bt = (t) => (D.inject(x.active(), t), t), Ht = (t = fetch) => async (e, r) => {
|
|
419
|
-
const s = (r == null ? void 0 : r.headers) ?? (e instanceof Request ? e.headers : void 0), o = new Headers(s);
|
|
420
|
-
return D.inject(x.active(), o, {
|
|
421
|
-
set: (n, i, a) => {
|
|
422
|
-
n.set(i, a);
|
|
423
|
-
}
|
|
424
|
-
}), t(e, { ...r, headers: o });
|
|
425
|
-
}, Vt = async () => {
|
|
426
|
-
g && await g.shutdown();
|
|
427
|
-
};
|
|
428
|
-
export {
|
|
429
|
-
V as buildSamplingContextFromAttributes,
|
|
430
|
-
ot as createIgnoreMatcher,
|
|
431
|
-
Ht as createPropagatingFetch,
|
|
432
|
-
Tt as createTelemetryRuntime,
|
|
433
|
-
E as defaultIgnoreConfig,
|
|
434
|
-
bt as injectTraceHeaders,
|
|
435
|
-
ft as loadTelemetryConfigFromEnv,
|
|
436
|
-
ut as matchSamplingRule,
|
|
437
|
-
v as resolveSamplingRatio,
|
|
438
|
-
N as resolveTelemetryConfig,
|
|
439
|
-
Vt as shutdownTelemetry,
|
|
440
|
-
Pt as startTelemetry,
|
|
441
|
-
Dt as updateTelemetryConfig
|
|
442
|
-
};
|