@zonastery/bursar 2.0.2 → 2.0.3
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/README.md +1 -0
- package/dist/billing/auto-recharge-service.d.ts +1 -1
- package/dist/billing/auto-recharge-service.d.ts.map +1 -1
- package/dist/billing/auto-recharge-service.js +3 -2
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +1 -1
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +2 -1
- package/dist/billing/contracts.d.ts.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +18 -6
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +33 -1
- package/dist/billing/postgres/repositories/event.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +1 -1
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/topup.js +1 -1
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +1 -1
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +16 -6
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/types/auto-recharge.d.ts +1 -1
- package/dist/billing/types/auto-recharge.d.ts.map +1 -1
- package/dist/billing/types/auto-recharge.js.map +1 -1
- package/dist/billing/types/catalog.d.ts +1 -1
- package/dist/billing/types/catalog.d.ts.map +1 -1
- package/dist/billing/types/catalog.js.map +1 -1
- package/dist/billing/types/documents.d.ts +1 -1
- package/dist/billing/types/documents.d.ts.map +1 -1
- package/dist/billing/types/documents.js.map +1 -1
- package/dist/billing/types/events.d.ts +8 -0
- package/dist/billing/types/events.d.ts.map +1 -1
- package/dist/billing/types/events.js.map +1 -1
- package/dist/breakdown.d.ts +1 -1
- package/dist/breakdown.d.ts.map +1 -1
- package/dist/breakdown.js +1 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +58 -50
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +1 -1
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-utils.d.ts +1 -1
- package/dist/config/parse-utils.d.ts.map +1 -1
- package/dist/config/parse-utils.js +1 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +1 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/credits/amount.d.ts +1 -1
- package/dist/credits/amount.d.ts.map +1 -1
- package/dist/credits/amount.js +1 -1
- package/dist/credits/amount.js.map +1 -1
- package/dist/credits/catalog-runtime.d.ts +1 -1
- package/dist/credits/catalog-runtime.d.ts.map +1 -1
- package/dist/credits/catalog-runtime.js +1 -1
- package/dist/credits/catalog-runtime.js.map +1 -1
- package/dist/credits/lease-workflow.d.ts +1 -1
- package/dist/credits/lease-workflow.d.ts.map +1 -1
- package/dist/credits/lease-workflow.js +1 -1
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.d.ts +1 -1
- package/dist/credits/low-balance-monitor.d.ts.map +1 -1
- package/dist/credits/low-balance-monitor.js +1 -1
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.js +1 -1
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js +1 -1
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/lease.js +4 -2
- package/dist/credits/postgres/repositories/lease.js.map +1 -1
- package/dist/credits/postgres/repositories/team.d.ts +2 -1
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/team.js +19 -5
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +3 -3
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +6 -3
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts +1 -1
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +1 -1
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/service-errors.d.ts +1 -1
- package/dist/credits/service-errors.d.ts.map +1 -1
- package/dist/credits/service-errors.js +1 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.d.ts +4 -1
- package/dist/credits/service-types.d.ts.map +1 -1
- package/dist/credits/service-types.js.map +1 -1
- package/dist/credits/service.d.ts +5 -0
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +20 -5
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +10 -1
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +1 -1
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/teams.d.ts +1 -0
- package/dist/credits/types/teams.d.ts.map +1 -1
- package/dist/credits/types/teams.js.map +1 -1
- package/dist/engine.js +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +34 -0
- package/dist/errors.js.map +1 -1
- package/dist/expr/evaluator.d.ts +1 -1
- package/dist/expr/evaluator.d.ts.map +1 -1
- package/dist/expr/evaluator.js +1 -1
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr.d.ts +1 -1
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +1 -1
- package/dist/expr.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/metrics.d.ts +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +6 -3
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +3 -3
- package/dist/providers/_shared.d.ts.map +1 -1
- package/dist/providers/_shared.js +11 -6
- package/dist/providers/_shared.js.map +1 -1
- package/dist/providers/dodo/client-contract.d.ts +8 -15
- package/dist/providers/dodo/client-contract.d.ts.map +1 -1
- package/dist/providers/dodo/client-contract.js.map +1 -1
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +18 -2
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +37 -26
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +71 -3
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/types.d.ts +0 -1
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/shared/diagnostics.d.ts +8 -0
- package/dist/shared/diagnostics.d.ts.map +1 -1
- package/dist/shared/diagnostics.js +49 -0
- package/dist/shared/diagnostics.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +3 -0
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +15 -2
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/storage/adapters/clickhouse.d.ts +9 -2
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +142 -36
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.d.ts +44 -6
- package/dist/storage/adapters/s3.d.ts.map +1 -1
- package/dist/storage/adapters/s3.js +59 -21
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/diagnostics.d.ts +105 -0
- package/dist/storage/diagnostics.d.ts.map +1 -0
- package/dist/storage/diagnostics.js +227 -0
- package/dist/storage/diagnostics.js.map +1 -0
- package/dist/storage/maintenance.d.ts +88 -0
- package/dist/storage/maintenance.d.ts.map +1 -0
- package/dist/storage/maintenance.js +266 -0
- package/dist/storage/maintenance.js.map +1 -0
- package/dist/storage/outbox-worker.d.ts +20 -0
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +152 -23
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +43 -1
- package/dist/storage/ports.d.ts.map +1 -1
- package/dist/storage/ports.js.map +1 -1
- package/dist/storage/postgres-repository.d.ts +7 -2
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +88 -8
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +19 -2
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +216 -29
- package/dist/storage/runtime.js.map +1 -1
- package/dist/telemetry/index.d.ts +37 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +115 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/opentelemetry.d.ts +25 -0
- package/dist/telemetry/opentelemetry.d.ts.map +1 -0
- package/dist/telemetry/opentelemetry.js +74 -0
- package/dist/telemetry/opentelemetry.js.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/** Package-scoped telemetry constants shared by every instrumentation adapter. */
|
|
2
|
+
export const BURSAR_INSTRUMENTATION_SCOPE = "@zonastery/bursar";
|
|
3
|
+
export const BURSAR_INSTRUMENTATION_VERSION = "2.0.3";
|
|
4
|
+
const ALLOWED_ATTRIBUTE_KEYS = new Set([
|
|
5
|
+
"bursar.operation",
|
|
6
|
+
"bursar.outcome",
|
|
7
|
+
"bursar.backend",
|
|
8
|
+
"bursar.provider",
|
|
9
|
+
"error.type",
|
|
10
|
+
"error.code",
|
|
11
|
+
]);
|
|
12
|
+
const MAX_ATTRIBUTE_LENGTH = 64;
|
|
13
|
+
function normalizeToken(value, fallback) {
|
|
14
|
+
if (typeof value !== "string")
|
|
15
|
+
return fallback;
|
|
16
|
+
const normalized = value
|
|
17
|
+
.trim()
|
|
18
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
19
|
+
.replace(/[^a-zA-Z0-9._-]+/g, "_")
|
|
20
|
+
.replace(/^[_\-.]+|[_\-.]+$/g, "")
|
|
21
|
+
.toLowerCase()
|
|
22
|
+
.slice(0, MAX_ATTRIBUTE_LENGTH);
|
|
23
|
+
return normalized || fallback;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Keep telemetry attributes bounded and low-cardinality.
|
|
27
|
+
*
|
|
28
|
+
* Unknown keys and non-scalar values are discarded. String values are
|
|
29
|
+
* normalized to stable tokens so identifiers, metadata, and raw payloads
|
|
30
|
+
* cannot accidentally pass through this boundary.
|
|
31
|
+
*/
|
|
32
|
+
export function sanitizeTelemetryAttributes(attributes = {}) {
|
|
33
|
+
const sanitized = {};
|
|
34
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
35
|
+
if (!ALLOWED_ATTRIBUTE_KEYS.has(key))
|
|
36
|
+
continue;
|
|
37
|
+
if (typeof value === "boolean") {
|
|
38
|
+
sanitized[key] = value;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
42
|
+
sanitized[key] = value;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const normalized = normalizeToken(value);
|
|
46
|
+
if (normalized !== undefined)
|
|
47
|
+
sanitized[key] = normalized;
|
|
48
|
+
}
|
|
49
|
+
return sanitized;
|
|
50
|
+
}
|
|
51
|
+
/** Build the safe base attributes for one Bursar operation. */
|
|
52
|
+
export function telemetryOperationAttributes(operation, attributes = {}) {
|
|
53
|
+
return {
|
|
54
|
+
...sanitizeTelemetryAttributes(attributes),
|
|
55
|
+
"bursar.operation": normalizeToken(operation, "unknown"),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Normalize an error without reading or recording its message or details. */
|
|
59
|
+
export function telemetryErrorAttributes(error) {
|
|
60
|
+
const type = normalizeToken(diagnosticErrorType(error), "unknown_error");
|
|
61
|
+
const code = normalizeToken(diagnosticErrorCode(error));
|
|
62
|
+
return {
|
|
63
|
+
"error.type": type,
|
|
64
|
+
...(code === undefined ? {} : { "error.code": code }),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Default implementation: execute normally and emit nothing. */
|
|
68
|
+
export class NoopInstrumentation {
|
|
69
|
+
async run(_operation, _attributes, callback) {
|
|
70
|
+
return callback();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export const NOOP_INSTRUMENTATION = Object.freeze(new NoopInstrumentation());
|
|
74
|
+
let defaultInstrumentation = NOOP_INSTRUMENTATION;
|
|
75
|
+
const instrumentationRegistrations = [];
|
|
76
|
+
function assertInstrumentation(value) {
|
|
77
|
+
if (typeof value !== "object" || value === null || typeof value.run !== "function") {
|
|
78
|
+
throw new TypeError("instrumentation must provide run()");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Return the instrumentation selected by the embedding application. */
|
|
82
|
+
export function getDefaultInstrumentation() {
|
|
83
|
+
return defaultInstrumentation;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Select a process-wide Bursar instrumentation implementation.
|
|
87
|
+
*
|
|
88
|
+
* This does not configure an OpenTelemetry provider or exporter. Call the
|
|
89
|
+
* returned function to restore the previous implementation. A stale restore
|
|
90
|
+
* cannot overwrite a newer registration.
|
|
91
|
+
*/
|
|
92
|
+
export function setDefaultInstrumentation(instrumentation) {
|
|
93
|
+
const selected = instrumentation ?? NOOP_INSTRUMENTATION;
|
|
94
|
+
assertInstrumentation(selected);
|
|
95
|
+
const registration = { instrumentation: selected, active: true };
|
|
96
|
+
instrumentationRegistrations.push(registration);
|
|
97
|
+
refreshDefaultInstrumentation();
|
|
98
|
+
let restored = false;
|
|
99
|
+
return () => {
|
|
100
|
+
if (restored)
|
|
101
|
+
return;
|
|
102
|
+
restored = true;
|
|
103
|
+
registration.active = false;
|
|
104
|
+
refreshDefaultInstrumentation();
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function refreshDefaultInstrumentation() {
|
|
108
|
+
while (instrumentationRegistrations.at(-1)?.active === false) {
|
|
109
|
+
instrumentationRegistrations.pop();
|
|
110
|
+
}
|
|
111
|
+
defaultInstrumentation =
|
|
112
|
+
instrumentationRegistrations.at(-1)?.instrumentation ?? NOOP_INSTRUMENTATION;
|
|
113
|
+
}
|
|
114
|
+
import { diagnosticErrorCode, diagnosticErrorType } from "../shared/diagnostics.js";
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,CAAC,MAAM,4BAA4B,GAAG,mBAAmB,CAAC;AAChE,MAAM,CAAC,MAAM,8BAA8B,GAAG,OAAO,CAAC;AAKtD,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,kBAAkB;IAClB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB,YAAY;IACZ,YAAY;CACb,CAAC,CAAC;AACH,MAAM,oBAAoB,GAA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,eAAe,IAAI,oBAAoB,CAAC;IACzD,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAChC,MAAM,YAAY,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACjE,4BAA4B,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAChD,6BAA6B,EAAE,CAAC;IAChC,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO,GAAG,EAAE;QACV,IAAI,QAAQ;YAAE,OAAO;QACrB,QAAQ,GAAG,IAAI,CAAC;QAChB,YAAY,CAAC,MAAM,GAAG,KAAK,CAAC;QAC5B,6BAA6B,EAAE,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,6BAA6B;IACpC,OAAO,4BAA4B,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,KAAK,EAAE,CAAC;QAC7D,4BAA4B,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;IACD,sBAAsB;QACpB,4BAA4B,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,eAAe,IAAI,oBAAoB,CAAC;AACjF,CAAC;AACD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["/** Package-scoped telemetry constants shared by every instrumentation adapter. */\nexport const BURSAR_INSTRUMENTATION_SCOPE = \"@zonastery/bursar\";\nexport const BURSAR_INSTRUMENTATION_VERSION = \"2.0.3\";\n\nexport type TelemetryAttributeValue = string | number | boolean;\nexport type TelemetryAttributes = Readonly<Record<string, TelemetryAttributeValue>>;\n\nconst ALLOWED_ATTRIBUTE_KEYS = new Set([\n \"bursar.operation\",\n \"bursar.outcome\",\n \"bursar.backend\",\n \"bursar.provider\",\n \"error.type\",\n \"error.code\",\n]);\nconst MAX_ATTRIBUTE_LENGTH = 64;\n\nfunction normalizeToken(value: unknown, fallback?: string): string | undefined {\n if (typeof value !== \"string\") return fallback;\n const normalized = value\n .trim()\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/[^a-zA-Z0-9._-]+/g, \"_\")\n .replace(/^[_\\-.]+|[_\\-.]+$/g, \"\")\n .toLowerCase()\n .slice(0, MAX_ATTRIBUTE_LENGTH);\n return normalized || fallback;\n}\n\n/**\n * Keep telemetry attributes bounded and low-cardinality.\n *\n * Unknown keys and non-scalar values are discarded. String values are\n * normalized to stable tokens so identifiers, metadata, and raw payloads\n * cannot accidentally pass through this boundary.\n */\nexport function sanitizeTelemetryAttributes(\n attributes: Readonly<Record<string, unknown>> = {},\n): Record<string, TelemetryAttributeValue> {\n const sanitized: Record<string, TelemetryAttributeValue> = {};\n for (const [key, value] of Object.entries(attributes)) {\n if (!ALLOWED_ATTRIBUTE_KEYS.has(key)) continue;\n if (typeof value === \"boolean\") {\n sanitized[key] = value;\n continue;\n }\n if (typeof value === \"number\" && Number.isFinite(value)) {\n sanitized[key] = value;\n continue;\n }\n const normalized = normalizeToken(value);\n if (normalized !== undefined) sanitized[key] = normalized;\n }\n return sanitized;\n}\n\n/** Build the safe base attributes for one Bursar operation. */\nexport function telemetryOperationAttributes(\n operation: string,\n attributes: Readonly<Record<string, unknown>> = {},\n): Record<string, TelemetryAttributeValue> {\n return {\n ...sanitizeTelemetryAttributes(attributes),\n \"bursar.operation\": normalizeToken(operation, \"unknown\")!,\n };\n}\n\n/** Normalize an error without reading or recording its message or details. */\nexport function telemetryErrorAttributes(error: unknown): Record<string, string> {\n const type = normalizeToken(diagnosticErrorType(error), \"unknown_error\")!;\n const code = normalizeToken(diagnosticErrorCode(error));\n return {\n \"error.type\": type,\n ...(code === undefined ? {} : { \"error.code\": code }),\n };\n}\n\n/** Vendor-neutral contract used by Bursar's core runtime. */\nexport interface Instrumentation {\n run<T>(\n operation: string,\n attributes: TelemetryAttributes | undefined,\n callback: () => Promise<T>,\n ): Promise<T>;\n}\n\n/** Default implementation: execute normally and emit nothing. */\nexport class NoopInstrumentation implements Instrumentation {\n async run<T>(\n _operation: string,\n _attributes: TelemetryAttributes | undefined,\n callback: () => Promise<T>,\n ): Promise<T> {\n return callback();\n }\n}\n\nexport const NOOP_INSTRUMENTATION: Instrumentation = Object.freeze(new NoopInstrumentation());\n\nlet defaultInstrumentation: Instrumentation = NOOP_INSTRUMENTATION;\nconst instrumentationRegistrations: Array<{\n instrumentation: Instrumentation;\n active: boolean;\n}> = [];\n\nfunction assertInstrumentation(value: Instrumentation): void {\n if (typeof value !== \"object\" || value === null || typeof value.run !== \"function\") {\n throw new TypeError(\"instrumentation must provide run()\");\n }\n}\n\n/** Return the instrumentation selected by the embedding application. */\nexport function getDefaultInstrumentation(): Instrumentation {\n return defaultInstrumentation;\n}\n\n/**\n * Select a process-wide Bursar instrumentation implementation.\n *\n * This does not configure an OpenTelemetry provider or exporter. Call the\n * returned function to restore the previous implementation. A stale restore\n * cannot overwrite a newer registration.\n */\nexport function setDefaultInstrumentation(instrumentation: Instrumentation | null): () => void {\n const selected = instrumentation ?? NOOP_INSTRUMENTATION;\n assertInstrumentation(selected);\n const registration = { instrumentation: selected, active: true };\n instrumentationRegistrations.push(registration);\n refreshDefaultInstrumentation();\n let restored = false;\n return () => {\n if (restored) return;\n restored = true;\n registration.active = false;\n refreshDefaultInstrumentation();\n };\n}\n\nfunction refreshDefaultInstrumentation(): void {\n while (instrumentationRegistrations.at(-1)?.active === false) {\n instrumentationRegistrations.pop();\n }\n defaultInstrumentation =\n instrumentationRegistrations.at(-1)?.instrumentation ?? NOOP_INSTRUMENTATION;\n}\nimport { diagnosticErrorCode, diagnosticErrorType } from \"../shared/diagnostics.js\";\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Meter, type Tracer } from "@opentelemetry/api";
|
|
2
|
+
import { type Instrumentation, type TelemetryAttributes } from "./index.js";
|
|
3
|
+
export interface OpenTelemetryInstrumentationOptions {
|
|
4
|
+
/** Override the API tracer, primarily for host-level composition or tests. */
|
|
5
|
+
tracer?: Tracer;
|
|
6
|
+
/** Override the API meter, primarily for host-level composition or tests. */
|
|
7
|
+
meter?: Meter;
|
|
8
|
+
}
|
|
9
|
+
/** OpenTelemetry API-only adapter. It never creates an SDK or exporter. */
|
|
10
|
+
export declare class OpenTelemetryInstrumentation implements Instrumentation {
|
|
11
|
+
private readonly tracer;
|
|
12
|
+
private readonly operationCounter;
|
|
13
|
+
private readonly operationDuration;
|
|
14
|
+
constructor(options?: OpenTelemetryInstrumentationOptions);
|
|
15
|
+
run<T>(operation: string, attributes: TelemetryAttributes | undefined, callback: () => Promise<T>): Promise<T>;
|
|
16
|
+
private runInSpan;
|
|
17
|
+
private recordMetrics;
|
|
18
|
+
}
|
|
19
|
+
export declare function createOpenTelemetryInstrumentation(options?: OpenTelemetryInstrumentationOptions): Instrumentation;
|
|
20
|
+
/**
|
|
21
|
+
* Enable the API-only adapter for subsequently constructed Bursar services.
|
|
22
|
+
* The embedding application remains responsible for the OTel SDK and export.
|
|
23
|
+
*/
|
|
24
|
+
export declare function enableOpenTelemetry(options?: OpenTelemetryInstrumentationOptions): () => void;
|
|
25
|
+
//# sourceMappingURL=opentelemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry.d.ts","sourceRoot":"","sources":["../../src/telemetry/opentelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,KAAK,EAEV,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,mCAAmC;IAClD,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAMD,2EAA2E;AAC3E,qBAAa,4BAA6B,YAAW,eAAe;IAClE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAC3C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAY;gBAElC,OAAO,GAAE,mCAAwC;IAiB7D,GAAG,CAAC,CAAC,EACH,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,mBAAmB,GAAG,SAAS,EAC3C,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,CAAC;YAUC,SAAS;IA8BvB,OAAO,CAAC,aAAa;CAWtB;AAED,wBAAgB,kCAAkC,CAChD,OAAO,GAAE,mCAAwC,GAChD,eAAe,CAEjB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,mCAAwC,GAAG,MAAM,IAAI,CAEjG"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { metrics, SpanStatusCode, trace, } from "@opentelemetry/api";
|
|
2
|
+
import { BURSAR_INSTRUMENTATION_SCOPE, BURSAR_INSTRUMENTATION_VERSION, setDefaultInstrumentation, telemetryErrorAttributes, telemetryOperationAttributes, } from "./index.js";
|
|
3
|
+
function otelAttributes(attributes) {
|
|
4
|
+
return attributes;
|
|
5
|
+
}
|
|
6
|
+
/** OpenTelemetry API-only adapter. It never creates an SDK or exporter. */
|
|
7
|
+
export class OpenTelemetryInstrumentation {
|
|
8
|
+
tracer;
|
|
9
|
+
operationCounter;
|
|
10
|
+
operationDuration;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.tracer =
|
|
13
|
+
options.tracer ??
|
|
14
|
+
trace.getTracer(BURSAR_INSTRUMENTATION_SCOPE, BURSAR_INSTRUMENTATION_VERSION);
|
|
15
|
+
const meter = options.meter ??
|
|
16
|
+
metrics.getMeter(BURSAR_INSTRUMENTATION_SCOPE, BURSAR_INSTRUMENTATION_VERSION);
|
|
17
|
+
this.operationCounter = meter.createCounter("bursar.operation.count", {
|
|
18
|
+
description: "Completed Bursar operations",
|
|
19
|
+
unit: "{operation}",
|
|
20
|
+
});
|
|
21
|
+
this.operationDuration = meter.createHistogram("bursar.operation.duration", {
|
|
22
|
+
description: "Bursar operation duration",
|
|
23
|
+
unit: "s",
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
run(operation, attributes, callback) {
|
|
27
|
+
const baseAttributes = telemetryOperationAttributes(operation, attributes);
|
|
28
|
+
const spanName = `bursar.${baseAttributes["bursar.operation"]}`;
|
|
29
|
+
return this.tracer.startActiveSpan(spanName, { attributes: otelAttributes(baseAttributes) }, async (span) => this.runInSpan(span, baseAttributes, callback));
|
|
30
|
+
}
|
|
31
|
+
async runInSpan(span, baseAttributes, callback) {
|
|
32
|
+
const startedAt = performance.now();
|
|
33
|
+
try {
|
|
34
|
+
const result = await callback();
|
|
35
|
+
const completed = { ...baseAttributes, "bursar.outcome": "success" };
|
|
36
|
+
span.setAttributes(otelAttributes(completed));
|
|
37
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
38
|
+
this.recordMetrics(startedAt, completed);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const completed = {
|
|
43
|
+
...baseAttributes,
|
|
44
|
+
"bursar.outcome": "error",
|
|
45
|
+
...telemetryErrorAttributes(error),
|
|
46
|
+
};
|
|
47
|
+
span.setAttributes(otelAttributes(completed));
|
|
48
|
+
// Deliberately omit a description and exception event: both may include
|
|
49
|
+
// the raw error message, SQL text, identifiers, or provider payloads.
|
|
50
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
51
|
+
this.recordMetrics(startedAt, completed);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
span.end();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
recordMetrics(startedAt, attributes) {
|
|
59
|
+
const safeAttributes = otelAttributes(attributes);
|
|
60
|
+
this.operationCounter.add(1, safeAttributes);
|
|
61
|
+
this.operationDuration.record(Math.max(0, performance.now() - startedAt) / 1_000, safeAttributes);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function createOpenTelemetryInstrumentation(options = {}) {
|
|
65
|
+
return new OpenTelemetryInstrumentation(options);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Enable the API-only adapter for subsequently constructed Bursar services.
|
|
69
|
+
* The embedding application remains responsible for the OTel SDK and export.
|
|
70
|
+
*/
|
|
71
|
+
export function enableOpenTelemetry(options = {}) {
|
|
72
|
+
return setDefaultInstrumentation(createOpenTelemetryInstrumentation(options));
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=opentelemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry.js","sourceRoot":"","sources":["../../src/telemetry/opentelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,cAAc,EACd,KAAK,GAON,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC9B,yBAAyB,EACzB,wBAAwB,EACxB,4BAA4B,GAI7B,MAAM,YAAY,CAAC;AASpB,SAAS,cAAc,CAAC,UAA6D;IACnF,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,2EAA2E;AAC3E,MAAM,OAAO,4BAA4B;IACtB,MAAM,CAAS;IACf,gBAAgB,CAAU;IAC1B,iBAAiB,CAAY;IAE9C,YAAY,UAA+C,EAAE;QAC3D,IAAI,CAAC,MAAM;YACT,OAAO,CAAC,MAAM;gBACd,KAAK,CAAC,SAAS,CAAC,4BAA4B,EAAE,8BAA8B,CAAC,CAAC;QAChF,MAAM,KAAK,GACT,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,QAAQ,CAAC,4BAA4B,EAAE,8BAA8B,CAAC,CAAC;QACjF,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAC,wBAAwB,EAAE;YACpE,WAAW,EAAE,6BAA6B;YAC1C,IAAI,EAAE,aAAa;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,iBA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,CAAC,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;YAC9C,wEAAwE;YACxE,sEAAsE;YACtE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/C,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACzC,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAEO,aAAa,CACnB,SAAiB,EACjB,UAAmD;QAEnD,MAAM,cAAc,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;QAC7C,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAC3B,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,KAAK,EAClD,cAAc,CACf,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,kCAAkC,CAChD,UAA+C,EAAE;IAEjD,OAAO,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA+C,EAAE;IACnF,OAAO,yBAAyB,CAAC,kCAAkC,CAAC,OAAO,CAAC,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import {\n metrics,\n SpanStatusCode,\n trace,\n type Attributes,\n type Counter,\n type Histogram,\n type Meter,\n type Span,\n type Tracer,\n} from \"@opentelemetry/api\";\n\nimport {\n BURSAR_INSTRUMENTATION_SCOPE,\n BURSAR_INSTRUMENTATION_VERSION,\n setDefaultInstrumentation,\n telemetryErrorAttributes,\n telemetryOperationAttributes,\n type Instrumentation,\n type TelemetryAttributes,\n type TelemetryAttributeValue,\n} from \"./index.js\";\n\nexport interface OpenTelemetryInstrumentationOptions {\n /** Override the API tracer, primarily for host-level composition or tests. */\n tracer?: Tracer;\n /** Override the API meter, primarily for host-level composition or tests. */\n meter?: Meter;\n}\n\nfunction otelAttributes(attributes: Readonly<Record<string, TelemetryAttributeValue>>): Attributes {\n return attributes;\n}\n\n/** OpenTelemetry API-only adapter. It never creates an SDK or exporter. */\nexport class OpenTelemetryInstrumentation implements Instrumentation {\n private readonly tracer: Tracer;\n private readonly operationCounter: Counter;\n private readonly operationDuration: Histogram;\n\n constructor(options: OpenTelemetryInstrumentationOptions = {}) {\n this.tracer =\n options.tracer ??\n trace.getTracer(BURSAR_INSTRUMENTATION_SCOPE, BURSAR_INSTRUMENTATION_VERSION);\n const meter =\n options.meter ??\n metrics.getMeter(BURSAR_INSTRUMENTATION_SCOPE, BURSAR_INSTRUMENTATION_VERSION);\n this.operationCounter = meter.createCounter(\"bursar.operation.count\", {\n description: \"Completed Bursar operations\",\n unit: \"{operation}\",\n });\n this.operationDuration = meter.createHistogram(\"bursar.operation.duration\", {\n description: \"Bursar operation duration\",\n unit: \"s\",\n });\n }\n\n run<T>(\n operation: string,\n attributes: TelemetryAttributes | undefined,\n callback: () => Promise<T>,\n ): Promise<T> {\n const baseAttributes = telemetryOperationAttributes(operation, attributes);\n const spanName = `bursar.${baseAttributes[\"bursar.operation\"]}`;\n return this.tracer.startActiveSpan(\n spanName,\n { attributes: otelAttributes(baseAttributes) },\n async (span) => this.runInSpan(span, baseAttributes, callback),\n );\n }\n\n private async runInSpan<T>(\n span: Span,\n baseAttributes: Record<string, TelemetryAttributeValue>,\n callback: () => Promise<T>,\n ): Promise<T> {\n const startedAt = performance.now();\n try {\n const result = await callback();\n const completed = { ...baseAttributes, \"bursar.outcome\": \"success\" };\n span.setAttributes(otelAttributes(completed));\n span.setStatus({ code: SpanStatusCode.OK });\n this.recordMetrics(startedAt, completed);\n return result;\n } catch (error) {\n const completed = {\n ...baseAttributes,\n \"bursar.outcome\": \"error\",\n ...telemetryErrorAttributes(error),\n };\n span.setAttributes(otelAttributes(completed));\n // Deliberately omit a description and exception event: both may include\n // the raw error message, SQL text, identifiers, or provider payloads.\n span.setStatus({ code: SpanStatusCode.ERROR });\n this.recordMetrics(startedAt, completed);\n throw error;\n } finally {\n span.end();\n }\n }\n\n private recordMetrics(\n startedAt: number,\n attributes: Record<string, TelemetryAttributeValue>,\n ): void {\n const safeAttributes = otelAttributes(attributes);\n this.operationCounter.add(1, safeAttributes);\n this.operationDuration.record(\n Math.max(0, performance.now() - startedAt) / 1_000,\n safeAttributes,\n );\n }\n}\n\nexport function createOpenTelemetryInstrumentation(\n options: OpenTelemetryInstrumentationOptions = {},\n): Instrumentation {\n return new OpenTelemetryInstrumentation(options);\n}\n\n/**\n * Enable the API-only adapter for subsequently constructed Bursar services.\n * The embedding application remains responsible for the OTel SDK and export.\n */\nexport function enableOpenTelemetry(options: OpenTelemetryInstrumentationOptions = {}): () => void {\n return setDefaultInstrumentation(createOpenTelemetryInstrumentation(options));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zonastery/bursar",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"packageManager": "bun@1.3.14",
|
|
5
5
|
"description": "Open-source PostgreSQL credit ledger, usage metering, and billing SDK for AI SaaS",
|
|
6
6
|
"type": "module",
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"import": "./dist/browser.js",
|
|
24
24
|
"default": "./dist/browser.js"
|
|
25
25
|
},
|
|
26
|
+
"./opentelemetry": {
|
|
27
|
+
"types": "./dist/telemetry/opentelemetry.d.ts",
|
|
28
|
+
"import": "./dist/telemetry/opentelemetry.js",
|
|
29
|
+
"default": "./dist/telemetry/opentelemetry.js"
|
|
30
|
+
},
|
|
26
31
|
"./providers": {
|
|
27
32
|
"types": "./dist/providers/index.d.ts",
|
|
28
33
|
"import": "./dist/providers/index.js",
|
|
@@ -132,6 +137,7 @@
|
|
|
132
137
|
"zod": "^4.4.3"
|
|
133
138
|
},
|
|
134
139
|
"peerDependencies": {
|
|
140
|
+
"@opentelemetry/api": "^1.9.0",
|
|
135
141
|
"@dodopayments/better-auth": "^1.6.4",
|
|
136
142
|
"@dodopayments/nextjs": "^0.3.7",
|
|
137
143
|
"@dodopayments/react-native-checkout": "^1.1.2",
|
|
@@ -143,6 +149,9 @@
|
|
|
143
149
|
"stripe": "^22.2.0"
|
|
144
150
|
},
|
|
145
151
|
"peerDependenciesMeta": {
|
|
152
|
+
"@opentelemetry/api": {
|
|
153
|
+
"optional": true
|
|
154
|
+
},
|
|
146
155
|
"@dodopayments/better-auth": {
|
|
147
156
|
"optional": true
|
|
148
157
|
},
|
|
@@ -172,6 +181,7 @@
|
|
|
172
181
|
}
|
|
173
182
|
},
|
|
174
183
|
"devDependencies": {
|
|
184
|
+
"@opentelemetry/api": "^1.9.0",
|
|
175
185
|
"@aws-sdk/client-s3": "^3.1106.0",
|
|
176
186
|
"@dodopayments/better-auth": "^1.6.4",
|
|
177
187
|
"@dodopayments/nextjs": "^0.3.7",
|