@burdenoff/be-sdk 2026.1111.1 → 2026.1112.1
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/bun-runtime-metrics-CPy5D6NT.js +58 -0
- package/dist/bun-runtime-metrics-CPy5D6NT.js.map +1 -0
- package/dist/{sdk-B62itAH1.js → sdk-DqIqX-Ue.js} +33 -2
- package/dist/sdk-DqIqX-Ue.js.map +1 -0
- package/dist/server/index.js +2 -3
- package/dist/server/index.js.map +1 -1
- package/dist/telemetry/index.js +8 -4
- package/dist/telemetry/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/sdk-B62itAH1.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/telemetry/bun-runtime-metrics.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime metrics that stall a Bun process (BOFF-12287).
|
|
4
|
+
*
|
|
5
|
+
* `v8.getHeapStatistics()` and `v8.getHeapSpaceStatistics()` are cheap under
|
|
6
|
+
* Node. Under Bun 1.4 they walk the whole JavaScriptCore heap synchronously:
|
|
7
|
+
* about 0.44 s per call on a 3M-object heap, during which the process serves
|
|
8
|
+
* nothing. Two collectors that be-sdk services load call one of them on a
|
|
9
|
+
* timer, so every Bun 1.4 service paid a recurring block sized to its heap:
|
|
10
|
+
*
|
|
11
|
+
* - prom-client's default `nodejs_heap_space_size_*_bytes` gauges, on every
|
|
12
|
+
* Prometheus scrape. Bun 1.3 threw `ERR_NOT_IMPLEMENTED` and prom-client
|
|
13
|
+
* skipped them; Bun 1.4 implements the call, so from the Bun 1.4.4 upgrade
|
|
14
|
+
* on the scrape itself became the block (wspace-int-gateway: 0.01 s →
|
|
15
|
+
* 0.5–0.76 s per scrape). Handled here.
|
|
16
|
+
* - the OpenTelemetry `runtime-node` instrumentation, on every 60 s OTLP
|
|
17
|
+
* metric export. Handled in `sdk.ts` (`autoInstrumentationConfig`).
|
|
18
|
+
*
|
|
19
|
+
* Heap size stays visible through prom-client's `nodejs_heap_size_*_bytes`,
|
|
20
|
+
* which reads `process.memoryUsage()`, and event-loop lag through
|
|
21
|
+
* `nodejs_eventloop_lag_*`. No dashboard or alert reads the dropped series.
|
|
22
|
+
*/
|
|
23
|
+
/** True when the process runs on Bun (also inside a `bun build --compile` binary). */
|
|
24
|
+
function isBunRuntime() {
|
|
25
|
+
return typeof process.versions["bun"] === "string";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* prom-client default metrics that are not served under Bun. The `total` gauge
|
|
29
|
+
* carries the collect callback that calls `v8.getHeapSpaceStatistics()`; the
|
|
30
|
+
* other two are only filled by it, so all three go.
|
|
31
|
+
*/
|
|
32
|
+
const BUN_HEAP_WALK_DEFAULT_METRICS = [
|
|
33
|
+
"nodejs_heap_space_size_total_bytes",
|
|
34
|
+
"nodejs_heap_space_size_used_bytes",
|
|
35
|
+
"nodejs_heap_space_size_available_bytes"
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Registers prom-client's default metrics on `prom.register` and, under Bun,
|
|
39
|
+
* removes the heap-space gauges again.
|
|
40
|
+
*
|
|
41
|
+
* Safe to call on every scrape: prom-client throws on the first metric name
|
|
42
|
+
* that is already registered, before it reaches the heap-space gauges, and the
|
|
43
|
+
* removal is a map delete. Calling it again also removes the gauges when the
|
|
44
|
+
* service registered the default metrics on the same registry itself.
|
|
45
|
+
*
|
|
46
|
+
* prom-client probes `v8.getHeapSpaceStatistics()` once when it registers the
|
|
47
|
+
* defaults, so a Bun process still pays one heap walk, on its first scrape.
|
|
48
|
+
*/
|
|
49
|
+
function collectPromDefaultMetrics(prom, bun = isBunRuntime()) {
|
|
50
|
+
try {
|
|
51
|
+
prom.collectDefaultMetrics({ register: prom.register });
|
|
52
|
+
} catch {}
|
|
53
|
+
if (!bun) return;
|
|
54
|
+
for (const name of BUN_HEAP_WALK_DEFAULT_METRICS) prom.register.removeSingleMetric(name);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { isBunRuntime as n, collectPromDefaultMetrics as t };
|
|
58
|
+
//# sourceMappingURL=bun-runtime-metrics-CPy5D6NT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun-runtime-metrics-CPy5D6NT.js","names":[],"sources":["../src/telemetry/bun-runtime-metrics.ts"],"sourcesContent":["/**\n * Runtime metrics that stall a Bun process (BOFF-12287).\n *\n * `v8.getHeapStatistics()` and `v8.getHeapSpaceStatistics()` are cheap under\n * Node. Under Bun 1.4 they walk the whole JavaScriptCore heap synchronously:\n * about 0.44 s per call on a 3M-object heap, during which the process serves\n * nothing. Two collectors that be-sdk services load call one of them on a\n * timer, so every Bun 1.4 service paid a recurring block sized to its heap:\n *\n * - prom-client's default `nodejs_heap_space_size_*_bytes` gauges, on every\n * Prometheus scrape. Bun 1.3 threw `ERR_NOT_IMPLEMENTED` and prom-client\n * skipped them; Bun 1.4 implements the call, so from the Bun 1.4.4 upgrade\n * on the scrape itself became the block (wspace-int-gateway: 0.01 s →\n * 0.5–0.76 s per scrape). Handled here.\n * - the OpenTelemetry `runtime-node` instrumentation, on every 60 s OTLP\n * metric export. Handled in `sdk.ts` (`autoInstrumentationConfig`).\n *\n * Heap size stays visible through prom-client's `nodejs_heap_size_*_bytes`,\n * which reads `process.memoryUsage()`, and event-loop lag through\n * `nodejs_eventloop_lag_*`. No dashboard or alert reads the dropped series.\n */\n\n/** True when the process runs on Bun (also inside a `bun build --compile` binary). */\nexport function isBunRuntime(): boolean {\n return typeof process.versions['bun'] === 'string';\n}\n\n/**\n * prom-client default metrics that are not served under Bun. The `total` gauge\n * carries the collect callback that calls `v8.getHeapSpaceStatistics()`; the\n * other two are only filled by it, so all three go.\n */\nexport const BUN_HEAP_WALK_DEFAULT_METRICS: readonly string[] = [\n 'nodejs_heap_space_size_total_bytes',\n 'nodejs_heap_space_size_used_bytes',\n 'nodejs_heap_space_size_available_bytes',\n];\n\n/** The part of the `prom-client` module that {@link collectPromDefaultMetrics} uses. */\nexport interface PromDefaultMetricsClient {\n register: { removeSingleMetric: (name: string) => void };\n collectDefaultMetrics: (opts?: Record<string, unknown>) => void;\n}\n\n/**\n * Registers prom-client's default metrics on `prom.register` and, under Bun,\n * removes the heap-space gauges again.\n *\n * Safe to call on every scrape: prom-client throws on the first metric name\n * that is already registered, before it reaches the heap-space gauges, and the\n * removal is a map delete. Calling it again also removes the gauges when the\n * service registered the default metrics on the same registry itself.\n *\n * prom-client probes `v8.getHeapSpaceStatistics()` once when it registers the\n * defaults, so a Bun process still pays one heap walk, on its first scrape.\n */\nexport function collectPromDefaultMetrics(prom: PromDefaultMetricsClient, bun: boolean = isBunRuntime()): void {\n try {\n prom.collectDefaultMetrics({ register: prom.register });\n } catch {\n // Already registered on this registry: prom-client rejects duplicate names.\n }\n if (!bun) return;\n for (const name of BUN_HEAP_WALK_DEFAULT_METRICS) prom.register.removeSingleMetric(name);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,eAAwB;CACtC,OAAO,OAAO,QAAQ,SAAS,WAAW;AAC5C;;;;;;AAOA,MAAa,gCAAmD;CAC9D;CACA;CACA;AACF;;;;;;;;;;;;;AAoBA,SAAgB,0BAA0B,MAAgC,MAAe,aAAa,GAAS;CAC7G,IAAI;EACF,KAAK,sBAAsB,EAAE,UAAU,KAAK,SAAS,CAAC;CACxD,QAAQ,CAER;CACA,IAAI,CAAC,KAAK;CACV,KAAK,MAAM,QAAQ,+BAA+B,KAAK,SAAS,mBAAmB,IAAI;AACzF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { t as importOptionalPeer } from "./import-optional-peer-B82VYxeX.js";
|
|
2
|
+
import { n as isBunRuntime } from "./bun-runtime-metrics-CPy5D6NT.js";
|
|
2
3
|
|
|
3
4
|
// src/telemetry/sdk.ts
|
|
4
5
|
/**
|
|
@@ -9,6 +10,33 @@ import { t as importOptionalPeer } from "./import-optional-peer-B82VYxeX.js";
|
|
|
9
10
|
* still compile and run. The function resolves `undefined` when the SDK
|
|
10
11
|
* isn't available, letting `bootstrapTelemetry` fall back gracefully.
|
|
11
12
|
*/
|
|
13
|
+
/** The name `OTEL_NODE_{ENABLED,DISABLED}_INSTRUMENTATIONS` use for `@opentelemetry/instrumentation-runtime-node`. */
|
|
14
|
+
const RUNTIME_NODE_INSTRUMENTATION = "runtime-node";
|
|
15
|
+
/** True when a comma-separated `OTEL_NODE_*_INSTRUMENTATIONS` value names `name` (parsed as auto-instrumentations-node does). */
|
|
16
|
+
const listsInstrumentation = (value, name) => value !== void 0 && value.split(",").some((entry) => entry.trim() === name);
|
|
17
|
+
/**
|
|
18
|
+
* The config be-sdk hands to `getNodeAutoInstrumentations`.
|
|
19
|
+
*
|
|
20
|
+
* - `instrumentation-fs` is always off.
|
|
21
|
+
* - `instrumentation-runtime-node` is off under Bun unless
|
|
22
|
+
* `OTEL_NODE_ENABLED_INSTRUMENTATIONS` names `runtime-node` (BOFF-12287). On
|
|
23
|
+
* every 60 s OTLP metric export it reads `v8.getHeapSpaceStatistics()`,
|
|
24
|
+
* which Bun implements as a synchronous walk of the whole heap: a 0.1–1.4 s
|
|
25
|
+
* block once a minute on the prod gateways, during which no request is
|
|
26
|
+
* served. Event-loop lag stays visible through prom-client's
|
|
27
|
+
* `nodejs_eventloop_lag_*`. Dropped: the OTel `v8js_*`,
|
|
28
|
+
* `nodejs_eventloop_delay_*`, `nodejs_eventloop_utilization_*` and
|
|
29
|
+
* `nodejs_eventloop_time_*` series, which no dashboard or alert reads.
|
|
30
|
+
*
|
|
31
|
+
* auto-instrumentations-node lets a programmatic `enabled: false` win over
|
|
32
|
+
* both env vars, so the opt-in has to be checked here. Under Node nothing
|
|
33
|
+
* changes: the env vars keep their usual meaning.
|
|
34
|
+
*/
|
|
35
|
+
function autoInstrumentationConfig(env = process.env, bun = isBunRuntime()) {
|
|
36
|
+
const config = { "@opentelemetry/instrumentation-fs": { enabled: false } };
|
|
37
|
+
if (bun && !listsInstrumentation(env["OTEL_NODE_ENABLED_INSTRUMENTATIONS"], RUNTIME_NODE_INSTRUMENTATION)) config["@opentelemetry/instrumentation-runtime-node"] = { enabled: false };
|
|
38
|
+
return config;
|
|
39
|
+
}
|
|
12
40
|
const isThenable = (value) => {
|
|
13
41
|
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
14
42
|
};
|
|
@@ -66,8 +94,11 @@ async function createOtelSdk(cfg) {
|
|
|
66
94
|
console.log("[sdk] importing @opentelemetry/auto-instrumentations-node...");
|
|
67
95
|
let autoInstrumentations;
|
|
68
96
|
try {
|
|
69
|
-
|
|
97
|
+
const auto = await load("@opentelemetry/auto-instrumentations-node");
|
|
98
|
+
const instrumentationConfig = autoInstrumentationConfig();
|
|
99
|
+
autoInstrumentations = auto.getNodeAutoInstrumentations(instrumentationConfig);
|
|
70
100
|
console.log("[sdk] auto-instrumentations loaded");
|
|
101
|
+
if (instrumentationConfig["@opentelemetry/instrumentation-runtime-node"]?.enabled === false) console.log("[sdk] runtime-node instrumentation off under Bun (its heap statistics stall the event loop); list runtime-node in OTEL_NODE_ENABLED_INSTRUMENTATIONS to turn it on");
|
|
71
102
|
} catch {
|
|
72
103
|
autoInstrumentations = void 0;
|
|
73
104
|
console.log("[sdk] auto-instrumentations not available (non-fatal)");
|
|
@@ -122,4 +153,4 @@ async function createOtelSdk(cfg) {
|
|
|
122
153
|
}
|
|
123
154
|
|
|
124
155
|
export { createOtelSdk };
|
|
125
|
-
//# sourceMappingURL=sdk-
|
|
156
|
+
//# sourceMappingURL=sdk-DqIqX-Ue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-DqIqX-Ue.js","names":[],"sources":["../src/telemetry/sdk.ts"],"sourcesContent":["/**\n * Thin wrapper that initializes `@opentelemetry/sdk-node` with the\n * OTLPTrace + OTLPMetric exporters and standard auto-instrumentations.\n *\n * All imports are dynamic so services that haven't installed sdk-node\n * still compile and run. The function resolves `undefined` when the SDK\n * isn't available, letting `bootstrapTelemetry` fall back gracefully.\n */\nimport { importOptionalPeer } from '../utils/import-optional-peer.js';\nimport { isBunRuntime } from './bun-runtime-metrics.js';\nimport type { TelemetryIdGenerator } from './id-generator.js';\nimport type { Boundary, Env } from './index.js';\n\nexport interface OtelSdkConfig {\n serviceName: string;\n serviceVersion: string;\n boundary: Boundary;\n module?: string;\n env: Env;\n otlpEndpoint: string;\n sampleRatio: number;\n /**\n * Optional trace/span id generator handed to NodeSDK's tracer provider.\n * Omitted means the SDK's default random generator.\n */\n idGenerator?: TelemetryIdGenerator;\n /**\n * Pre-loaded OpenTelemetry packages, keyed by package name. A package found\n * here is used as is; any other one is loaded at runtime from the consumer's\n * `node_modules` through `importOptionalPeer`. A service built with\n * `bun build --compile` has no `node_modules` at runtime, so it imports the\n * packages statically and hands them in here.\n */\n modules?: OtelModules;\n}\n\n/** The OpenTelemetry packages `createOtelSdk` can load. */\nexport type OtelPeerPackage =\n | '@opentelemetry/api'\n | '@opentelemetry/auto-instrumentations-node'\n | '@opentelemetry/exporter-metrics-otlp-http'\n | '@opentelemetry/exporter-trace-otlp-http'\n | '@opentelemetry/resources'\n | '@opentelemetry/sdk-metrics'\n | '@opentelemetry/sdk-node'\n | '@opentelemetry/sdk-trace-base'\n | '@opentelemetry/semantic-conventions';\n\n/** Module namespaces injected in place of runtime imports (see `OtelSdkConfig.modules`). */\nexport type OtelModules = Partial<Record<OtelPeerPackage, unknown>>;\n\nexport interface OtelSdkHandle {\n shutdown: () => Promise<void>;\n metricsEnabled: boolean;\n metricsDropReason?: string;\n}\n\n/** Per-instrumentation config handed to `getNodeAutoInstrumentations`, keyed by package name. */\nexport type AutoInstrumentationConfig = Record<string, { enabled: boolean }>;\n\n/** The name `OTEL_NODE_{ENABLED,DISABLED}_INSTRUMENTATIONS` use for `@opentelemetry/instrumentation-runtime-node`. */\nconst RUNTIME_NODE_INSTRUMENTATION = 'runtime-node';\n\n/** True when a comma-separated `OTEL_NODE_*_INSTRUMENTATIONS` value names `name` (parsed as auto-instrumentations-node does). */\nconst listsInstrumentation = (value: string | undefined, name: string): boolean =>\n value !== undefined && value.split(',').some((entry) => entry.trim() === name);\n\n/**\n * The config be-sdk hands to `getNodeAutoInstrumentations`.\n *\n * - `instrumentation-fs` is always off.\n * - `instrumentation-runtime-node` is off under Bun unless\n * `OTEL_NODE_ENABLED_INSTRUMENTATIONS` names `runtime-node` (BOFF-12287). On\n * every 60 s OTLP metric export it reads `v8.getHeapSpaceStatistics()`,\n * which Bun implements as a synchronous walk of the whole heap: a 0.1–1.4 s\n * block once a minute on the prod gateways, during which no request is\n * served. Event-loop lag stays visible through prom-client's\n * `nodejs_eventloop_lag_*`. Dropped: the OTel `v8js_*`,\n * `nodejs_eventloop_delay_*`, `nodejs_eventloop_utilization_*` and\n * `nodejs_eventloop_time_*` series, which no dashboard or alert reads.\n *\n * auto-instrumentations-node lets a programmatic `enabled: false` win over\n * both env vars, so the opt-in has to be checked here. Under Node nothing\n * changes: the env vars keep their usual meaning.\n */\nexport function autoInstrumentationConfig(\n env: Readonly<Record<string, string | undefined>> = process.env,\n bun: boolean = isBunRuntime()\n): AutoInstrumentationConfig {\n const config: AutoInstrumentationConfig = {\n '@opentelemetry/instrumentation-fs': { enabled: false },\n };\n if (bun && !listsInstrumentation(env['OTEL_NODE_ENABLED_INSTRUMENTATIONS'], RUNTIME_NODE_INSTRUMENTATION)) {\n config['@opentelemetry/instrumentation-runtime-node'] = { enabled: false };\n }\n return config;\n}\n\ntype Thenable = {\n then: (onfulfilled?: (value: void) => void, onrejected?: (reason: unknown) => void) => unknown;\n};\n\nconst isThenable = (value: unknown): value is Thenable => {\n return typeof value === 'object' && value !== null && typeof (value as { then?: unknown }).then === 'function';\n};\n\nconst asyncDisposeMetricReader = async (metricReaderCandidate: unknown): Promise<void> => {\n const shutdown = (metricReaderCandidate as { shutdown?: () => void | Promise<void> }).shutdown;\n if (typeof shutdown === 'function') {\n const result = shutdown.call(metricReaderCandidate) as unknown;\n if (isThenable(result)) await result;\n }\n};\n\nexport async function createOtelSdk(cfg: OtelSdkConfig): Promise<OtelSdkHandle> {\n const load = (name: OtelPeerPackage): Promise<unknown> =>\n cfg.modules?.[name] !== undefined ? Promise.resolve(cfg.modules[name]) : importOptionalPeer(name);\n console.log('[sdk] importing @opentelemetry/sdk-node...');\n const sdkMod = (await load('@opentelemetry/sdk-node')) as {\n NodeSDK: new (init: Record<string, unknown>) => {\n start: () => void;\n shutdown: () => Promise<void>;\n };\n };\n\n console.log('[sdk] importing @opentelemetry/resources...');\n const resources = (await load('@opentelemetry/resources')) as {\n resourceFromAttributes: (attrs: Record<string, string | number>) => unknown;\n };\n\n console.log('[sdk] importing @opentelemetry/semantic-conventions...');\n const sem = (await load('@opentelemetry/semantic-conventions')) as Record<string, string>;\n\n console.log('[sdk] importing @opentelemetry/exporter-trace-otlp-http...');\n const traceExp = (await load('@opentelemetry/exporter-trace-otlp-http')) as {\n OTLPTraceExporter: new (init: Record<string, string>) => unknown;\n };\n\n console.log('[sdk] importing @opentelemetry/exporter-metrics-otlp-http...');\n let metricsExp: { OTLPMetricExporter?: new (init: Record<string, string>) => unknown } | undefined;\n try {\n metricsExp = (await load('@opentelemetry/exporter-metrics-otlp-http')) as typeof metricsExp;\n } catch {\n metricsExp = undefined;\n console.log('[sdk] metrics exporter not available (non-fatal)');\n }\n\n let metricReader: unknown;\n let metricsEnabled = false;\n let metricsDropReason: string | undefined;\n if (metricsExp?.OTLPMetricExporter) {\n try {\n const metricsSdk = (await load('@opentelemetry/sdk-metrics')) as {\n PeriodicExportingMetricReader: new (init: Record<string, unknown>) => unknown;\n };\n const candidate = new metricsSdk.PeriodicExportingMetricReader({\n exporter: new metricsExp.OTLPMetricExporter({\n url: `${cfg.otlpEndpoint.replace(/\\/$/, '')}/v1/metrics`,\n }),\n });\n // Pre-flight API compatibility check. Some OTel package version\n // combinations construct `PeriodicExportingMetricReader` successfully\n // but lack `setMetricProducer` on the prototype chain (mixed\n // sdk-metrics versions, or runtime-specific class-inheritance\n // quirks — Bun has surfaced this in the past). Without the check,\n // `NodeSDK.start()` may register the global tracer provider BEFORE\n // it tries to call `setMetricProducer` and throws — leaving the\n // global tracer pointing at a half-initialized provider whose\n // span pipeline never drains. Skipping the metric reader when the\n // API isn't there avoids that whole failure mode in one pass.\n const setProducer = (candidate as { setMetricProducer?: unknown }).setMetricProducer;\n if (typeof setProducer === 'function') {\n metricReader = candidate;\n metricsEnabled = true;\n } else {\n metricsDropReason =\n 'setMetricProducer is not a function on PeriodicExportingMetricReader; skipping metrics path';\n await asyncDisposeMetricReader(candidate);\n metricReader = undefined;\n }\n } catch {\n if (metricsDropReason === undefined) {\n metricsDropReason = 'metric reader construction or compatibility check failed';\n }\n metricReader = undefined;\n }\n }\n\n console.log('[sdk] importing @opentelemetry/sdk-trace-base for sampler...');\n let sampler: unknown;\n try {\n const traceBase = (await load('@opentelemetry/sdk-trace-base')) as {\n ParentBasedSampler: new (init: Record<string, unknown>) => unknown;\n TraceIdRatioBasedSampler: new (ratio: number) => unknown;\n };\n sampler = new traceBase.ParentBasedSampler({\n root: new traceBase.TraceIdRatioBasedSampler(Math.min(1, Math.max(0, cfg.sampleRatio))),\n });\n } catch {\n sampler = undefined;\n console.log('[sdk] sampler not available (non-fatal)');\n }\n\n // Some services have auto-instrumentations installed; optional.\n console.log('[sdk] importing @opentelemetry/auto-instrumentations-node...');\n let autoInstrumentations: unknown[] | undefined;\n try {\n const auto = (await load('@opentelemetry/auto-instrumentations-node')) as {\n getNodeAutoInstrumentations: (cfg?: Record<string, unknown>) => unknown[];\n };\n const instrumentationConfig = autoInstrumentationConfig();\n autoInstrumentations = auto.getNodeAutoInstrumentations(instrumentationConfig);\n console.log('[sdk] auto-instrumentations loaded');\n if (instrumentationConfig['@opentelemetry/instrumentation-runtime-node']?.enabled === false) {\n console.log(\n '[sdk] runtime-node instrumentation off under Bun (its heap statistics stall the event loop); ' +\n 'list runtime-node in OTEL_NODE_ENABLED_INSTRUMENTATIONS to turn it on'\n );\n }\n } catch {\n autoInstrumentations = undefined;\n console.log('[sdk] auto-instrumentations not available (non-fatal)');\n }\n\n const serviceNamespaceByBoundary: Record<Boundary, string> = {\n wspace: 'workspaces',\n global: 'tenant',\n gateway: 'gateways',\n };\n const resourceAttributes: Record<string, string> = {\n [sem['SEMRESATTRS_SERVICE_NAME'] ?? 'service.name']: cfg.serviceName,\n [sem['SEMRESATTRS_SERVICE_VERSION'] ?? 'service.version']: cfg.serviceVersion,\n [sem['SEMRESATTRS_SERVICE_NAMESPACE'] ?? 'service.namespace']: serviceNamespaceByBoundary[cfg.boundary],\n [sem['SEMRESATTRS_DEPLOYMENT_ENVIRONMENT'] ?? 'deployment.environment']: cfg.env,\n 'burdenoff.boundary': cfg.boundary,\n };\n if (cfg.module) resourceAttributes['burdenoff.module'] = cfg.module;\n const serviceInstanceId = process.env['POD_NAME'] ?? process.env['HOSTNAME'];\n if (serviceInstanceId) resourceAttributes['service.instance.id'] = serviceInstanceId;\n const clusterName = process.env['CLUSTER_NAME'];\n if (clusterName) {\n resourceAttributes['cluster'] = clusterName;\n resourceAttributes['k8s.cluster.name'] = clusterName;\n }\n\n const resource = resources.resourceFromAttributes(resourceAttributes);\n\n const traceExporter = new traceExp.OTLPTraceExporter({\n url: `${cfg.otlpEndpoint.replace(/\\/$/, '')}/v1/traces`,\n });\n\n // Single NodeSDK, single start. The pre-flight `setMetricProducer`\n // check above means we never pass an incompatible metric reader into\n // NodeSDK construction — so we no longer need the prior catch+rebuild\n // fallback dance, which had its own side-effect: the failed first\n // NodeSDK could leave the global tracer provider partially registered,\n // and the second NodeSDK's `setGlobalTracerProvider` becomes a no-op\n // — meaning spans flow into the FIRST (broken) provider and never\n // reach the exporter. Eliminating the fallback eliminates that hazard.\n console.log('[sdk] constructing NodeSDK...');\n const nodeSdk = new sdkMod.NodeSDK({\n resource,\n traceExporter,\n ...(metricReader ? { metricReader } : {}),\n ...(sampler ? { sampler } : {}),\n ...(cfg.idGenerator ? { idGenerator: cfg.idGenerator } : {}),\n ...(autoInstrumentations ? { instrumentations: autoInstrumentations } : {}),\n });\n console.log('[sdk] NodeSDK constructed, calling start()...');\n // NodeSDK.start() returns void in modern versions and Promise<void> in older\n // ones. Cast to a permissive thenable shape so awaiting works either way\n // without tripping `@typescript-eslint/await-thenable`.\n const startResult = nodeSdk.start() as unknown;\n if (isThenable(startResult)) {\n await startResult;\n }\n console.log('[sdk] NodeSDK started');\n\n // Stash the @opentelemetry/api reference for pino-logger's mixin.\n try {\n (globalThis as unknown as { __otelApi?: unknown }).__otelApi = await load('@opentelemetry/api');\n console.log('[sdk] @opentelemetry/api stashed for pino mixin');\n } catch {\n console.log('[sdk] @opentelemetry/api stash failed (non-fatal)');\n }\n\n console.log('[sdk] OTel SDK initialization complete');\n return {\n shutdown: async (): Promise<void> => nodeSdk.shutdown(),\n metricsEnabled,\n metricsDropReason,\n };\n}\n"],"mappings":";;;;;;;;;;;;;AA6DA,MAAM,+BAA+B;;AAGrC,MAAM,wBAAwB,OAA2B,SACvD,UAAU,UAAa,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,UAAU,MAAM,KAAK,MAAM,IAAI;;;;;;;;;;;;;;;;;;;AAoB/E,SAAgB,0BACd,MAAoD,QAAQ,KAC5D,MAAe,aAAa,GACD;CAC3B,MAAM,SAAoC,EACxC,qCAAqC,EAAE,SAAS,MAAM,EACxD;CACA,IAAI,OAAO,CAAC,qBAAqB,IAAI,uCAAuC,4BAA4B,GACtG,OAAO,iDAAiD,EAAE,SAAS,MAAM;CAE3E,OAAO;AACT;AAMA,MAAM,cAAc,UAAsC;CACxD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAQ,MAA6B,SAAS;AACtG;AAEA,MAAM,2BAA2B,OAAO,0BAAkD;CACxF,MAAM,WAAY,sBAAoE;CACtF,IAAI,OAAO,aAAa,YAAY;EAClC,MAAM,SAAS,SAAS,KAAK,qBAAqB;EAClD,IAAI,WAAW,MAAM,GAAG,MAAM;CAChC;AACF;AAEA,eAAs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uBAAuB,EAAE,kBAAkB,qBAAqB,IAAI,CAAC;CAC3E,CAAC;CACD,QAAQ,IAAI,+CAA+C;CAI3D,MAAM,cAAc,QAAQ,MAAM;CAClC,IAAI,WAAW,WAAW,GACxB,MAAM;CAER,QAAQ,IAAI,uBAAuB;CAGnC,IAAI;EACF,AAAC,WAAkD,YAAY,MAAM,KAAK,oBAAoB;EAC9F,QAAQ,IAAI,iDAAiD;CAC/D,QAAQ;EACN,QAAQ,IAAI,mDAAmD;CACjE;CAEA,QAAQ,IAAI,wCAAwC;CACpD,OAAO;EACL,UAAU,YAA2B,QAAQ,SAAS;EACtD;EACA;CACF;AACF"}
|
package/dist/server/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { ContextManager } from "../context/index.js";
|
|
|
6
6
|
import { l as I18n } from "../i18n-BBMYFd0P.js";
|
|
7
7
|
import { o as getMetricsRegistry } from "../metrics-collector-C2eShrlW.js";
|
|
8
8
|
import { t as getWorkspaceQuotaRegistry } from "../metrics-BrLwNUrb.js";
|
|
9
|
+
import { t as collectPromDefaultMetrics } from "../bun-runtime-metrics-CPy5D6NT.js";
|
|
9
10
|
import { i as suppressMutationAudit, r as runInExplicitActivityScope, t as createExplicitActivityScope } from "../explicit-activity-scope-DikJ7NAE.js";
|
|
10
11
|
import { GraphQLError, Kind, OperationTypeNode } from "graphql";
|
|
11
12
|
import crypto from "node:crypto";
|
|
@@ -1507,9 +1508,7 @@ async function createServer(definition) {
|
|
|
1507
1508
|
}
|
|
1508
1509
|
if (pathname === "/metrics" && request.method === "GET") try {
|
|
1509
1510
|
const prom = await import("prom-client");
|
|
1510
|
-
|
|
1511
|
-
prom.collectDefaultMetrics({ register: prom.register });
|
|
1512
|
-
} catch {}
|
|
1511
|
+
collectPromDefaultMetrics(prom);
|
|
1513
1512
|
const promBody = await prom.register.metrics();
|
|
1514
1513
|
let sdkBody = "";
|
|
1515
1514
|
await quotaGaugeRefresher.refresh();
|