@burdenoff/be-sdk 2026.510.79
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 +173 -0
- package/configs/eslint/index.js +492 -0
- package/configs/tsconfig/tsconfig.json +53 -0
- package/dist/EventQueueFactory-6NMSGECR.js +8 -0
- package/dist/EventQueueFactory-6NMSGECR.js.map +1 -0
- package/dist/auth/index.d.ts +66 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.js +6 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/captcha/index.d.ts +1 -0
- package/dist/captcha/index.js +4 -0
- package/dist/captcha/index.js.map +1 -0
- package/dist/chunk-2HANKZZM.js +245 -0
- package/dist/chunk-2HANKZZM.js.map +1 -0
- package/dist/chunk-2SD5L2F2.js +816 -0
- package/dist/chunk-2SD5L2F2.js.map +1 -0
- package/dist/chunk-3O2RQOPV.js +1068 -0
- package/dist/chunk-3O2RQOPV.js.map +1 -0
- package/dist/chunk-4B43DZIS.js +560 -0
- package/dist/chunk-4B43DZIS.js.map +1 -0
- package/dist/chunk-4XAEES25.js +2444 -0
- package/dist/chunk-4XAEES25.js.map +1 -0
- package/dist/chunk-4XGGWW36.js +1405 -0
- package/dist/chunk-4XGGWW36.js.map +1 -0
- package/dist/chunk-5LXDPGDH.js +245 -0
- package/dist/chunk-5LXDPGDH.js.map +1 -0
- package/dist/chunk-AI7L22ZJ.js +472 -0
- package/dist/chunk-AI7L22ZJ.js.map +1 -0
- package/dist/chunk-CBZNP6RF.js +286 -0
- package/dist/chunk-CBZNP6RF.js.map +1 -0
- package/dist/chunk-ELLX3K54.js +613 -0
- package/dist/chunk-ELLX3K54.js.map +1 -0
- package/dist/chunk-F5XEAGHQ.js +1875 -0
- package/dist/chunk-F5XEAGHQ.js.map +1 -0
- package/dist/chunk-FNZEQOJY.js +628 -0
- package/dist/chunk-FNZEQOJY.js.map +1 -0
- package/dist/chunk-GTEMQXCA.js +516 -0
- package/dist/chunk-GTEMQXCA.js.map +1 -0
- package/dist/chunk-HIWTWIGQ.js +226 -0
- package/dist/chunk-HIWTWIGQ.js.map +1 -0
- package/dist/chunk-IYE2NTRX.js +764 -0
- package/dist/chunk-IYE2NTRX.js.map +1 -0
- package/dist/chunk-J26YGR2U.js +1484 -0
- package/dist/chunk-J26YGR2U.js.map +1 -0
- package/dist/chunk-JG2FTZPI.js +509 -0
- package/dist/chunk-JG2FTZPI.js.map +1 -0
- package/dist/chunk-JVBTNSPG.js +1551 -0
- package/dist/chunk-JVBTNSPG.js.map +1 -0
- package/dist/chunk-L7ZMN2FJ.js +12 -0
- package/dist/chunk-L7ZMN2FJ.js.map +1 -0
- package/dist/chunk-M5IMU3US.js +473 -0
- package/dist/chunk-M5IMU3US.js.map +1 -0
- package/dist/chunk-MLW2HPS5.js +1267 -0
- package/dist/chunk-MLW2HPS5.js.map +1 -0
- package/dist/chunk-MNCGUYLJ.js +269 -0
- package/dist/chunk-MNCGUYLJ.js.map +1 -0
- package/dist/chunk-MOCUBSTW.js +373 -0
- package/dist/chunk-MOCUBSTW.js.map +1 -0
- package/dist/chunk-NGMEI42S.js +103 -0
- package/dist/chunk-NGMEI42S.js.map +1 -0
- package/dist/chunk-NUB5GQTU.js +270 -0
- package/dist/chunk-NUB5GQTU.js.map +1 -0
- package/dist/chunk-OVSYMNCI.js +145 -0
- package/dist/chunk-OVSYMNCI.js.map +1 -0
- package/dist/chunk-QLVKMWFA.js +94 -0
- package/dist/chunk-QLVKMWFA.js.map +1 -0
- package/dist/chunk-SAG6ZYWQ.js +89 -0
- package/dist/chunk-SAG6ZYWQ.js.map +1 -0
- package/dist/chunk-SAK2JCA7.js +198 -0
- package/dist/chunk-SAK2JCA7.js.map +1 -0
- package/dist/chunk-SBS4S2PJ.js +100 -0
- package/dist/chunk-SBS4S2PJ.js.map +1 -0
- package/dist/chunk-SNEOLWXT.js +148 -0
- package/dist/chunk-SNEOLWXT.js.map +1 -0
- package/dist/chunk-TKBD2ONF.js +564 -0
- package/dist/chunk-TKBD2ONF.js.map +1 -0
- package/dist/chunk-UBXFIIAW.js +127 -0
- package/dist/chunk-UBXFIIAW.js.map +1 -0
- package/dist/chunk-VI4VSNTI.js +57 -0
- package/dist/chunk-VI4VSNTI.js.map +1 -0
- package/dist/chunk-VWCN5PMD.js +268 -0
- package/dist/chunk-VWCN5PMD.js.map +1 -0
- package/dist/chunk-XC2YD6CF.js +913 -0
- package/dist/chunk-XC2YD6CF.js.map +1 -0
- package/dist/chunk-XE4OXN2W.js +10 -0
- package/dist/chunk-XE4OXN2W.js.map +1 -0
- package/dist/chunk-YMZEUTD2.js +110 -0
- package/dist/chunk-YMZEUTD2.js.map +1 -0
- package/dist/chunk-Z4IRLBWO.js +758 -0
- package/dist/chunk-Z4IRLBWO.js.map +1 -0
- package/dist/client/internal-client.d.ts +7 -0
- package/dist/client/internal-client.js +5 -0
- package/dist/client/internal-client.js.map +1 -0
- package/dist/client-CSjIrYKS.d.ts +77 -0
- package/dist/config-UKE2E3BW.js +4 -0
- package/dist/config-UKE2E3BW.js.map +1 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +4 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/database/index.d.ts +117 -0
- package/dist/database/index.js +7 -0
- package/dist/database/index.js.map +1 -0
- package/dist/dataloader/index.d.ts +1 -0
- package/dist/dataloader/index.js +4 -0
- package/dist/dataloader/index.js.map +1 -0
- package/dist/esm-K6H7EIWK.js +1450 -0
- package/dist/esm-K6H7EIWK.js.map +1 -0
- package/dist/event-queue/index.d.ts +6 -0
- package/dist/event-queue/index.js +10 -0
- package/dist/event-queue/index.js.map +1 -0
- package/dist/export/index.d.ts +2 -0
- package/dist/export/index.js +9 -0
- package/dist/export/index.js.map +1 -0
- package/dist/feature-flags/index.d.ts +1 -0
- package/dist/feature-flags/index.js +4 -0
- package/dist/feature-flags/index.js.map +1 -0
- package/dist/gateway/index.d.ts +4 -0
- package/dist/gateway/index.js +8 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/security/index.d.ts +2 -0
- package/dist/gateway/security/index.js +5 -0
- package/dist/gateway/security/index.js.map +1 -0
- package/dist/graph/index.d.ts +9 -0
- package/dist/graph/index.js +13 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-emitter-Bk0FqD53.d.ts +47 -0
- package/dist/graphql/index.d.ts +2 -0
- package/dist/graphql/index.js +7 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/services/index.d.ts +24 -0
- package/dist/graphql/services/index.js +5 -0
- package/dist/graphql/services/index.js.map +1 -0
- package/dist/graphql-BAVrUgBF.d.ts +22 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +5 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n-DA6IPnYy.d.ts +101 -0
- package/dist/index-4gKQKZ2B.d.ts +71 -0
- package/dist/index-B18rrFru.d.ts +42 -0
- package/dist/index-B70b5mYS.d.ts +33 -0
- package/dist/index-BMq3lFjj.d.ts +247 -0
- package/dist/index-BODgvRtL.d.ts +316 -0
- package/dist/index-BS2idbnr.d.ts +874 -0
- package/dist/index-BV3G48cH.d.ts +124 -0
- package/dist/index-CHbVw5M7.d.ts +73 -0
- package/dist/index-Cq_xNjcv.d.ts +602 -0
- package/dist/index-CrQgidpx.d.ts +77 -0
- package/dist/index-CyVEg86m.d.ts +309 -0
- package/dist/index-DOcBnmMe.d.ts +166 -0
- package/dist/index-DSOpj8DI.d.ts +17 -0
- package/dist/index-DW9q22GH.d.ts +75 -0
- package/dist/index-DlFDFyWD.d.ts +55 -0
- package/dist/index-DoK0bjhH.d.ts +607 -0
- package/dist/index-Dtf6FBaD.d.ts +199 -0
- package/dist/index-KVWGHMbS.d.ts +415 -0
- package/dist/index-PaojfSdd.d.ts +71 -0
- package/dist/index-RU_M5c74.d.ts +163 -0
- package/dist/index-UhkH2eaB.d.ts +192 -0
- package/dist/index-e_18DzAg.d.ts +18 -0
- package/dist/index-jOuh_TKn.d.ts +59 -0
- package/dist/index.d.ts +584 -0
- package/dist/index.js +2626 -0
- package/dist/index.js.map +1 -0
- package/dist/init/index.d.ts +2 -0
- package/dist/init/index.js +12 -0
- package/dist/init/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +3 -0
- package/dist/instrumentation/index.js +5 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/layer/index.d.ts +2 -0
- package/dist/layer/index.js +6 -0
- package/dist/layer/index.js.map +1 -0
- package/dist/layer-DDip18KY.d.ts +67 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger/index.js +4 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/middleware/index.d.ts +3 -0
- package/dist/middleware/index.js +5 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/notifications/index.d.ts +4 -0
- package/dist/notifications/index.js +7 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.js +5 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/pino-logger-RYLGXPHZ.js +5 -0
- package/dist/pino-logger-RYLGXPHZ.js.map +1 -0
- package/dist/prisma/generator/index.d.ts +1 -0
- package/dist/prisma/generator/index.js +228 -0
- package/dist/prisma/generator/index.js.map +1 -0
- package/dist/prisma/index.d.ts +5 -0
- package/dist/prisma/index.js +12 -0
- package/dist/prisma/index.js.map +1 -0
- package/dist/prisma-extension-krXnYnrN.d.ts +30 -0
- package/dist/rbac/index.d.ts +116 -0
- package/dist/rbac/index.js +7 -0
- package/dist/rbac/index.js.map +1 -0
- package/dist/sdk-THO3IWEE.js +136 -0
- package/dist/sdk-THO3IWEE.js.map +1 -0
- package/dist/server/index.d.ts +359 -0
- package/dist/server/index.js +884 -0
- package/dist/server/index.js.map +1 -0
- package/dist/telemetry/index.d.ts +83 -0
- package/dist/telemetry/index.js +209 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/temporal/index.d.ts +148 -0
- package/dist/temporal/index.js +6 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/tracker/index.d.ts +5 -0
- package/dist/tracker/index.js +9 -0
- package/dist/tracker/index.js.map +1 -0
- package/dist/types-Bo2wkjSP.d.ts +35 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/workspace-guard-LHBNK4TG.js +5 -0
- package/dist/workspace-guard-LHBNK4TG.js.map +1 -0
- package/package.json +241 -0
|
@@ -0,0 +1,2444 @@
|
|
|
1
|
+
import { logger } from './chunk-CBZNP6RF.js';
|
|
2
|
+
import { __export, __name } from './chunk-XE4OXN2W.js';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
|
|
5
|
+
// src/instrumentation/index.ts
|
|
6
|
+
var instrumentation_exports = {};
|
|
7
|
+
__export(instrumentation_exports, {
|
|
8
|
+
DEFAULT_CACHE_CONFIG: () => DEFAULT_CACHE_CONFIG,
|
|
9
|
+
DEFAULT_DATABASE_CONFIG: () => DEFAULT_DATABASE_CONFIG,
|
|
10
|
+
DEFAULT_EVENT_QUEUE_CONFIG: () => DEFAULT_EVENT_QUEUE_CONFIG,
|
|
11
|
+
DEFAULT_FEATURE_FLAGS: () => DEFAULT_FEATURE_FLAGS,
|
|
12
|
+
DEFAULT_GRAPHQL_CONFIG: () => DEFAULT_GRAPHQL_CONFIG,
|
|
13
|
+
DEFAULT_HTTP_CONFIG: () => DEFAULT_HTTP_CONFIG,
|
|
14
|
+
DEFAULT_LOGGING_CONFIG: () => DEFAULT_LOGGING_CONFIG,
|
|
15
|
+
DEFAULT_METRICS_CONFIG: () => DEFAULT_METRICS_CONFIG,
|
|
16
|
+
DEFAULT_TRACING_CONFIG: () => DEFAULT_TRACING_CONFIG,
|
|
17
|
+
ENV_VARS: () => ENV_VARS,
|
|
18
|
+
Instrument: () => Instrument,
|
|
19
|
+
Log: () => Log,
|
|
20
|
+
Metric: () => Metric,
|
|
21
|
+
MetricsRegistry: () => MetricsRegistry,
|
|
22
|
+
STANDARD_METRICS: () => STANDARD_METRICS,
|
|
23
|
+
SpanKind: () => SpanKind,
|
|
24
|
+
SpanStatus: () => SpanStatus,
|
|
25
|
+
Trace: () => Trace,
|
|
26
|
+
Tracer: () => Tracer,
|
|
27
|
+
buildDatabaseConfig: () => buildDatabaseConfig,
|
|
28
|
+
buildFeatureFlags: () => buildFeatureFlags,
|
|
29
|
+
buildGraphQLConfig: () => buildGraphQLConfig,
|
|
30
|
+
buildInstrumentationConfig: () => buildInstrumentationConfig,
|
|
31
|
+
buildMetricsConfig: () => buildMetricsConfig,
|
|
32
|
+
buildTracingConfig: () => buildTracingConfig,
|
|
33
|
+
createApolloInlineTracePlugin: () => createApolloInlineTracePlugin,
|
|
34
|
+
createCounter: () => createCounter,
|
|
35
|
+
createGauge: () => createGauge,
|
|
36
|
+
createGraphQLInstrumentationPlugin: () => createGraphQLInstrumentationPlugin,
|
|
37
|
+
createHistogram: () => createHistogram,
|
|
38
|
+
createPrometheusPlugin: () => createPrometheusPlugin,
|
|
39
|
+
createUpDownCounter: () => createUpDownCounter,
|
|
40
|
+
extractOperationInfo: () => extractOperationInfo,
|
|
41
|
+
extractTraceContext: () => extractTraceContext,
|
|
42
|
+
getGraphQLOperationFromContext: () => getGraphQLOperationFromContext,
|
|
43
|
+
getGraphQLSpanFromContext: () => getGraphQLSpanFromContext,
|
|
44
|
+
getInstrumentationConfig: () => getInstrumentationConfig,
|
|
45
|
+
getLogger: () => getLogger,
|
|
46
|
+
getMetricsRegistry: () => getMetricsRegistry,
|
|
47
|
+
getTraceContext: () => getTraceContext,
|
|
48
|
+
getTracer: () => getTracer,
|
|
49
|
+
initializeInstrumentation: () => initializeInstrumentation,
|
|
50
|
+
initializeInstrumentationConfig: () => initializeInstrumentationConfig,
|
|
51
|
+
initializeMetricsRegistry: () => initializeMetricsRegistry,
|
|
52
|
+
initializeTracer: () => initializeTracer,
|
|
53
|
+
injectTraceContext: () => injectTraceContext,
|
|
54
|
+
instrumentResolver: () => instrumentResolver,
|
|
55
|
+
instrumentResolverMap: () => instrumentResolverMap,
|
|
56
|
+
instrumented: () => instrumented,
|
|
57
|
+
isApolloInlineTraceAvailable: () => isApolloInlineTraceAvailable,
|
|
58
|
+
isFeatureEnabled: () => isFeatureEnabled,
|
|
59
|
+
isInstrumentationConfigInitialized: () => isInstrumentationConfigInitialized,
|
|
60
|
+
isInstrumentationInitialized: () => isInstrumentationInitialized,
|
|
61
|
+
isMetricsRegistryInitialized: () => isMetricsRegistryInitialized,
|
|
62
|
+
isPrometheusAvailable: () => isPrometheusAvailable,
|
|
63
|
+
isTracerInitialized: () => isTracerInitialized,
|
|
64
|
+
logger: () => logger,
|
|
65
|
+
resetInstrumentation: () => resetInstrumentation,
|
|
66
|
+
resetInstrumentationConfig: () => resetInstrumentationConfig,
|
|
67
|
+
resetMetricsRegistry: () => resetMetricsRegistry,
|
|
68
|
+
setupInstrumentation: () => setupInstrumentation,
|
|
69
|
+
startSpan: () => startSpan,
|
|
70
|
+
traced: () => traced,
|
|
71
|
+
updateInstrumentationConfig: () => updateInstrumentationConfig,
|
|
72
|
+
withSpan: () => withSpan
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// src/instrumentation/config.ts
|
|
76
|
+
var ENV_VARS = {
|
|
77
|
+
// Master switch
|
|
78
|
+
INSTRUMENTATION_ENABLED: "INSTRUMENTATION_ENABLED",
|
|
79
|
+
// Feature flags
|
|
80
|
+
INSTRUMENTATION_TRACING: "INSTRUMENTATION_TRACING",
|
|
81
|
+
INSTRUMENTATION_METRICS: "INSTRUMENTATION_METRICS",
|
|
82
|
+
INSTRUMENTATION_LOGGING: "INSTRUMENTATION_LOGGING",
|
|
83
|
+
INSTRUMENTATION_GRAPHQL: "INSTRUMENTATION_GRAPHQL",
|
|
84
|
+
INSTRUMENTATION_DATABASE: "INSTRUMENTATION_DATABASE",
|
|
85
|
+
INSTRUMENTATION_HTTP: "INSTRUMENTATION_HTTP",
|
|
86
|
+
INSTRUMENTATION_CACHE: "INSTRUMENTATION_CACHE",
|
|
87
|
+
INSTRUMENTATION_EVENT_QUEUE: "INSTRUMENTATION_EVENT_QUEUE",
|
|
88
|
+
// Tracing
|
|
89
|
+
OTEL_SERVICE_NAME: "OTEL_SERVICE_NAME",
|
|
90
|
+
OTEL_SERVICE_VERSION: "OTEL_SERVICE_VERSION",
|
|
91
|
+
OTEL_ENVIRONMENT: "OTEL_ENVIRONMENT",
|
|
92
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "OTEL_EXPORTER_OTLP_ENDPOINT",
|
|
93
|
+
OTEL_EXPORTER_TYPE: "OTEL_EXPORTER_TYPE",
|
|
94
|
+
OTEL_SAMPLING_RATE: "OTEL_SAMPLING_RATE",
|
|
95
|
+
OTEL_PROPAGATION_FORMAT: "OTEL_PROPAGATION_FORMAT",
|
|
96
|
+
// Metrics
|
|
97
|
+
METRICS_EXPORTER_TYPE: "METRICS_EXPORTER_TYPE",
|
|
98
|
+
METRICS_PROMETHEUS_ENDPOINT: "METRICS_PROMETHEUS_ENDPOINT",
|
|
99
|
+
METRICS_PROMETHEUS_PORT: "METRICS_PROMETHEUS_PORT",
|
|
100
|
+
METRICS_COLLECT_INTERVAL: "METRICS_COLLECT_INTERVAL",
|
|
101
|
+
METRICS_DEFAULT_ENABLED: "METRICS_DEFAULT_ENABLED",
|
|
102
|
+
METRICS_PREFIX: "METRICS_PREFIX",
|
|
103
|
+
// Database
|
|
104
|
+
DB_INSTRUMENTATION_INCLUDE_STATEMENT: "DB_INSTRUMENTATION_INCLUDE_STATEMENT",
|
|
105
|
+
DB_INSTRUMENTATION_SLOW_QUERY_THRESHOLD: "DB_INSTRUMENTATION_SLOW_QUERY_THRESHOLD",
|
|
106
|
+
// GraphQL
|
|
107
|
+
GRAPHQL_INSTRUMENTATION_INCLUDE_DOCUMENT: "GRAPHQL_INSTRUMENTATION_INCLUDE_DOCUMENT",
|
|
108
|
+
GRAPHQL_INSTRUMENTATION_INCLUDE_VARIABLES: "GRAPHQL_INSTRUMENTATION_INCLUDE_VARIABLES",
|
|
109
|
+
GRAPHQL_INSTRUMENTATION_INCLUDE_RESOLVERS: "GRAPHQL_INSTRUMENTATION_INCLUDE_RESOLVERS"
|
|
110
|
+
};
|
|
111
|
+
function getEnvBoolean(key, defaultValue) {
|
|
112
|
+
const value = process.env[key];
|
|
113
|
+
if (value === void 0 || value === "") return defaultValue;
|
|
114
|
+
return value.toLowerCase() === "true" || value === "1";
|
|
115
|
+
}
|
|
116
|
+
__name(getEnvBoolean, "getEnvBoolean");
|
|
117
|
+
function getEnvNumber(key, defaultValue) {
|
|
118
|
+
const value = process.env[key];
|
|
119
|
+
if (value === void 0 || value === "") return defaultValue;
|
|
120
|
+
const parsed = parseFloat(value);
|
|
121
|
+
return isNaN(parsed) ? defaultValue : parsed;
|
|
122
|
+
}
|
|
123
|
+
__name(getEnvNumber, "getEnvNumber");
|
|
124
|
+
function getEnvString(key, defaultValue) {
|
|
125
|
+
const value = process.env[key];
|
|
126
|
+
return value !== void 0 && value !== "" ? value : defaultValue;
|
|
127
|
+
}
|
|
128
|
+
__name(getEnvString, "getEnvString");
|
|
129
|
+
var DEFAULT_FEATURE_FLAGS = {
|
|
130
|
+
tracing: true,
|
|
131
|
+
metrics: true,
|
|
132
|
+
logging: true,
|
|
133
|
+
graphql: true,
|
|
134
|
+
database: true,
|
|
135
|
+
http: true,
|
|
136
|
+
cache: true,
|
|
137
|
+
eventQueue: true
|
|
138
|
+
};
|
|
139
|
+
var DEFAULT_TRACING_CONFIG = {
|
|
140
|
+
enabled: true,
|
|
141
|
+
serviceName: "unknown-service",
|
|
142
|
+
serviceVersion: "1.0.0",
|
|
143
|
+
environment: "development",
|
|
144
|
+
exporterType: "none",
|
|
145
|
+
samplingRate: 1,
|
|
146
|
+
propagationFormat: "w3c",
|
|
147
|
+
resourceAttributes: {},
|
|
148
|
+
ignoredRoutes: [
|
|
149
|
+
"/health",
|
|
150
|
+
"/ready",
|
|
151
|
+
"/live",
|
|
152
|
+
"/metrics"
|
|
153
|
+
],
|
|
154
|
+
ignoredOperations: [
|
|
155
|
+
"IntrospectionQuery"
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
var DEFAULT_METRICS_CONFIG = {
|
|
159
|
+
enabled: true,
|
|
160
|
+
serviceName: "unknown-service",
|
|
161
|
+
exporterType: "none",
|
|
162
|
+
prometheusEndpoint: "/metrics",
|
|
163
|
+
prometheusPort: 9090,
|
|
164
|
+
collectInterval: 6e4,
|
|
165
|
+
defaultMetrics: true,
|
|
166
|
+
metricPrefix: ""
|
|
167
|
+
};
|
|
168
|
+
var DEFAULT_LOGGING_CONFIG = {
|
|
169
|
+
enabled: true,
|
|
170
|
+
includeTraceId: true,
|
|
171
|
+
includeSpanId: true,
|
|
172
|
+
includeTraceFlags: false,
|
|
173
|
+
level: "info"
|
|
174
|
+
};
|
|
175
|
+
var DEFAULT_GRAPHQL_CONFIG = {
|
|
176
|
+
enabled: true,
|
|
177
|
+
includeDocument: false,
|
|
178
|
+
includeVariables: false,
|
|
179
|
+
includeResult: false,
|
|
180
|
+
documentDepth: 3,
|
|
181
|
+
ignoredOperations: [
|
|
182
|
+
"IntrospectionQuery"
|
|
183
|
+
],
|
|
184
|
+
includeResolvers: true,
|
|
185
|
+
resolverSpanDepth: 3
|
|
186
|
+
};
|
|
187
|
+
var DEFAULT_DATABASE_CONFIG = {
|
|
188
|
+
enabled: true,
|
|
189
|
+
includeStatement: false,
|
|
190
|
+
includeParameters: false,
|
|
191
|
+
includeRowCount: true,
|
|
192
|
+
slowQueryThreshold: 1e3,
|
|
193
|
+
ignoredOperations: []
|
|
194
|
+
};
|
|
195
|
+
var DEFAULT_HTTP_CONFIG = {
|
|
196
|
+
enabled: true,
|
|
197
|
+
includeRequestHeaders: false,
|
|
198
|
+
includeResponseHeaders: false,
|
|
199
|
+
includeRequestBody: false,
|
|
200
|
+
includeResponseBody: false,
|
|
201
|
+
redactedHeaders: [
|
|
202
|
+
"authorization",
|
|
203
|
+
"cookie",
|
|
204
|
+
"set-cookie",
|
|
205
|
+
"x-api-key"
|
|
206
|
+
],
|
|
207
|
+
ignoredRoutes: [
|
|
208
|
+
"/health",
|
|
209
|
+
"/ready",
|
|
210
|
+
"/live",
|
|
211
|
+
"/metrics"
|
|
212
|
+
],
|
|
213
|
+
maxBodySize: 10240
|
|
214
|
+
};
|
|
215
|
+
var DEFAULT_CACHE_CONFIG = {
|
|
216
|
+
enabled: true,
|
|
217
|
+
includeKey: true,
|
|
218
|
+
includeValueSize: true,
|
|
219
|
+
includeTTL: true
|
|
220
|
+
};
|
|
221
|
+
var DEFAULT_EVENT_QUEUE_CONFIG = {
|
|
222
|
+
enabled: true,
|
|
223
|
+
includePayload: false,
|
|
224
|
+
includeHeaders: true,
|
|
225
|
+
maxPayloadSize: 1024
|
|
226
|
+
};
|
|
227
|
+
var globalConfig = null;
|
|
228
|
+
function buildFeatureFlags(overrides) {
|
|
229
|
+
return {
|
|
230
|
+
tracing: getEnvBoolean(ENV_VARS.INSTRUMENTATION_TRACING, DEFAULT_FEATURE_FLAGS.tracing),
|
|
231
|
+
metrics: getEnvBoolean(ENV_VARS.INSTRUMENTATION_METRICS, DEFAULT_FEATURE_FLAGS.metrics),
|
|
232
|
+
logging: getEnvBoolean(ENV_VARS.INSTRUMENTATION_LOGGING, DEFAULT_FEATURE_FLAGS.logging),
|
|
233
|
+
graphql: getEnvBoolean(ENV_VARS.INSTRUMENTATION_GRAPHQL, DEFAULT_FEATURE_FLAGS.graphql),
|
|
234
|
+
database: getEnvBoolean(ENV_VARS.INSTRUMENTATION_DATABASE, DEFAULT_FEATURE_FLAGS.database),
|
|
235
|
+
http: getEnvBoolean(ENV_VARS.INSTRUMENTATION_HTTP, DEFAULT_FEATURE_FLAGS.http),
|
|
236
|
+
cache: getEnvBoolean(ENV_VARS.INSTRUMENTATION_CACHE, DEFAULT_FEATURE_FLAGS.cache),
|
|
237
|
+
eventQueue: getEnvBoolean(ENV_VARS.INSTRUMENTATION_EVENT_QUEUE, DEFAULT_FEATURE_FLAGS.eventQueue),
|
|
238
|
+
...overrides
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
__name(buildFeatureFlags, "buildFeatureFlags");
|
|
242
|
+
function buildTracingConfig(serviceName, overrides) {
|
|
243
|
+
return {
|
|
244
|
+
enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_TRACING, DEFAULT_TRACING_CONFIG.enabled),
|
|
245
|
+
serviceName: getEnvString(ENV_VARS.OTEL_SERVICE_NAME, serviceName),
|
|
246
|
+
serviceVersion: getEnvString(ENV_VARS.OTEL_SERVICE_VERSION, DEFAULT_TRACING_CONFIG.serviceVersion),
|
|
247
|
+
environment: getEnvString(ENV_VARS.OTEL_ENVIRONMENT, process.env["NODE_ENV"] || "development"),
|
|
248
|
+
exporterEndpoint: process.env[ENV_VARS.OTEL_EXPORTER_OTLP_ENDPOINT],
|
|
249
|
+
exporterType: getEnvString(ENV_VARS.OTEL_EXPORTER_TYPE, DEFAULT_TRACING_CONFIG.exporterType),
|
|
250
|
+
samplingRate: getEnvNumber(ENV_VARS.OTEL_SAMPLING_RATE, DEFAULT_TRACING_CONFIG.samplingRate),
|
|
251
|
+
propagationFormat: getEnvString(ENV_VARS.OTEL_PROPAGATION_FORMAT, DEFAULT_TRACING_CONFIG.propagationFormat),
|
|
252
|
+
resourceAttributes: DEFAULT_TRACING_CONFIG.resourceAttributes,
|
|
253
|
+
ignoredRoutes: DEFAULT_TRACING_CONFIG.ignoredRoutes,
|
|
254
|
+
ignoredOperations: DEFAULT_TRACING_CONFIG.ignoredOperations,
|
|
255
|
+
...overrides
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
__name(buildTracingConfig, "buildTracingConfig");
|
|
259
|
+
function buildMetricsConfig(serviceName, overrides) {
|
|
260
|
+
return {
|
|
261
|
+
enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_METRICS, DEFAULT_METRICS_CONFIG.enabled),
|
|
262
|
+
serviceName: getEnvString(ENV_VARS.OTEL_SERVICE_NAME, serviceName),
|
|
263
|
+
exporterEndpoint: process.env[ENV_VARS.OTEL_EXPORTER_OTLP_ENDPOINT],
|
|
264
|
+
exporterType: getEnvString(ENV_VARS.METRICS_EXPORTER_TYPE, DEFAULT_METRICS_CONFIG.exporterType),
|
|
265
|
+
prometheusEndpoint: getEnvString(ENV_VARS.METRICS_PROMETHEUS_ENDPOINT, DEFAULT_METRICS_CONFIG.prometheusEndpoint),
|
|
266
|
+
prometheusPort: getEnvNumber(ENV_VARS.METRICS_PROMETHEUS_PORT, DEFAULT_METRICS_CONFIG.prometheusPort),
|
|
267
|
+
collectInterval: getEnvNumber(ENV_VARS.METRICS_COLLECT_INTERVAL, DEFAULT_METRICS_CONFIG.collectInterval),
|
|
268
|
+
defaultMetrics: getEnvBoolean(ENV_VARS.METRICS_DEFAULT_ENABLED, DEFAULT_METRICS_CONFIG.defaultMetrics),
|
|
269
|
+
metricPrefix: getEnvString(ENV_VARS.METRICS_PREFIX, DEFAULT_METRICS_CONFIG.metricPrefix),
|
|
270
|
+
...overrides
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
__name(buildMetricsConfig, "buildMetricsConfig");
|
|
274
|
+
function buildDatabaseConfig(overrides) {
|
|
275
|
+
return {
|
|
276
|
+
enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_DATABASE, DEFAULT_DATABASE_CONFIG.enabled),
|
|
277
|
+
includeStatement: getEnvBoolean(ENV_VARS.DB_INSTRUMENTATION_INCLUDE_STATEMENT, DEFAULT_DATABASE_CONFIG.includeStatement),
|
|
278
|
+
includeParameters: DEFAULT_DATABASE_CONFIG.includeParameters,
|
|
279
|
+
includeRowCount: DEFAULT_DATABASE_CONFIG.includeRowCount,
|
|
280
|
+
slowQueryThreshold: getEnvNumber(ENV_VARS.DB_INSTRUMENTATION_SLOW_QUERY_THRESHOLD, DEFAULT_DATABASE_CONFIG.slowQueryThreshold),
|
|
281
|
+
ignoredOperations: DEFAULT_DATABASE_CONFIG.ignoredOperations,
|
|
282
|
+
...overrides
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
__name(buildDatabaseConfig, "buildDatabaseConfig");
|
|
286
|
+
function buildGraphQLConfig(overrides) {
|
|
287
|
+
return {
|
|
288
|
+
enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_GRAPHQL, DEFAULT_GRAPHQL_CONFIG.enabled),
|
|
289
|
+
includeDocument: getEnvBoolean(ENV_VARS.GRAPHQL_INSTRUMENTATION_INCLUDE_DOCUMENT, DEFAULT_GRAPHQL_CONFIG.includeDocument),
|
|
290
|
+
includeVariables: getEnvBoolean(ENV_VARS.GRAPHQL_INSTRUMENTATION_INCLUDE_VARIABLES, DEFAULT_GRAPHQL_CONFIG.includeVariables),
|
|
291
|
+
includeResult: DEFAULT_GRAPHQL_CONFIG.includeResult,
|
|
292
|
+
documentDepth: DEFAULT_GRAPHQL_CONFIG.documentDepth,
|
|
293
|
+
ignoredOperations: DEFAULT_GRAPHQL_CONFIG.ignoredOperations,
|
|
294
|
+
includeResolvers: getEnvBoolean(ENV_VARS.GRAPHQL_INSTRUMENTATION_INCLUDE_RESOLVERS, DEFAULT_GRAPHQL_CONFIG.includeResolvers),
|
|
295
|
+
resolverSpanDepth: DEFAULT_GRAPHQL_CONFIG.resolverSpanDepth,
|
|
296
|
+
...overrides
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
__name(buildGraphQLConfig, "buildGraphQLConfig");
|
|
300
|
+
function buildInstrumentationConfig(serviceName, overrides) {
|
|
301
|
+
const enabled = getEnvBoolean(ENV_VARS.INSTRUMENTATION_ENABLED, true);
|
|
302
|
+
return {
|
|
303
|
+
enabled,
|
|
304
|
+
features: buildFeatureFlags(overrides?.features),
|
|
305
|
+
tracing: buildTracingConfig(serviceName, overrides?.tracing),
|
|
306
|
+
metrics: buildMetricsConfig(serviceName, overrides?.metrics),
|
|
307
|
+
logging: {
|
|
308
|
+
...DEFAULT_LOGGING_CONFIG,
|
|
309
|
+
...overrides?.logging
|
|
310
|
+
},
|
|
311
|
+
graphql: buildGraphQLConfig(overrides?.graphql),
|
|
312
|
+
database: buildDatabaseConfig(overrides?.database),
|
|
313
|
+
http: {
|
|
314
|
+
...DEFAULT_HTTP_CONFIG,
|
|
315
|
+
...overrides?.http
|
|
316
|
+
},
|
|
317
|
+
cache: {
|
|
318
|
+
...DEFAULT_CACHE_CONFIG,
|
|
319
|
+
...overrides?.cache
|
|
320
|
+
},
|
|
321
|
+
eventQueue: {
|
|
322
|
+
...DEFAULT_EVENT_QUEUE_CONFIG,
|
|
323
|
+
...overrides?.eventQueue
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
__name(buildInstrumentationConfig, "buildInstrumentationConfig");
|
|
328
|
+
function initializeInstrumentationConfig(serviceName, overrides) {
|
|
329
|
+
globalConfig = buildInstrumentationConfig(serviceName, overrides);
|
|
330
|
+
return globalConfig;
|
|
331
|
+
}
|
|
332
|
+
__name(initializeInstrumentationConfig, "initializeInstrumentationConfig");
|
|
333
|
+
function getInstrumentationConfig() {
|
|
334
|
+
if (!globalConfig) {
|
|
335
|
+
throw new Error("Instrumentation config not initialized. Call initializeInstrumentationConfig() first.");
|
|
336
|
+
}
|
|
337
|
+
return globalConfig;
|
|
338
|
+
}
|
|
339
|
+
__name(getInstrumentationConfig, "getInstrumentationConfig");
|
|
340
|
+
function isInstrumentationConfigInitialized() {
|
|
341
|
+
return globalConfig !== null;
|
|
342
|
+
}
|
|
343
|
+
__name(isInstrumentationConfigInitialized, "isInstrumentationConfigInitialized");
|
|
344
|
+
function isFeatureEnabled(feature) {
|
|
345
|
+
if (!globalConfig) return false;
|
|
346
|
+
return globalConfig.enabled && globalConfig.features[feature];
|
|
347
|
+
}
|
|
348
|
+
__name(isFeatureEnabled, "isFeatureEnabled");
|
|
349
|
+
function updateInstrumentationConfig(updates) {
|
|
350
|
+
if (!globalConfig) {
|
|
351
|
+
throw new Error("Instrumentation config not initialized. Call initializeInstrumentationConfig() first.");
|
|
352
|
+
}
|
|
353
|
+
globalConfig = {
|
|
354
|
+
...globalConfig,
|
|
355
|
+
...updates
|
|
356
|
+
};
|
|
357
|
+
return globalConfig;
|
|
358
|
+
}
|
|
359
|
+
__name(updateInstrumentationConfig, "updateInstrumentationConfig");
|
|
360
|
+
function resetInstrumentationConfig() {
|
|
361
|
+
globalConfig = null;
|
|
362
|
+
}
|
|
363
|
+
__name(resetInstrumentationConfig, "resetInstrumentationConfig");
|
|
364
|
+
|
|
365
|
+
// src/instrumentation/metrics-collector.ts
|
|
366
|
+
function getLabelKey(labels) {
|
|
367
|
+
if (!labels || Object.keys(labels).length === 0) return "";
|
|
368
|
+
return Object.entries(labels).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}=${v}`).join(",");
|
|
369
|
+
}
|
|
370
|
+
__name(getLabelKey, "getLabelKey");
|
|
371
|
+
var InMemoryCounter = class InMemoryCounter2 {
|
|
372
|
+
static {
|
|
373
|
+
__name(this, "InMemoryCounter");
|
|
374
|
+
}
|
|
375
|
+
values = /* @__PURE__ */ new Map();
|
|
376
|
+
name;
|
|
377
|
+
description;
|
|
378
|
+
constructor(name, description) {
|
|
379
|
+
this.name = name;
|
|
380
|
+
this.description = description;
|
|
381
|
+
}
|
|
382
|
+
add(value, labels) {
|
|
383
|
+
const key = getLabelKey(labels);
|
|
384
|
+
const current = this.values.get(key) || 0;
|
|
385
|
+
this.values.set(key, current + value);
|
|
386
|
+
}
|
|
387
|
+
inc(labels) {
|
|
388
|
+
this.add(1, labels);
|
|
389
|
+
}
|
|
390
|
+
getValue(labels) {
|
|
391
|
+
const key = getLabelKey(labels);
|
|
392
|
+
return this.values.get(key) || 0;
|
|
393
|
+
}
|
|
394
|
+
getName() {
|
|
395
|
+
return this.name;
|
|
396
|
+
}
|
|
397
|
+
getDescription() {
|
|
398
|
+
return this.description;
|
|
399
|
+
}
|
|
400
|
+
getAllValues() {
|
|
401
|
+
return new Map(this.values);
|
|
402
|
+
}
|
|
403
|
+
reset() {
|
|
404
|
+
this.values.clear();
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
var InMemoryHistogram = class InMemoryHistogram2 {
|
|
408
|
+
static {
|
|
409
|
+
__name(this, "InMemoryHistogram");
|
|
410
|
+
}
|
|
411
|
+
values = /* @__PURE__ */ new Map();
|
|
412
|
+
name;
|
|
413
|
+
description;
|
|
414
|
+
boundaries;
|
|
415
|
+
constructor(name, description, boundaries) {
|
|
416
|
+
this.name = name;
|
|
417
|
+
this.description = description;
|
|
418
|
+
this.boundaries = boundaries || [
|
|
419
|
+
5,
|
|
420
|
+
10,
|
|
421
|
+
25,
|
|
422
|
+
50,
|
|
423
|
+
100,
|
|
424
|
+
250,
|
|
425
|
+
500,
|
|
426
|
+
1e3,
|
|
427
|
+
2500,
|
|
428
|
+
5e3,
|
|
429
|
+
1e4
|
|
430
|
+
];
|
|
431
|
+
}
|
|
432
|
+
record(value, labels) {
|
|
433
|
+
const key = getLabelKey(labels);
|
|
434
|
+
const existing = this.values.get(key) || [];
|
|
435
|
+
existing.push(value);
|
|
436
|
+
if (existing.length > 1e4) {
|
|
437
|
+
existing.shift();
|
|
438
|
+
}
|
|
439
|
+
this.values.set(key, existing);
|
|
440
|
+
}
|
|
441
|
+
getData(labels) {
|
|
442
|
+
const key = getLabelKey(labels);
|
|
443
|
+
const values = this.values.get(key) || [];
|
|
444
|
+
if (values.length === 0) {
|
|
445
|
+
return {
|
|
446
|
+
count: 0,
|
|
447
|
+
sum: 0,
|
|
448
|
+
min: 0,
|
|
449
|
+
max: 0,
|
|
450
|
+
avg: 0,
|
|
451
|
+
buckets: /* @__PURE__ */ new Map(),
|
|
452
|
+
percentiles: {
|
|
453
|
+
p50: 0,
|
|
454
|
+
p75: 0,
|
|
455
|
+
p90: 0,
|
|
456
|
+
p95: 0,
|
|
457
|
+
p99: 0
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
const sorted = [
|
|
462
|
+
...values
|
|
463
|
+
].sort((a, b) => a - b);
|
|
464
|
+
const sum = values.reduce((a, b) => a + b, 0);
|
|
465
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
466
|
+
for (const boundary of this.boundaries) {
|
|
467
|
+
buckets.set(boundary, values.filter((v) => v <= boundary).length);
|
|
468
|
+
}
|
|
469
|
+
buckets.set(Infinity, values.length);
|
|
470
|
+
const percentile = /* @__PURE__ */ __name((p) => {
|
|
471
|
+
const index = Math.ceil(p / 100 * sorted.length) - 1;
|
|
472
|
+
return sorted[Math.max(0, index)] || 0;
|
|
473
|
+
}, "percentile");
|
|
474
|
+
return {
|
|
475
|
+
count: values.length,
|
|
476
|
+
sum,
|
|
477
|
+
min: sorted[0] || 0,
|
|
478
|
+
max: sorted[sorted.length - 1] || 0,
|
|
479
|
+
avg: sum / values.length,
|
|
480
|
+
buckets,
|
|
481
|
+
percentiles: {
|
|
482
|
+
p50: percentile(50),
|
|
483
|
+
p75: percentile(75),
|
|
484
|
+
p90: percentile(90),
|
|
485
|
+
p95: percentile(95),
|
|
486
|
+
p99: percentile(99)
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
getName() {
|
|
491
|
+
return this.name;
|
|
492
|
+
}
|
|
493
|
+
getDescription() {
|
|
494
|
+
return this.description;
|
|
495
|
+
}
|
|
496
|
+
getAllData() {
|
|
497
|
+
const result = /* @__PURE__ */ new Map();
|
|
498
|
+
for (const [key] of this.values) {
|
|
499
|
+
result.set(key, this.getData(key ? this.parseLabels(key) : void 0));
|
|
500
|
+
}
|
|
501
|
+
return result;
|
|
502
|
+
}
|
|
503
|
+
parseLabels(key) {
|
|
504
|
+
const labels = {};
|
|
505
|
+
for (const part of key.split(",")) {
|
|
506
|
+
const [k, v] = part.split("=");
|
|
507
|
+
if (k && v) labels[k] = v;
|
|
508
|
+
}
|
|
509
|
+
return labels;
|
|
510
|
+
}
|
|
511
|
+
reset() {
|
|
512
|
+
this.values.clear();
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var InMemoryGauge = class InMemoryGauge2 {
|
|
516
|
+
static {
|
|
517
|
+
__name(this, "InMemoryGauge");
|
|
518
|
+
}
|
|
519
|
+
values = /* @__PURE__ */ new Map();
|
|
520
|
+
name;
|
|
521
|
+
description;
|
|
522
|
+
constructor(name, description) {
|
|
523
|
+
this.name = name;
|
|
524
|
+
this.description = description;
|
|
525
|
+
}
|
|
526
|
+
set(value, labels) {
|
|
527
|
+
const key = getLabelKey(labels);
|
|
528
|
+
this.values.set(key, value);
|
|
529
|
+
}
|
|
530
|
+
// eslint-disable-next-line sonarjs/no-identical-functions -- Shared implementation across metric types by design
|
|
531
|
+
add(value, labels) {
|
|
532
|
+
const key = getLabelKey(labels);
|
|
533
|
+
const current = this.values.get(key) || 0;
|
|
534
|
+
this.values.set(key, current + value);
|
|
535
|
+
}
|
|
536
|
+
sub(value, labels) {
|
|
537
|
+
this.add(-value, labels);
|
|
538
|
+
}
|
|
539
|
+
getValue(labels) {
|
|
540
|
+
const key = getLabelKey(labels);
|
|
541
|
+
return this.values.get(key) || 0;
|
|
542
|
+
}
|
|
543
|
+
getName() {
|
|
544
|
+
return this.name;
|
|
545
|
+
}
|
|
546
|
+
getDescription() {
|
|
547
|
+
return this.description;
|
|
548
|
+
}
|
|
549
|
+
getAllValues() {
|
|
550
|
+
return new Map(this.values);
|
|
551
|
+
}
|
|
552
|
+
reset() {
|
|
553
|
+
this.values.clear();
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
var InMemoryUpDownCounter = class InMemoryUpDownCounter2 {
|
|
557
|
+
static {
|
|
558
|
+
__name(this, "InMemoryUpDownCounter");
|
|
559
|
+
}
|
|
560
|
+
values = /* @__PURE__ */ new Map();
|
|
561
|
+
name;
|
|
562
|
+
description;
|
|
563
|
+
constructor(name, description) {
|
|
564
|
+
this.name = name;
|
|
565
|
+
this.description = description;
|
|
566
|
+
}
|
|
567
|
+
// eslint-disable-next-line sonarjs/no-identical-functions -- Shared implementation across metric types by design
|
|
568
|
+
add(value, labels) {
|
|
569
|
+
const key = getLabelKey(labels);
|
|
570
|
+
const current = this.values.get(key) || 0;
|
|
571
|
+
this.values.set(key, current + value);
|
|
572
|
+
}
|
|
573
|
+
getValue(labels) {
|
|
574
|
+
const key = getLabelKey(labels);
|
|
575
|
+
return this.values.get(key) || 0;
|
|
576
|
+
}
|
|
577
|
+
getName() {
|
|
578
|
+
return this.name;
|
|
579
|
+
}
|
|
580
|
+
getDescription() {
|
|
581
|
+
return this.description;
|
|
582
|
+
}
|
|
583
|
+
getAllValues() {
|
|
584
|
+
return new Map(this.values);
|
|
585
|
+
}
|
|
586
|
+
reset() {
|
|
587
|
+
this.values.clear();
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
var NoOpCounter = class NoOpCounter2 {
|
|
591
|
+
static {
|
|
592
|
+
__name(this, "NoOpCounter");
|
|
593
|
+
}
|
|
594
|
+
add() {
|
|
595
|
+
}
|
|
596
|
+
inc() {
|
|
597
|
+
}
|
|
598
|
+
getValue() {
|
|
599
|
+
return 0;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
var NoOpHistogram = class NoOpHistogram2 {
|
|
603
|
+
static {
|
|
604
|
+
__name(this, "NoOpHistogram");
|
|
605
|
+
}
|
|
606
|
+
record() {
|
|
607
|
+
}
|
|
608
|
+
getData() {
|
|
609
|
+
return {
|
|
610
|
+
count: 0,
|
|
611
|
+
sum: 0,
|
|
612
|
+
min: 0,
|
|
613
|
+
max: 0,
|
|
614
|
+
avg: 0,
|
|
615
|
+
buckets: /* @__PURE__ */ new Map(),
|
|
616
|
+
percentiles: {
|
|
617
|
+
p50: 0,
|
|
618
|
+
p75: 0,
|
|
619
|
+
p90: 0,
|
|
620
|
+
p95: 0,
|
|
621
|
+
p99: 0
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
var NoOpGauge = class NoOpGauge2 {
|
|
627
|
+
static {
|
|
628
|
+
__name(this, "NoOpGauge");
|
|
629
|
+
}
|
|
630
|
+
set() {
|
|
631
|
+
}
|
|
632
|
+
add() {
|
|
633
|
+
}
|
|
634
|
+
sub() {
|
|
635
|
+
}
|
|
636
|
+
getValue() {
|
|
637
|
+
return 0;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
var NoOpUpDownCounter = class NoOpUpDownCounter2 {
|
|
641
|
+
static {
|
|
642
|
+
__name(this, "NoOpUpDownCounter");
|
|
643
|
+
}
|
|
644
|
+
add() {
|
|
645
|
+
}
|
|
646
|
+
getValue() {
|
|
647
|
+
return 0;
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
var MetricsRegistry = class {
|
|
651
|
+
static {
|
|
652
|
+
__name(this, "MetricsRegistry");
|
|
653
|
+
}
|
|
654
|
+
counters = /* @__PURE__ */ new Map();
|
|
655
|
+
histograms = /* @__PURE__ */ new Map();
|
|
656
|
+
gauges = /* @__PURE__ */ new Map();
|
|
657
|
+
upDownCounters = /* @__PURE__ */ new Map();
|
|
658
|
+
serviceName;
|
|
659
|
+
metricPrefix;
|
|
660
|
+
constructor(serviceName, metricPrefix = "") {
|
|
661
|
+
this.serviceName = serviceName;
|
|
662
|
+
this.metricPrefix = metricPrefix;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Get service name
|
|
666
|
+
*/
|
|
667
|
+
getServiceName() {
|
|
668
|
+
return this.serviceName;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Check if metrics are enabled
|
|
672
|
+
*/
|
|
673
|
+
isEnabled() {
|
|
674
|
+
return isInstrumentationConfigInitialized() && isFeatureEnabled("metrics");
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Get prefixed metric name
|
|
678
|
+
*/
|
|
679
|
+
getPrefixedName(name) {
|
|
680
|
+
return this.metricPrefix ? `${this.metricPrefix}_${name}` : name;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Create or get a counter
|
|
684
|
+
*/
|
|
685
|
+
createCounter(name, description) {
|
|
686
|
+
if (!this.isEnabled()) {
|
|
687
|
+
return new NoOpCounter();
|
|
688
|
+
}
|
|
689
|
+
const prefixedName = this.getPrefixedName(name);
|
|
690
|
+
let counter = this.counters.get(prefixedName);
|
|
691
|
+
if (!counter) {
|
|
692
|
+
counter = new InMemoryCounter(prefixedName, description);
|
|
693
|
+
this.counters.set(prefixedName, counter);
|
|
694
|
+
}
|
|
695
|
+
return counter;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Create or get a histogram
|
|
699
|
+
*/
|
|
700
|
+
createHistogram(name, description, boundaries) {
|
|
701
|
+
if (!this.isEnabled()) {
|
|
702
|
+
return new NoOpHistogram();
|
|
703
|
+
}
|
|
704
|
+
const prefixedName = this.getPrefixedName(name);
|
|
705
|
+
let histogram = this.histograms.get(prefixedName);
|
|
706
|
+
if (!histogram) {
|
|
707
|
+
histogram = new InMemoryHistogram(prefixedName, description, boundaries);
|
|
708
|
+
this.histograms.set(prefixedName, histogram);
|
|
709
|
+
}
|
|
710
|
+
return histogram;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Create or get a gauge
|
|
714
|
+
*/
|
|
715
|
+
createGauge(name, description) {
|
|
716
|
+
if (!this.isEnabled()) {
|
|
717
|
+
return new NoOpGauge();
|
|
718
|
+
}
|
|
719
|
+
const prefixedName = this.getPrefixedName(name);
|
|
720
|
+
let gauge = this.gauges.get(prefixedName);
|
|
721
|
+
if (!gauge) {
|
|
722
|
+
gauge = new InMemoryGauge(prefixedName, description);
|
|
723
|
+
this.gauges.set(prefixedName, gauge);
|
|
724
|
+
}
|
|
725
|
+
return gauge;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Create or get an up-down counter
|
|
729
|
+
*/
|
|
730
|
+
createUpDownCounter(name, description) {
|
|
731
|
+
if (!this.isEnabled()) {
|
|
732
|
+
return new NoOpUpDownCounter();
|
|
733
|
+
}
|
|
734
|
+
const prefixedName = this.getPrefixedName(name);
|
|
735
|
+
let counter = this.upDownCounters.get(prefixedName);
|
|
736
|
+
if (!counter) {
|
|
737
|
+
counter = new InMemoryUpDownCounter(prefixedName, description);
|
|
738
|
+
this.upDownCounters.set(prefixedName, counter);
|
|
739
|
+
}
|
|
740
|
+
return counter;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Create metric from definition
|
|
744
|
+
*/
|
|
745
|
+
createFromDefinition(definition) {
|
|
746
|
+
switch (definition.type) {
|
|
747
|
+
case "counter":
|
|
748
|
+
return this.createCounter(definition.name, definition.description);
|
|
749
|
+
case "histogram":
|
|
750
|
+
return this.createHistogram(definition.name, definition.description, definition.boundaries);
|
|
751
|
+
case "gauge":
|
|
752
|
+
return this.createGauge(definition.name, definition.description);
|
|
753
|
+
case "upDownCounter":
|
|
754
|
+
return this.createUpDownCounter(definition.name, definition.description);
|
|
755
|
+
default:
|
|
756
|
+
throw new Error(`Unknown metric type: ${definition.type}`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Get all metrics data
|
|
761
|
+
*/
|
|
762
|
+
getAllMetrics() {
|
|
763
|
+
return {
|
|
764
|
+
counters: Array.from(this.counters.values()).map((c) => ({
|
|
765
|
+
name: c.getName(),
|
|
766
|
+
description: c.getDescription(),
|
|
767
|
+
values: c.getAllValues()
|
|
768
|
+
})),
|
|
769
|
+
histograms: Array.from(this.histograms.values()).map((h) => ({
|
|
770
|
+
name: h.getName(),
|
|
771
|
+
description: h.getDescription(),
|
|
772
|
+
data: h.getAllData()
|
|
773
|
+
})),
|
|
774
|
+
gauges: Array.from(this.gauges.values()).map((g) => ({
|
|
775
|
+
name: g.getName(),
|
|
776
|
+
description: g.getDescription(),
|
|
777
|
+
values: g.getAllValues()
|
|
778
|
+
})),
|
|
779
|
+
upDownCounters: Array.from(this.upDownCounters.values()).map((c) => ({
|
|
780
|
+
name: c.getName(),
|
|
781
|
+
description: c.getDescription(),
|
|
782
|
+
values: c.getAllValues()
|
|
783
|
+
}))
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Export counter metrics to Prometheus format
|
|
788
|
+
*/
|
|
789
|
+
exportCountersToPrometheus(lines) {
|
|
790
|
+
for (const counter of this.counters.values()) {
|
|
791
|
+
lines.push(`# HELP ${counter.getName()} ${counter.getDescription()}`);
|
|
792
|
+
lines.push(`# TYPE ${counter.getName()} counter`);
|
|
793
|
+
for (const [labels, value] of counter.getAllValues()) {
|
|
794
|
+
const labelStr = labels ? `{${labels}}` : "";
|
|
795
|
+
lines.push(`${counter.getName()}${labelStr} ${value}`);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Export histogram metrics to Prometheus format
|
|
801
|
+
*/
|
|
802
|
+
exportHistogramsToPrometheus(lines) {
|
|
803
|
+
for (const histogram of this.histograms.values()) {
|
|
804
|
+
lines.push(`# HELP ${histogram.getName()} ${histogram.getDescription()}`);
|
|
805
|
+
lines.push(`# TYPE ${histogram.getName()} histogram`);
|
|
806
|
+
for (const [labels, data] of histogram.getAllData()) {
|
|
807
|
+
const labelStr = labels ? `,${labels}` : "";
|
|
808
|
+
for (const [le, count] of data.buckets) {
|
|
809
|
+
const leStr = le === Infinity ? "+Inf" : le.toString();
|
|
810
|
+
lines.push(`${histogram.getName()}_bucket{le="${leStr}"${labelStr}} ${count}`);
|
|
811
|
+
}
|
|
812
|
+
lines.push(`${histogram.getName()}_sum{${labels || ""}} ${data.sum}`);
|
|
813
|
+
lines.push(`${histogram.getName()}_count{${labels || ""}} ${data.count}`);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Export gauge metrics to Prometheus format
|
|
819
|
+
*/
|
|
820
|
+
exportGaugesToPrometheus(lines) {
|
|
821
|
+
for (const gauge of this.gauges.values()) {
|
|
822
|
+
lines.push(`# HELP ${gauge.getName()} ${gauge.getDescription()}`);
|
|
823
|
+
lines.push(`# TYPE ${gauge.getName()} gauge`);
|
|
824
|
+
for (const [labels, value] of gauge.getAllValues()) {
|
|
825
|
+
const labelStr = labels ? `{${labels}}` : "";
|
|
826
|
+
lines.push(`${gauge.getName()}${labelStr} ${value}`);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Export up-down counter metrics to Prometheus format (as gauges)
|
|
832
|
+
*/
|
|
833
|
+
exportUpDownCountersToPrometheus(lines) {
|
|
834
|
+
for (const counter of this.upDownCounters.values()) {
|
|
835
|
+
lines.push(`# HELP ${counter.getName()} ${counter.getDescription()}`);
|
|
836
|
+
lines.push(`# TYPE ${counter.getName()} gauge`);
|
|
837
|
+
for (const [labels, value] of counter.getAllValues()) {
|
|
838
|
+
const labelStr = labels ? `{${labels}}` : "";
|
|
839
|
+
lines.push(`${counter.getName()}${labelStr} ${value}`);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Export metrics in Prometheus format
|
|
845
|
+
*/
|
|
846
|
+
toPrometheusFormat() {
|
|
847
|
+
const lines = [];
|
|
848
|
+
this.exportCountersToPrometheus(lines);
|
|
849
|
+
this.exportHistogramsToPrometheus(lines);
|
|
850
|
+
this.exportGaugesToPrometheus(lines);
|
|
851
|
+
this.exportUpDownCountersToPrometheus(lines);
|
|
852
|
+
return lines.join("\n");
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Reset all metrics
|
|
856
|
+
*/
|
|
857
|
+
reset() {
|
|
858
|
+
for (const counter of this.counters.values()) {
|
|
859
|
+
counter.reset();
|
|
860
|
+
}
|
|
861
|
+
for (const histogram of this.histograms.values()) {
|
|
862
|
+
histogram.reset();
|
|
863
|
+
}
|
|
864
|
+
for (const gauge of this.gauges.values()) {
|
|
865
|
+
gauge.reset();
|
|
866
|
+
}
|
|
867
|
+
for (const counter of this.upDownCounters.values()) {
|
|
868
|
+
counter.reset();
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Clear all metrics (remove registrations)
|
|
873
|
+
*/
|
|
874
|
+
clear() {
|
|
875
|
+
this.counters.clear();
|
|
876
|
+
this.histograms.clear();
|
|
877
|
+
this.gauges.clear();
|
|
878
|
+
this.upDownCounters.clear();
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
var globalRegistry = null;
|
|
882
|
+
function initializeMetricsRegistry(serviceName, metricPrefix = "") {
|
|
883
|
+
globalRegistry = new MetricsRegistry(serviceName, metricPrefix);
|
|
884
|
+
return globalRegistry;
|
|
885
|
+
}
|
|
886
|
+
__name(initializeMetricsRegistry, "initializeMetricsRegistry");
|
|
887
|
+
function getMetricsRegistry() {
|
|
888
|
+
if (!globalRegistry) {
|
|
889
|
+
globalRegistry = new MetricsRegistry("unknown-service");
|
|
890
|
+
}
|
|
891
|
+
return globalRegistry;
|
|
892
|
+
}
|
|
893
|
+
__name(getMetricsRegistry, "getMetricsRegistry");
|
|
894
|
+
function isMetricsRegistryInitialized() {
|
|
895
|
+
return globalRegistry !== null;
|
|
896
|
+
}
|
|
897
|
+
__name(isMetricsRegistryInitialized, "isMetricsRegistryInitialized");
|
|
898
|
+
function resetMetricsRegistry() {
|
|
899
|
+
if (globalRegistry) {
|
|
900
|
+
globalRegistry.clear();
|
|
901
|
+
}
|
|
902
|
+
globalRegistry = null;
|
|
903
|
+
}
|
|
904
|
+
__name(resetMetricsRegistry, "resetMetricsRegistry");
|
|
905
|
+
function createCounter(name, description) {
|
|
906
|
+
return getMetricsRegistry().createCounter(name, description);
|
|
907
|
+
}
|
|
908
|
+
__name(createCounter, "createCounter");
|
|
909
|
+
function createHistogram(name, description, boundaries) {
|
|
910
|
+
return getMetricsRegistry().createHistogram(name, description, boundaries);
|
|
911
|
+
}
|
|
912
|
+
__name(createHistogram, "createHistogram");
|
|
913
|
+
function createGauge(name, description) {
|
|
914
|
+
return getMetricsRegistry().createGauge(name, description);
|
|
915
|
+
}
|
|
916
|
+
__name(createGauge, "createGauge");
|
|
917
|
+
function createUpDownCounter(name, description) {
|
|
918
|
+
return getMetricsRegistry().createUpDownCounter(name, description);
|
|
919
|
+
}
|
|
920
|
+
__name(createUpDownCounter, "createUpDownCounter");
|
|
921
|
+
|
|
922
|
+
// src/instrumentation/tracer.ts
|
|
923
|
+
var SpanStatus = /* @__PURE__ */ (function(SpanStatus2) {
|
|
924
|
+
SpanStatus2[SpanStatus2["UNSET"] = 0] = "UNSET";
|
|
925
|
+
SpanStatus2[SpanStatus2["OK"] = 1] = "OK";
|
|
926
|
+
SpanStatus2[SpanStatus2["ERROR"] = 2] = "ERROR";
|
|
927
|
+
return SpanStatus2;
|
|
928
|
+
})({});
|
|
929
|
+
var SpanKind = /* @__PURE__ */ (function(SpanKind2) {
|
|
930
|
+
SpanKind2[SpanKind2["INTERNAL"] = 0] = "INTERNAL";
|
|
931
|
+
SpanKind2[SpanKind2["SERVER"] = 1] = "SERVER";
|
|
932
|
+
SpanKind2[SpanKind2["CLIENT"] = 2] = "CLIENT";
|
|
933
|
+
SpanKind2[SpanKind2["PRODUCER"] = 3] = "PRODUCER";
|
|
934
|
+
SpanKind2[SpanKind2["CONSUMER"] = 4] = "CONSUMER";
|
|
935
|
+
return SpanKind2;
|
|
936
|
+
})({});
|
|
937
|
+
function generateTraceId() {
|
|
938
|
+
const bytes = new Uint8Array(16);
|
|
939
|
+
crypto.getRandomValues(bytes);
|
|
940
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
941
|
+
}
|
|
942
|
+
__name(generateTraceId, "generateTraceId");
|
|
943
|
+
function generateSpanId() {
|
|
944
|
+
const bytes = new Uint8Array(8);
|
|
945
|
+
crypto.getRandomValues(bytes);
|
|
946
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
947
|
+
}
|
|
948
|
+
__name(generateSpanId, "generateSpanId");
|
|
949
|
+
var InMemorySpan = class InMemorySpan2 {
|
|
950
|
+
static {
|
|
951
|
+
__name(this, "InMemorySpan");
|
|
952
|
+
}
|
|
953
|
+
name;
|
|
954
|
+
traceId;
|
|
955
|
+
spanId;
|
|
956
|
+
parentSpanId;
|
|
957
|
+
kind;
|
|
958
|
+
startTime;
|
|
959
|
+
endTime;
|
|
960
|
+
status = 0;
|
|
961
|
+
attributes = {};
|
|
962
|
+
events = [];
|
|
963
|
+
isRecording = true;
|
|
964
|
+
onEnd;
|
|
965
|
+
constructor(name, kind = 0, parentContext, onEnd) {
|
|
966
|
+
this.name = name;
|
|
967
|
+
this.kind = kind;
|
|
968
|
+
this.startTime = Date.now();
|
|
969
|
+
this.spanId = generateSpanId();
|
|
970
|
+
this.onEnd = onEnd;
|
|
971
|
+
if (parentContext) {
|
|
972
|
+
this.traceId = parentContext.traceId;
|
|
973
|
+
this.parentSpanId = parentContext.spanId;
|
|
974
|
+
} else {
|
|
975
|
+
this.traceId = generateTraceId();
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
setAttribute(key, value) {
|
|
979
|
+
if (this.isRecording) {
|
|
980
|
+
this.attributes[key] = value;
|
|
981
|
+
}
|
|
982
|
+
return this;
|
|
983
|
+
}
|
|
984
|
+
setAttributes(attributes) {
|
|
985
|
+
if (this.isRecording) {
|
|
986
|
+
Object.assign(this.attributes, attributes);
|
|
987
|
+
}
|
|
988
|
+
return this;
|
|
989
|
+
}
|
|
990
|
+
setStatus(status, message) {
|
|
991
|
+
this.status = status;
|
|
992
|
+
if (message) {
|
|
993
|
+
this.attributes["status.message"] = message;
|
|
994
|
+
}
|
|
995
|
+
return this;
|
|
996
|
+
}
|
|
997
|
+
recordException(error) {
|
|
998
|
+
this.status = 2;
|
|
999
|
+
this.attributes["error"] = true;
|
|
1000
|
+
this.attributes["error.type"] = error.name;
|
|
1001
|
+
this.attributes["error.message"] = error.message;
|
|
1002
|
+
if (error.stack) {
|
|
1003
|
+
this.attributes["error.stack"] = error.stack;
|
|
1004
|
+
}
|
|
1005
|
+
this.addEvent("exception", {
|
|
1006
|
+
"exception.type": error.name,
|
|
1007
|
+
"exception.message": error.message
|
|
1008
|
+
});
|
|
1009
|
+
return this;
|
|
1010
|
+
}
|
|
1011
|
+
addEvent(name, attributes) {
|
|
1012
|
+
if (this.isRecording) {
|
|
1013
|
+
this.events.push({
|
|
1014
|
+
name,
|
|
1015
|
+
timestamp: Date.now(),
|
|
1016
|
+
attributes
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
return this;
|
|
1020
|
+
}
|
|
1021
|
+
end() {
|
|
1022
|
+
if (!this.isRecording) return;
|
|
1023
|
+
this.endTime = Date.now();
|
|
1024
|
+
this.isRecording = false;
|
|
1025
|
+
if (this.onEnd) {
|
|
1026
|
+
this.onEnd(this);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
getSpanContext() {
|
|
1030
|
+
return {
|
|
1031
|
+
traceId: this.traceId,
|
|
1032
|
+
spanId: this.spanId,
|
|
1033
|
+
traceFlags: this.status === 2 ? 1 : 0
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
var NoOpSpan = class NoOpSpan2 {
|
|
1038
|
+
static {
|
|
1039
|
+
__name(this, "NoOpSpan");
|
|
1040
|
+
}
|
|
1041
|
+
name = "";
|
|
1042
|
+
traceId = "";
|
|
1043
|
+
spanId = "";
|
|
1044
|
+
kind = 0;
|
|
1045
|
+
startTime = 0;
|
|
1046
|
+
status = 0;
|
|
1047
|
+
attributes = {};
|
|
1048
|
+
events = [];
|
|
1049
|
+
isRecording = false;
|
|
1050
|
+
setAttribute() {
|
|
1051
|
+
return this;
|
|
1052
|
+
}
|
|
1053
|
+
setAttributes() {
|
|
1054
|
+
return this;
|
|
1055
|
+
}
|
|
1056
|
+
setStatus() {
|
|
1057
|
+
return this;
|
|
1058
|
+
}
|
|
1059
|
+
recordException() {
|
|
1060
|
+
return this;
|
|
1061
|
+
}
|
|
1062
|
+
addEvent() {
|
|
1063
|
+
return this;
|
|
1064
|
+
}
|
|
1065
|
+
end() {
|
|
1066
|
+
}
|
|
1067
|
+
getSpanContext() {
|
|
1068
|
+
return {
|
|
1069
|
+
traceId: "",
|
|
1070
|
+
spanId: "",
|
|
1071
|
+
traceFlags: 0
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
var Tracer = class {
|
|
1076
|
+
static {
|
|
1077
|
+
__name(this, "Tracer");
|
|
1078
|
+
}
|
|
1079
|
+
serviceName;
|
|
1080
|
+
activeSpans = /* @__PURE__ */ new Map();
|
|
1081
|
+
currentSpan = null;
|
|
1082
|
+
spanListeners = [];
|
|
1083
|
+
constructor(serviceName) {
|
|
1084
|
+
this.serviceName = serviceName;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Check if tracing is enabled
|
|
1088
|
+
*/
|
|
1089
|
+
isEnabled() {
|
|
1090
|
+
return isInstrumentationConfigInitialized() && isFeatureEnabled("tracing");
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Start a new span
|
|
1094
|
+
*/
|
|
1095
|
+
startSpan(name, kind = 0, parentContext) {
|
|
1096
|
+
if (!this.isEnabled()) {
|
|
1097
|
+
return new NoOpSpan();
|
|
1098
|
+
}
|
|
1099
|
+
const config = getInstrumentationConfig();
|
|
1100
|
+
if (config.tracing.ignoredOperations?.includes(name)) {
|
|
1101
|
+
return new NoOpSpan();
|
|
1102
|
+
}
|
|
1103
|
+
const parent = parentContext || this.currentSpan?.getSpanContext();
|
|
1104
|
+
const span = new InMemorySpan(name, kind, parent, (completedSpan) => {
|
|
1105
|
+
this.onSpanEnd(completedSpan);
|
|
1106
|
+
});
|
|
1107
|
+
span.setAttributes({
|
|
1108
|
+
"service.name": this.serviceName,
|
|
1109
|
+
"service.version": config.tracing.serviceVersion || "1.0.0",
|
|
1110
|
+
"deployment.environment": config.tracing.environment || "development"
|
|
1111
|
+
});
|
|
1112
|
+
if (config.tracing.resourceAttributes) {
|
|
1113
|
+
span.setAttributes(config.tracing.resourceAttributes);
|
|
1114
|
+
}
|
|
1115
|
+
this.activeSpans.set(span.spanId, span);
|
|
1116
|
+
this.currentSpan = span;
|
|
1117
|
+
return span;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Start a span from operation context
|
|
1121
|
+
*/
|
|
1122
|
+
startSpanFromContext(context, kind = 0) {
|
|
1123
|
+
const span = this.startSpan(context.operationName, kind);
|
|
1124
|
+
if (span.isRecording) {
|
|
1125
|
+
span.setAttributes({
|
|
1126
|
+
"operation.type": context.operationType,
|
|
1127
|
+
...context.actorId && {
|
|
1128
|
+
"actor.id": context.actorId
|
|
1129
|
+
},
|
|
1130
|
+
...context.tenantId && {
|
|
1131
|
+
"tenant.id": context.tenantId
|
|
1132
|
+
},
|
|
1133
|
+
...context.workspaceId && {
|
|
1134
|
+
"workspace.id": context.workspaceId
|
|
1135
|
+
},
|
|
1136
|
+
...context.requestId && {
|
|
1137
|
+
"request.id": context.requestId
|
|
1138
|
+
},
|
|
1139
|
+
...context.attributes
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
return span;
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Get current active span
|
|
1146
|
+
*/
|
|
1147
|
+
getCurrentSpan() {
|
|
1148
|
+
return this.currentSpan;
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Get current trace context for logging
|
|
1152
|
+
*/
|
|
1153
|
+
getTraceContext() {
|
|
1154
|
+
if (!this.currentSpan || !this.isEnabled()) {
|
|
1155
|
+
return {};
|
|
1156
|
+
}
|
|
1157
|
+
const spanContext = this.currentSpan.getSpanContext();
|
|
1158
|
+
return {
|
|
1159
|
+
traceId: spanContext.traceId,
|
|
1160
|
+
spanId: spanContext.spanId,
|
|
1161
|
+
traceFlags: spanContext.traceFlags,
|
|
1162
|
+
parentSpanId: this.currentSpan.parentSpanId
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Set current span (for context propagation)
|
|
1167
|
+
*/
|
|
1168
|
+
setCurrentSpan(span) {
|
|
1169
|
+
this.currentSpan = span;
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Run a function within a span
|
|
1173
|
+
*/
|
|
1174
|
+
async withSpan(name, fn, kind = 0, parentContext) {
|
|
1175
|
+
const span = this.startSpan(name, kind, parentContext);
|
|
1176
|
+
try {
|
|
1177
|
+
const result = await fn(span);
|
|
1178
|
+
span.setStatus(1);
|
|
1179
|
+
return result;
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
if (error instanceof Error) {
|
|
1182
|
+
span.recordException(error);
|
|
1183
|
+
}
|
|
1184
|
+
throw error;
|
|
1185
|
+
} finally {
|
|
1186
|
+
span.end();
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Run a synchronous function within a span
|
|
1191
|
+
*/
|
|
1192
|
+
withSpanSync(name, fn, kind = 0, parentContext) {
|
|
1193
|
+
const span = this.startSpan(name, kind, parentContext);
|
|
1194
|
+
try {
|
|
1195
|
+
const result = fn(span);
|
|
1196
|
+
span.setStatus(1);
|
|
1197
|
+
return result;
|
|
1198
|
+
} catch (error) {
|
|
1199
|
+
if (error instanceof Error) {
|
|
1200
|
+
span.recordException(error);
|
|
1201
|
+
}
|
|
1202
|
+
throw error;
|
|
1203
|
+
} finally {
|
|
1204
|
+
span.end();
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Add a listener for completed spans
|
|
1209
|
+
*/
|
|
1210
|
+
addSpanListener(listener) {
|
|
1211
|
+
this.spanListeners.push(listener);
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Remove a span listener
|
|
1215
|
+
*/
|
|
1216
|
+
removeSpanListener(listener) {
|
|
1217
|
+
const index = this.spanListeners.indexOf(listener);
|
|
1218
|
+
if (index !== -1) {
|
|
1219
|
+
this.spanListeners.splice(index, 1);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Handle span completion
|
|
1224
|
+
*/
|
|
1225
|
+
onSpanEnd(span) {
|
|
1226
|
+
this.activeSpans.delete(span.spanId);
|
|
1227
|
+
if (this.currentSpan?.spanId === span.spanId) {
|
|
1228
|
+
if (span.parentSpanId) {
|
|
1229
|
+
this.currentSpan = this.activeSpans.get(span.parentSpanId) || null;
|
|
1230
|
+
} else {
|
|
1231
|
+
this.currentSpan = null;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
const config = getInstrumentationConfig();
|
|
1235
|
+
if (config.tracing.exporterType === "console") {
|
|
1236
|
+
this.logSpan(span);
|
|
1237
|
+
}
|
|
1238
|
+
for (const listener of this.spanListeners) {
|
|
1239
|
+
try {
|
|
1240
|
+
listener(span);
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
logger.error("[Tracer] Error in span listener:", error);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Log span to console (for debugging)
|
|
1248
|
+
*/
|
|
1249
|
+
logSpan(span) {
|
|
1250
|
+
const duration = span.endTime ? span.endTime - span.startTime : 0;
|
|
1251
|
+
logger.debug("[Tracer] Span completed", {
|
|
1252
|
+
name: span.name,
|
|
1253
|
+
traceId: span.traceId,
|
|
1254
|
+
spanId: span.spanId,
|
|
1255
|
+
parentSpanId: span.parentSpanId,
|
|
1256
|
+
kind: SpanKind[span.kind],
|
|
1257
|
+
status: SpanStatus[span.status],
|
|
1258
|
+
duration: `${duration}ms`,
|
|
1259
|
+
attributes: span.attributes,
|
|
1260
|
+
eventCount: span.events.length
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Get active span count
|
|
1265
|
+
*/
|
|
1266
|
+
getActiveSpanCount() {
|
|
1267
|
+
return this.activeSpans.size;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Clear all active spans (for testing)
|
|
1271
|
+
*/
|
|
1272
|
+
clearActiveSpans() {
|
|
1273
|
+
this.activeSpans.clear();
|
|
1274
|
+
this.currentSpan = null;
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
var globalTracer = null;
|
|
1278
|
+
function initializeTracer(serviceName) {
|
|
1279
|
+
globalTracer = new Tracer(serviceName);
|
|
1280
|
+
return globalTracer;
|
|
1281
|
+
}
|
|
1282
|
+
__name(initializeTracer, "initializeTracer");
|
|
1283
|
+
function getTracer() {
|
|
1284
|
+
if (!globalTracer) {
|
|
1285
|
+
globalTracer = new Tracer("unknown-service");
|
|
1286
|
+
}
|
|
1287
|
+
return globalTracer;
|
|
1288
|
+
}
|
|
1289
|
+
__name(getTracer, "getTracer");
|
|
1290
|
+
function isTracerInitialized() {
|
|
1291
|
+
return globalTracer !== null;
|
|
1292
|
+
}
|
|
1293
|
+
__name(isTracerInitialized, "isTracerInitialized");
|
|
1294
|
+
function startSpan(name, kind = 0, parentContext) {
|
|
1295
|
+
return getTracer().startSpan(name, kind, parentContext);
|
|
1296
|
+
}
|
|
1297
|
+
__name(startSpan, "startSpan");
|
|
1298
|
+
async function withSpan(name, fn, kind = 0) {
|
|
1299
|
+
return getTracer().withSpan(name, fn, kind);
|
|
1300
|
+
}
|
|
1301
|
+
__name(withSpan, "withSpan");
|
|
1302
|
+
function getTraceContext() {
|
|
1303
|
+
return getTracer().getTraceContext();
|
|
1304
|
+
}
|
|
1305
|
+
__name(getTraceContext, "getTraceContext");
|
|
1306
|
+
function extractTraceContext(headers) {
|
|
1307
|
+
const traceparent = headers["traceparent"];
|
|
1308
|
+
if (!traceparent) return void 0;
|
|
1309
|
+
const value = Array.isArray(traceparent) ? traceparent[0] : traceparent;
|
|
1310
|
+
if (!value) return void 0;
|
|
1311
|
+
const parts = value.split("-");
|
|
1312
|
+
if (parts.length !== 4) return void 0;
|
|
1313
|
+
const [, traceId, spanId, traceFlags] = parts;
|
|
1314
|
+
if (!traceId || !spanId || traceId.length !== 32 || spanId.length !== 16) {
|
|
1315
|
+
return void 0;
|
|
1316
|
+
}
|
|
1317
|
+
return {
|
|
1318
|
+
traceId,
|
|
1319
|
+
spanId,
|
|
1320
|
+
traceFlags: parseInt(traceFlags || "0", 16),
|
|
1321
|
+
isRemote: true
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
__name(extractTraceContext, "extractTraceContext");
|
|
1325
|
+
function injectTraceContext(headers, spanContext) {
|
|
1326
|
+
const context = spanContext || getTracer().getCurrentSpan()?.getSpanContext();
|
|
1327
|
+
if (!context || !context.traceId || !context.spanId) return;
|
|
1328
|
+
headers["traceparent"] = `00-${context.traceId}-${context.spanId}-${context.traceFlags.toString(16).padStart(2, "0")}`;
|
|
1329
|
+
}
|
|
1330
|
+
__name(injectTraceContext, "injectTraceContext");
|
|
1331
|
+
|
|
1332
|
+
// src/telemetry/logger-state.ts
|
|
1333
|
+
var activeTelemetryLogger;
|
|
1334
|
+
function setActiveTelemetryLogger(logger2) {
|
|
1335
|
+
activeTelemetryLogger = logger2;
|
|
1336
|
+
}
|
|
1337
|
+
__name(setActiveTelemetryLogger, "setActiveTelemetryLogger");
|
|
1338
|
+
function getActiveTelemetryLogger() {
|
|
1339
|
+
return activeTelemetryLogger;
|
|
1340
|
+
}
|
|
1341
|
+
__name(getActiveTelemetryLogger, "getActiveTelemetryLogger");
|
|
1342
|
+
|
|
1343
|
+
// src/instrumentation/types.ts
|
|
1344
|
+
var STANDARD_METRICS = {
|
|
1345
|
+
// HTTP metrics
|
|
1346
|
+
HTTP_REQUEST_DURATION: {
|
|
1347
|
+
name: "http_request_duration_ms",
|
|
1348
|
+
description: "HTTP request duration in milliseconds",
|
|
1349
|
+
type: "histogram",
|
|
1350
|
+
unit: "ms",
|
|
1351
|
+
labelKeys: [
|
|
1352
|
+
"method",
|
|
1353
|
+
"route",
|
|
1354
|
+
"status_code"
|
|
1355
|
+
],
|
|
1356
|
+
boundaries: [
|
|
1357
|
+
5,
|
|
1358
|
+
10,
|
|
1359
|
+
25,
|
|
1360
|
+
50,
|
|
1361
|
+
100,
|
|
1362
|
+
250,
|
|
1363
|
+
500,
|
|
1364
|
+
1e3,
|
|
1365
|
+
2500,
|
|
1366
|
+
5e3,
|
|
1367
|
+
1e4
|
|
1368
|
+
]
|
|
1369
|
+
},
|
|
1370
|
+
HTTP_REQUEST_TOTAL: {
|
|
1371
|
+
name: "http_requests_total",
|
|
1372
|
+
description: "Total number of HTTP requests",
|
|
1373
|
+
type: "counter",
|
|
1374
|
+
labelKeys: [
|
|
1375
|
+
"method",
|
|
1376
|
+
"route",
|
|
1377
|
+
"status_code"
|
|
1378
|
+
]
|
|
1379
|
+
},
|
|
1380
|
+
HTTP_REQUEST_SIZE: {
|
|
1381
|
+
name: "http_request_size_bytes",
|
|
1382
|
+
description: "HTTP request size in bytes",
|
|
1383
|
+
type: "histogram",
|
|
1384
|
+
unit: "bytes",
|
|
1385
|
+
labelKeys: [
|
|
1386
|
+
"method",
|
|
1387
|
+
"route"
|
|
1388
|
+
],
|
|
1389
|
+
boundaries: [
|
|
1390
|
+
100,
|
|
1391
|
+
1e3,
|
|
1392
|
+
1e4,
|
|
1393
|
+
1e5,
|
|
1394
|
+
1e6
|
|
1395
|
+
]
|
|
1396
|
+
},
|
|
1397
|
+
HTTP_RESPONSE_SIZE: {
|
|
1398
|
+
name: "http_response_size_bytes",
|
|
1399
|
+
description: "HTTP response size in bytes",
|
|
1400
|
+
type: "histogram",
|
|
1401
|
+
unit: "bytes",
|
|
1402
|
+
labelKeys: [
|
|
1403
|
+
"method",
|
|
1404
|
+
"route"
|
|
1405
|
+
],
|
|
1406
|
+
boundaries: [
|
|
1407
|
+
100,
|
|
1408
|
+
1e3,
|
|
1409
|
+
1e4,
|
|
1410
|
+
1e5,
|
|
1411
|
+
1e6
|
|
1412
|
+
]
|
|
1413
|
+
},
|
|
1414
|
+
// GraphQL metrics
|
|
1415
|
+
GRAPHQL_OPERATION_DURATION: {
|
|
1416
|
+
name: "graphql_operation_duration_ms",
|
|
1417
|
+
description: "GraphQL operation duration in milliseconds",
|
|
1418
|
+
type: "histogram",
|
|
1419
|
+
unit: "ms",
|
|
1420
|
+
labelKeys: [
|
|
1421
|
+
"operation_type",
|
|
1422
|
+
"operation_name"
|
|
1423
|
+
],
|
|
1424
|
+
boundaries: [
|
|
1425
|
+
5,
|
|
1426
|
+
10,
|
|
1427
|
+
25,
|
|
1428
|
+
50,
|
|
1429
|
+
100,
|
|
1430
|
+
250,
|
|
1431
|
+
500,
|
|
1432
|
+
1e3,
|
|
1433
|
+
2500,
|
|
1434
|
+
5e3
|
|
1435
|
+
]
|
|
1436
|
+
},
|
|
1437
|
+
GRAPHQL_OPERATION_TOTAL: {
|
|
1438
|
+
name: "graphql_operations_total",
|
|
1439
|
+
description: "Total number of GraphQL operations",
|
|
1440
|
+
type: "counter",
|
|
1441
|
+
labelKeys: [
|
|
1442
|
+
"operation_type",
|
|
1443
|
+
"operation_name",
|
|
1444
|
+
"status"
|
|
1445
|
+
]
|
|
1446
|
+
},
|
|
1447
|
+
GRAPHQL_RESOLVER_DURATION: {
|
|
1448
|
+
name: "graphql_resolver_duration_ms",
|
|
1449
|
+
description: "GraphQL resolver duration in milliseconds",
|
|
1450
|
+
type: "histogram",
|
|
1451
|
+
unit: "ms",
|
|
1452
|
+
labelKeys: [
|
|
1453
|
+
"type_name",
|
|
1454
|
+
"field_name"
|
|
1455
|
+
],
|
|
1456
|
+
boundaries: [
|
|
1457
|
+
1,
|
|
1458
|
+
5,
|
|
1459
|
+
10,
|
|
1460
|
+
25,
|
|
1461
|
+
50,
|
|
1462
|
+
100,
|
|
1463
|
+
250,
|
|
1464
|
+
500
|
|
1465
|
+
]
|
|
1466
|
+
},
|
|
1467
|
+
// Database metrics
|
|
1468
|
+
DB_QUERY_DURATION: {
|
|
1469
|
+
name: "db_query_duration_ms",
|
|
1470
|
+
description: "Database query duration in milliseconds",
|
|
1471
|
+
type: "histogram",
|
|
1472
|
+
unit: "ms",
|
|
1473
|
+
labelKeys: [
|
|
1474
|
+
"operation",
|
|
1475
|
+
"model"
|
|
1476
|
+
],
|
|
1477
|
+
boundaries: [
|
|
1478
|
+
1,
|
|
1479
|
+
5,
|
|
1480
|
+
10,
|
|
1481
|
+
25,
|
|
1482
|
+
50,
|
|
1483
|
+
100,
|
|
1484
|
+
250,
|
|
1485
|
+
500,
|
|
1486
|
+
1e3
|
|
1487
|
+
]
|
|
1488
|
+
},
|
|
1489
|
+
DB_QUERY_TOTAL: {
|
|
1490
|
+
name: "db_queries_total",
|
|
1491
|
+
description: "Total number of database queries",
|
|
1492
|
+
type: "counter",
|
|
1493
|
+
labelKeys: [
|
|
1494
|
+
"operation",
|
|
1495
|
+
"model",
|
|
1496
|
+
"status"
|
|
1497
|
+
]
|
|
1498
|
+
},
|
|
1499
|
+
DB_CONNECTION_POOL_SIZE: {
|
|
1500
|
+
name: "db_connection_pool_size",
|
|
1501
|
+
description: "Database connection pool size",
|
|
1502
|
+
type: "gauge",
|
|
1503
|
+
labelKeys: [
|
|
1504
|
+
"state"
|
|
1505
|
+
]
|
|
1506
|
+
},
|
|
1507
|
+
// Cache metrics
|
|
1508
|
+
CACHE_OPERATION_DURATION: {
|
|
1509
|
+
name: "cache_operation_duration_ms",
|
|
1510
|
+
description: "Cache operation duration in milliseconds",
|
|
1511
|
+
type: "histogram",
|
|
1512
|
+
unit: "ms",
|
|
1513
|
+
labelKeys: [
|
|
1514
|
+
"operation"
|
|
1515
|
+
],
|
|
1516
|
+
boundaries: [
|
|
1517
|
+
0.1,
|
|
1518
|
+
0.5,
|
|
1519
|
+
1,
|
|
1520
|
+
2,
|
|
1521
|
+
5,
|
|
1522
|
+
10,
|
|
1523
|
+
25,
|
|
1524
|
+
50
|
|
1525
|
+
]
|
|
1526
|
+
},
|
|
1527
|
+
CACHE_HIT_TOTAL: {
|
|
1528
|
+
name: "cache_hits_total",
|
|
1529
|
+
description: "Total number of cache hits",
|
|
1530
|
+
type: "counter",
|
|
1531
|
+
labelKeys: [
|
|
1532
|
+
"cache_type"
|
|
1533
|
+
]
|
|
1534
|
+
},
|
|
1535
|
+
CACHE_MISS_TOTAL: {
|
|
1536
|
+
name: "cache_misses_total",
|
|
1537
|
+
description: "Total number of cache misses",
|
|
1538
|
+
type: "counter",
|
|
1539
|
+
labelKeys: [
|
|
1540
|
+
"cache_type"
|
|
1541
|
+
]
|
|
1542
|
+
},
|
|
1543
|
+
// Business metrics
|
|
1544
|
+
OPERATION_DURATION: {
|
|
1545
|
+
name: "operation_duration_ms",
|
|
1546
|
+
description: "Business operation duration in milliseconds",
|
|
1547
|
+
type: "histogram",
|
|
1548
|
+
unit: "ms",
|
|
1549
|
+
labelKeys: [
|
|
1550
|
+
"operation",
|
|
1551
|
+
"status"
|
|
1552
|
+
],
|
|
1553
|
+
boundaries: [
|
|
1554
|
+
10,
|
|
1555
|
+
50,
|
|
1556
|
+
100,
|
|
1557
|
+
250,
|
|
1558
|
+
500,
|
|
1559
|
+
1e3,
|
|
1560
|
+
2500,
|
|
1561
|
+
5e3,
|
|
1562
|
+
1e4
|
|
1563
|
+
]
|
|
1564
|
+
},
|
|
1565
|
+
OPERATION_TOTAL: {
|
|
1566
|
+
name: "operations_total",
|
|
1567
|
+
description: "Total number of business operations",
|
|
1568
|
+
type: "counter",
|
|
1569
|
+
labelKeys: [
|
|
1570
|
+
"operation",
|
|
1571
|
+
"status"
|
|
1572
|
+
]
|
|
1573
|
+
},
|
|
1574
|
+
ACTIVE_OPERATIONS: {
|
|
1575
|
+
name: "active_operations",
|
|
1576
|
+
description: "Number of currently active operations",
|
|
1577
|
+
type: "upDownCounter",
|
|
1578
|
+
labelKeys: [
|
|
1579
|
+
"operation"
|
|
1580
|
+
]
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
// src/instrumentation/graphql-plugin.ts
|
|
1585
|
+
var require2 = createRequire(import.meta.url);
|
|
1586
|
+
var prometheusPluginFactory = void 0;
|
|
1587
|
+
var prometheusLoadAttempted = false;
|
|
1588
|
+
function loadPrometheusPlugin() {
|
|
1589
|
+
if (prometheusLoadAttempted) {
|
|
1590
|
+
return prometheusPluginFactory ?? null;
|
|
1591
|
+
}
|
|
1592
|
+
prometheusLoadAttempted = true;
|
|
1593
|
+
try {
|
|
1594
|
+
const module = require2("@graphql-yoga/plugin-prometheus");
|
|
1595
|
+
prometheusPluginFactory = module.usePrometheus;
|
|
1596
|
+
if (prometheusPluginFactory) {
|
|
1597
|
+
logger.info("[Instrumentation] Successfully loaded @graphql-yoga/plugin-prometheus");
|
|
1598
|
+
} else {
|
|
1599
|
+
logger.warn("[Instrumentation] @graphql-yoga/plugin-prometheus loaded but usePrometheus not found");
|
|
1600
|
+
}
|
|
1601
|
+
return prometheusPluginFactory ?? null;
|
|
1602
|
+
} catch (error) {
|
|
1603
|
+
logger.warn("[Instrumentation] Failed to load @graphql-yoga/plugin-prometheus:", error);
|
|
1604
|
+
prometheusPluginFactory = null;
|
|
1605
|
+
return null;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
__name(loadPrometheusPlugin, "loadPrometheusPlugin");
|
|
1609
|
+
function createPrometheusPlugin(options) {
|
|
1610
|
+
if (isInstrumentationConfigInitialized() && !isFeatureEnabled("metrics")) {
|
|
1611
|
+
logger.debug("[Instrumentation] Metrics disabled, skipping Prometheus plugin");
|
|
1612
|
+
return null;
|
|
1613
|
+
}
|
|
1614
|
+
const pluginFactory = loadPrometheusPlugin();
|
|
1615
|
+
if (!pluginFactory) {
|
|
1616
|
+
logger.debug("[Instrumentation] @graphql-yoga/plugin-prometheus not installed, metrics not available");
|
|
1617
|
+
return null;
|
|
1618
|
+
}
|
|
1619
|
+
const config = {
|
|
1620
|
+
// Expose metrics endpoint (set to false to disable, e.g., for push mode)
|
|
1621
|
+
endpoint: options?.endpoint ?? "/metrics",
|
|
1622
|
+
// Skip introspection queries from metrics
|
|
1623
|
+
skipIntrospection: options?.skipIntrospection ?? true,
|
|
1624
|
+
// Metrics configuration
|
|
1625
|
+
metrics: {
|
|
1626
|
+
// HTTP-level metrics
|
|
1627
|
+
graphql_yoga_http_duration: options?.httpDuration ?? true,
|
|
1628
|
+
// Operation-level metrics
|
|
1629
|
+
graphql_envelop_request_duration: options?.requestDuration ?? true,
|
|
1630
|
+
graphql_envelop_request_time_summary: options?.requestDuration ?? true,
|
|
1631
|
+
graphql_envelop_request: options?.requestCount ?? true,
|
|
1632
|
+
graphql_envelop_error_result: options?.errorCount ?? true,
|
|
1633
|
+
graphql_envelop_deprecated_field: options?.deprecatedFields ?? true,
|
|
1634
|
+
// Execution phase metrics
|
|
1635
|
+
graphql_envelop_phase_parse: options?.parsePhase ?? true,
|
|
1636
|
+
graphql_envelop_phase_validate: options?.validatePhase ?? true,
|
|
1637
|
+
graphql_envelop_phase_context: options?.contextPhase ?? true,
|
|
1638
|
+
graphql_envelop_phase_execute: options?.executePhase ?? true,
|
|
1639
|
+
graphql_envelop_phase_subscribe: true,
|
|
1640
|
+
// Schema change tracking
|
|
1641
|
+
graphql_envelop_schema_change: true,
|
|
1642
|
+
// Resolver-level metrics (disabled by default due to performance overhead)
|
|
1643
|
+
graphql_envelop_execute_resolver: options?.resolverMetrics ?? false
|
|
1644
|
+
},
|
|
1645
|
+
// If resolver metrics enabled, optionally filter which resolvers to instrument
|
|
1646
|
+
...options?.instrumentResolvers && {
|
|
1647
|
+
instrumentResolvers: options.instrumentResolvers
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
logger.debug("[Instrumentation] Using Prometheus metrics plugin", {
|
|
1651
|
+
endpoint: config.endpoint,
|
|
1652
|
+
resolverMetrics: options?.resolverMetrics ?? false
|
|
1653
|
+
});
|
|
1654
|
+
return pluginFactory(config);
|
|
1655
|
+
}
|
|
1656
|
+
__name(createPrometheusPlugin, "createPrometheusPlugin");
|
|
1657
|
+
function isPrometheusAvailable() {
|
|
1658
|
+
return loadPrometheusPlugin() !== null;
|
|
1659
|
+
}
|
|
1660
|
+
__name(isPrometheusAvailable, "isPrometheusAvailable");
|
|
1661
|
+
var apolloInlineTracePluginFactory = void 0;
|
|
1662
|
+
var apolloInlineTraceLoadAttempted = false;
|
|
1663
|
+
function loadApolloInlineTracePlugin() {
|
|
1664
|
+
if (apolloInlineTraceLoadAttempted) {
|
|
1665
|
+
return apolloInlineTracePluginFactory ?? null;
|
|
1666
|
+
}
|
|
1667
|
+
apolloInlineTraceLoadAttempted = true;
|
|
1668
|
+
try {
|
|
1669
|
+
const module = require2("@graphql-yoga/plugin-apollo-inline-trace");
|
|
1670
|
+
apolloInlineTracePluginFactory = module.useApolloInlineTrace;
|
|
1671
|
+
return apolloInlineTracePluginFactory ?? null;
|
|
1672
|
+
} catch {
|
|
1673
|
+
apolloInlineTracePluginFactory = null;
|
|
1674
|
+
return null;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
__name(loadApolloInlineTracePlugin, "loadApolloInlineTracePlugin");
|
|
1678
|
+
function createApolloInlineTracePlugin(_options) {
|
|
1679
|
+
if (isInstrumentationConfigInitialized() && !isFeatureEnabled("tracing")) {
|
|
1680
|
+
logger.debug("[Instrumentation] Tracing disabled, skipping Apollo inline trace plugin");
|
|
1681
|
+
return null;
|
|
1682
|
+
}
|
|
1683
|
+
const pluginFactory = loadApolloInlineTracePlugin();
|
|
1684
|
+
if (!pluginFactory) {
|
|
1685
|
+
logger.debug("[Instrumentation] @graphql-yoga/plugin-apollo-inline-trace not installed, using fallback tracing");
|
|
1686
|
+
return null;
|
|
1687
|
+
}
|
|
1688
|
+
logger.debug("[Instrumentation] Using Apollo Federation inline trace plugin");
|
|
1689
|
+
return pluginFactory();
|
|
1690
|
+
}
|
|
1691
|
+
__name(createApolloInlineTracePlugin, "createApolloInlineTracePlugin");
|
|
1692
|
+
function isApolloInlineTraceAvailable() {
|
|
1693
|
+
return loadApolloInlineTracePlugin() !== null;
|
|
1694
|
+
}
|
|
1695
|
+
__name(isApolloInlineTraceAvailable, "isApolloInlineTraceAvailable");
|
|
1696
|
+
function createGraphQLMetrics() {
|
|
1697
|
+
const def = STANDARD_METRICS;
|
|
1698
|
+
return {
|
|
1699
|
+
operationDuration: createHistogram(def["GRAPHQL_OPERATION_DURATION"]?.name || "graphql_operation_duration_ms", def["GRAPHQL_OPERATION_DURATION"]?.description || "GraphQL operation duration", def["GRAPHQL_OPERATION_DURATION"]?.boundaries),
|
|
1700
|
+
operationTotal: createCounter(def["GRAPHQL_OPERATION_TOTAL"]?.name || "graphql_operations_total", def["GRAPHQL_OPERATION_TOTAL"]?.description || "Total GraphQL operations"),
|
|
1701
|
+
operationErrors: createCounter("graphql_operation_errors_total", "Total GraphQL operation errors"),
|
|
1702
|
+
resolverDuration: createHistogram(def["GRAPHQL_RESOLVER_DURATION"]?.name || "graphql_resolver_duration_ms", def["GRAPHQL_RESOLVER_DURATION"]?.description || "GraphQL resolver duration", def["GRAPHQL_RESOLVER_DURATION"]?.boundaries),
|
|
1703
|
+
resolverTotal: createCounter("graphql_resolvers_total", "Total GraphQL resolver calls")
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
__name(createGraphQLMetrics, "createGraphQLMetrics");
|
|
1707
|
+
var graphqlMetrics = null;
|
|
1708
|
+
function getGraphQLMetrics() {
|
|
1709
|
+
if (!graphqlMetrics) {
|
|
1710
|
+
graphqlMetrics = createGraphQLMetrics();
|
|
1711
|
+
}
|
|
1712
|
+
return graphqlMetrics;
|
|
1713
|
+
}
|
|
1714
|
+
__name(getGraphQLMetrics, "getGraphQLMetrics");
|
|
1715
|
+
function extractOperationInfo(args) {
|
|
1716
|
+
let operationType = "query";
|
|
1717
|
+
let operationName = args.operationName || null;
|
|
1718
|
+
const definitions = args.document?.definitions;
|
|
1719
|
+
if (definitions && definitions.length > 0) {
|
|
1720
|
+
for (const def of definitions) {
|
|
1721
|
+
if (def.kind === "OperationDefinition") {
|
|
1722
|
+
operationType = def.operation || "query";
|
|
1723
|
+
if (!operationName && def.name?.value) {
|
|
1724
|
+
operationName = def.name.value;
|
|
1725
|
+
}
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
return {
|
|
1731
|
+
operationType,
|
|
1732
|
+
operationName,
|
|
1733
|
+
document: args.document?.loc?.source?.body,
|
|
1734
|
+
variables: args.variableValues
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
__name(extractOperationInfo, "extractOperationInfo");
|
|
1738
|
+
function shouldIgnoreOperation(operationName) {
|
|
1739
|
+
if (!isInstrumentationConfigInitialized()) return false;
|
|
1740
|
+
const config = getInstrumentationConfig();
|
|
1741
|
+
const ignoredOps = config.graphql.ignoredOperations || [];
|
|
1742
|
+
return operationName ? ignoredOps.includes(operationName) : false;
|
|
1743
|
+
}
|
|
1744
|
+
__name(shouldIgnoreOperation, "shouldIgnoreOperation");
|
|
1745
|
+
function createGraphQLInstrumentationPlugin() {
|
|
1746
|
+
return {
|
|
1747
|
+
onExecute({ args }) {
|
|
1748
|
+
if (!isFeatureEnabled("graphql")) {
|
|
1749
|
+
return void 0;
|
|
1750
|
+
}
|
|
1751
|
+
const operationInfo = extractOperationInfo(args);
|
|
1752
|
+
if (shouldIgnoreOperation(operationInfo.operationName)) {
|
|
1753
|
+
return void 0;
|
|
1754
|
+
}
|
|
1755
|
+
const startTime = Date.now();
|
|
1756
|
+
const config = getInstrumentationConfig();
|
|
1757
|
+
const metrics = getGraphQLMetrics();
|
|
1758
|
+
let span;
|
|
1759
|
+
if (isFeatureEnabled("tracing")) {
|
|
1760
|
+
const tracer = getTracer();
|
|
1761
|
+
const spanName = operationInfo.operationName ? `GraphQL ${operationInfo.operationType} ${operationInfo.operationName}` : `GraphQL ${operationInfo.operationType}`;
|
|
1762
|
+
span = tracer.startSpan(spanName, SpanKind.SERVER);
|
|
1763
|
+
span.setAttributes({
|
|
1764
|
+
"graphql.operation.type": operationInfo.operationType,
|
|
1765
|
+
"graphql.operation.name": operationInfo.operationName || "anonymous"
|
|
1766
|
+
});
|
|
1767
|
+
if (config.graphql.includeDocument && operationInfo.document) {
|
|
1768
|
+
span.setAttribute("graphql.document", operationInfo.document.substring(0, 2e3));
|
|
1769
|
+
}
|
|
1770
|
+
if (config.graphql.includeVariables && operationInfo.variables) {
|
|
1771
|
+
try {
|
|
1772
|
+
span.setAttribute("graphql.variables", JSON.stringify(operationInfo.variables).substring(0, 500));
|
|
1773
|
+
} catch {
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
if (isFeatureEnabled("logging")) {
|
|
1778
|
+
logger.debug("[GraphQL] Operation started", {
|
|
1779
|
+
type: operationInfo.operationType,
|
|
1780
|
+
name: operationInfo.operationName || "anonymous"
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
const context = args.contextValue;
|
|
1784
|
+
if (context) {
|
|
1785
|
+
context._instrumentation = {
|
|
1786
|
+
span,
|
|
1787
|
+
startTime,
|
|
1788
|
+
operationInfo
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
return {
|
|
1792
|
+
onExecuteDone({ result }) {
|
|
1793
|
+
const duration = Date.now() - startTime;
|
|
1794
|
+
const hasErrors = result && typeof result === "object" && "errors" in result && Array.isArray(result.errors) && result.errors.length > 0;
|
|
1795
|
+
if (isFeatureEnabled("metrics")) {
|
|
1796
|
+
const labels = {
|
|
1797
|
+
operation_type: operationInfo.operationType,
|
|
1798
|
+
operation_name: operationInfo.operationName || "anonymous"
|
|
1799
|
+
};
|
|
1800
|
+
metrics.operationDuration.record(duration, labels);
|
|
1801
|
+
metrics.operationTotal.inc({
|
|
1802
|
+
...labels,
|
|
1803
|
+
status: hasErrors ? "error" : "success"
|
|
1804
|
+
});
|
|
1805
|
+
if (hasErrors) {
|
|
1806
|
+
metrics.operationErrors.inc(labels);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
if (span) {
|
|
1810
|
+
span.setAttribute("graphql.duration_ms", duration);
|
|
1811
|
+
if (hasErrors) {
|
|
1812
|
+
span.setStatus(SpanStatus.ERROR, "GraphQL operation had errors");
|
|
1813
|
+
const errors = result.errors;
|
|
1814
|
+
if (errors && errors.length > 0) {
|
|
1815
|
+
span.setAttribute("graphql.error_count", errors.length);
|
|
1816
|
+
span.addEvent("graphql.errors", {
|
|
1817
|
+
errors: errors.map((e) => e.message || "Unknown error").join("; ")
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
} else {
|
|
1821
|
+
span.setStatus(SpanStatus.OK);
|
|
1822
|
+
}
|
|
1823
|
+
if (config.graphql.includeResult) {
|
|
1824
|
+
try {
|
|
1825
|
+
span.setAttribute("graphql.result", JSON.stringify(result).substring(0, 500));
|
|
1826
|
+
} catch {
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
span.end();
|
|
1830
|
+
}
|
|
1831
|
+
if (isFeatureEnabled("logging")) {
|
|
1832
|
+
if (hasErrors) {
|
|
1833
|
+
logger.warn("[GraphQL] Operation completed with errors", {
|
|
1834
|
+
type: operationInfo.operationType,
|
|
1835
|
+
name: operationInfo.operationName || "anonymous",
|
|
1836
|
+
duration: `${duration}ms`,
|
|
1837
|
+
errorCount: (result.errors || []).length
|
|
1838
|
+
});
|
|
1839
|
+
} else {
|
|
1840
|
+
logger.debug("[GraphQL] Operation completed", {
|
|
1841
|
+
type: operationInfo.operationType,
|
|
1842
|
+
name: operationInfo.operationName || "anonymous",
|
|
1843
|
+
duration: `${duration}ms`
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
__name(createGraphQLInstrumentationPlugin, "createGraphQLInstrumentationPlugin");
|
|
1853
|
+
function instrumentResolver(name, resolver, options) {
|
|
1854
|
+
const [typeName, fieldName] = name.includes(".") ? name.split(".", 2) : [
|
|
1855
|
+
"Unknown",
|
|
1856
|
+
name
|
|
1857
|
+
];
|
|
1858
|
+
return async (...args) => {
|
|
1859
|
+
if (!isFeatureEnabled("graphql")) {
|
|
1860
|
+
return resolver(...args);
|
|
1861
|
+
}
|
|
1862
|
+
const config = getInstrumentationConfig();
|
|
1863
|
+
const startTime = Date.now();
|
|
1864
|
+
const metrics = getGraphQLMetrics();
|
|
1865
|
+
let span;
|
|
1866
|
+
if (isFeatureEnabled("tracing") && config.graphql.includeResolvers) {
|
|
1867
|
+
const tracer = getTracer();
|
|
1868
|
+
span = tracer.startSpan(`Resolver: ${name}`, SpanKind.INTERNAL);
|
|
1869
|
+
span.setAttributes({
|
|
1870
|
+
"graphql.resolver.type": typeName || "Unknown",
|
|
1871
|
+
"graphql.resolver.field": fieldName || name,
|
|
1872
|
+
...options?.attributes
|
|
1873
|
+
});
|
|
1874
|
+
if (options?.includeArgs && args.length > 1) {
|
|
1875
|
+
try {
|
|
1876
|
+
span.setAttribute("graphql.resolver.args", JSON.stringify(args[1]).substring(0, 500));
|
|
1877
|
+
} catch {
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
try {
|
|
1882
|
+
const result = await resolver(...args);
|
|
1883
|
+
if (span) {
|
|
1884
|
+
span.setStatus(SpanStatus.OK);
|
|
1885
|
+
if (options?.includeResult) {
|
|
1886
|
+
try {
|
|
1887
|
+
span.setAttribute("graphql.resolver.result", JSON.stringify(result).substring(0, 500));
|
|
1888
|
+
} catch {
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
return result;
|
|
1893
|
+
} catch (error) {
|
|
1894
|
+
if (span && error instanceof Error) {
|
|
1895
|
+
span.recordException(error);
|
|
1896
|
+
}
|
|
1897
|
+
throw error;
|
|
1898
|
+
} finally {
|
|
1899
|
+
const duration = Date.now() - startTime;
|
|
1900
|
+
if (span) {
|
|
1901
|
+
span.end();
|
|
1902
|
+
}
|
|
1903
|
+
if (isFeatureEnabled("metrics")) {
|
|
1904
|
+
metrics.resolverDuration.record(duration, {
|
|
1905
|
+
type_name: typeName || "Unknown",
|
|
1906
|
+
field_name: fieldName || name
|
|
1907
|
+
});
|
|
1908
|
+
metrics.resolverTotal.inc({
|
|
1909
|
+
type_name: typeName || "Unknown",
|
|
1910
|
+
field_name: fieldName || name
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
}
|
|
1916
|
+
__name(instrumentResolver, "instrumentResolver");
|
|
1917
|
+
function instrumentResolverMap(resolverMap, options) {
|
|
1918
|
+
const result = {};
|
|
1919
|
+
for (const [typeName, fields] of Object.entries(resolverMap)) {
|
|
1920
|
+
if (options?.excludeTypes?.includes(typeName)) {
|
|
1921
|
+
result[typeName] = fields;
|
|
1922
|
+
continue;
|
|
1923
|
+
}
|
|
1924
|
+
if (options?.includeTypes && !options.includeTypes.includes(typeName)) {
|
|
1925
|
+
result[typeName] = fields;
|
|
1926
|
+
continue;
|
|
1927
|
+
}
|
|
1928
|
+
result[typeName] = {};
|
|
1929
|
+
for (const [fieldName, resolver] of Object.entries(fields)) {
|
|
1930
|
+
const fullName = `${typeName}.${fieldName}`;
|
|
1931
|
+
if (options?.excludeFields?.includes(fullName)) {
|
|
1932
|
+
result[typeName][fieldName] = resolver;
|
|
1933
|
+
continue;
|
|
1934
|
+
}
|
|
1935
|
+
result[typeName][fieldName] = instrumentResolver(fullName, resolver);
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
return result;
|
|
1939
|
+
}
|
|
1940
|
+
__name(instrumentResolverMap, "instrumentResolverMap");
|
|
1941
|
+
function getGraphQLOperationFromContext(context) {
|
|
1942
|
+
const instrumentedContext = context;
|
|
1943
|
+
return instrumentedContext?._instrumentation?.operationInfo;
|
|
1944
|
+
}
|
|
1945
|
+
__name(getGraphQLOperationFromContext, "getGraphQLOperationFromContext");
|
|
1946
|
+
function getGraphQLSpanFromContext(context) {
|
|
1947
|
+
const instrumentedContext = context;
|
|
1948
|
+
return instrumentedContext?._instrumentation?.span;
|
|
1949
|
+
}
|
|
1950
|
+
__name(getGraphQLSpanFromContext, "getGraphQLSpanFromContext");
|
|
1951
|
+
|
|
1952
|
+
// src/instrumentation/decorators.ts
|
|
1953
|
+
function Trace(options = {}) {
|
|
1954
|
+
return function(target, propertyKey, descriptor) {
|
|
1955
|
+
const originalMethod = descriptor.value;
|
|
1956
|
+
if (typeof originalMethod !== "function") {
|
|
1957
|
+
return descriptor;
|
|
1958
|
+
}
|
|
1959
|
+
const className = target.constructor.name;
|
|
1960
|
+
const methodName = String(propertyKey);
|
|
1961
|
+
const spanName = options.name || `${className}.${methodName}`;
|
|
1962
|
+
descriptor.value = async function(...args) {
|
|
1963
|
+
if (!isFeatureEnabled("tracing")) {
|
|
1964
|
+
return originalMethod.apply(this, args);
|
|
1965
|
+
}
|
|
1966
|
+
if (options.skip) {
|
|
1967
|
+
const shouldSkip = typeof options.skip === "function" ? options.skip(args) : options.skip;
|
|
1968
|
+
if (shouldSkip) {
|
|
1969
|
+
return originalMethod.apply(this, args);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
const tracer = getTracer();
|
|
1973
|
+
const span = tracer.startSpan(spanName, options.kind || SpanKind.INTERNAL);
|
|
1974
|
+
span.setAttributes({
|
|
1975
|
+
"code.function": methodName,
|
|
1976
|
+
"code.namespace": className,
|
|
1977
|
+
...options.attributes
|
|
1978
|
+
});
|
|
1979
|
+
if (options.extractAttributes) {
|
|
1980
|
+
try {
|
|
1981
|
+
const extractedAttrs = options.extractAttributes(args);
|
|
1982
|
+
span.setAttributes(extractedAttrs);
|
|
1983
|
+
} catch {
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
if (options.includeArgs) {
|
|
1987
|
+
try {
|
|
1988
|
+
span.setAttribute("method.args", JSON.stringify(args).substring(0, 1e3));
|
|
1989
|
+
} catch {
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
try {
|
|
1993
|
+
const result = await originalMethod.apply(this, args);
|
|
1994
|
+
if (options.includeResult) {
|
|
1995
|
+
try {
|
|
1996
|
+
span.setAttribute("method.result", JSON.stringify(result).substring(0, 1e3));
|
|
1997
|
+
} catch {
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
span.setStatus(SpanStatus.OK);
|
|
2001
|
+
return result;
|
|
2002
|
+
} catch (error) {
|
|
2003
|
+
if (error instanceof Error) {
|
|
2004
|
+
span.recordException(error);
|
|
2005
|
+
}
|
|
2006
|
+
throw error;
|
|
2007
|
+
} finally {
|
|
2008
|
+
span.end();
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
return descriptor;
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
__name(Trace, "Trace");
|
|
2015
|
+
function Metric(options = {}) {
|
|
2016
|
+
return function(target, propertyKey, descriptor) {
|
|
2017
|
+
const originalMethod = descriptor.value;
|
|
2018
|
+
if (typeof originalMethod !== "function") {
|
|
2019
|
+
return descriptor;
|
|
2020
|
+
}
|
|
2021
|
+
const className = target.constructor.name;
|
|
2022
|
+
const methodName = String(propertyKey);
|
|
2023
|
+
const baseName = options.name || `${className.toLowerCase()}_${methodName.toLowerCase()}`;
|
|
2024
|
+
const durationHistogram = createHistogram(`${baseName}_duration_ms`, `Duration of ${className}.${methodName} in milliseconds`, options.boundaries);
|
|
2025
|
+
const totalCounter = createCounter(`${baseName}_total`, `Total calls to ${className}.${methodName}`);
|
|
2026
|
+
const errorCounter = createCounter(`${baseName}_errors_total`, `Total errors in ${className}.${methodName}`);
|
|
2027
|
+
descriptor.value = async function(...args) {
|
|
2028
|
+
if (!isFeatureEnabled("metrics")) {
|
|
2029
|
+
return originalMethod.apply(this, args);
|
|
2030
|
+
}
|
|
2031
|
+
const startTime = Date.now();
|
|
2032
|
+
let result;
|
|
2033
|
+
let hasError = false;
|
|
2034
|
+
try {
|
|
2035
|
+
result = await originalMethod.apply(this, args);
|
|
2036
|
+
return result;
|
|
2037
|
+
} catch (error) {
|
|
2038
|
+
hasError = true;
|
|
2039
|
+
throw error;
|
|
2040
|
+
} finally {
|
|
2041
|
+
const duration = Date.now() - startTime;
|
|
2042
|
+
let labels = {};
|
|
2043
|
+
if (options.labels) {
|
|
2044
|
+
labels = typeof options.labels === "function" ? options.labels(args, result) : options.labels;
|
|
2045
|
+
}
|
|
2046
|
+
if (options.recordDuration !== false) {
|
|
2047
|
+
durationHistogram.record(duration, labels);
|
|
2048
|
+
}
|
|
2049
|
+
if (options.recordCount !== false) {
|
|
2050
|
+
totalCounter.inc({
|
|
2051
|
+
...labels,
|
|
2052
|
+
status: hasError ? "error" : "success"
|
|
2053
|
+
});
|
|
2054
|
+
}
|
|
2055
|
+
if (hasError) {
|
|
2056
|
+
errorCounter.inc(labels);
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
return descriptor;
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
__name(Metric, "Metric");
|
|
2064
|
+
function Log(options = {}) {
|
|
2065
|
+
return function(target, propertyKey, descriptor) {
|
|
2066
|
+
const originalMethod = descriptor.value;
|
|
2067
|
+
if (typeof originalMethod !== "function") {
|
|
2068
|
+
return descriptor;
|
|
2069
|
+
}
|
|
2070
|
+
const className = target.constructor.name;
|
|
2071
|
+
const methodName = String(propertyKey);
|
|
2072
|
+
const level = options.level || "debug";
|
|
2073
|
+
const logEntry = options.logEntry !== false;
|
|
2074
|
+
const logExit = options.logExit !== false;
|
|
2075
|
+
const logError = options.logError !== false;
|
|
2076
|
+
descriptor.value = async function(...args) {
|
|
2077
|
+
if (!isFeatureEnabled("logging")) {
|
|
2078
|
+
return originalMethod.apply(this, args);
|
|
2079
|
+
}
|
|
2080
|
+
const baseMessage = options.message || `${className}.${methodName}`;
|
|
2081
|
+
if (logEntry) {
|
|
2082
|
+
const entryData = {
|
|
2083
|
+
class: className,
|
|
2084
|
+
method: methodName
|
|
2085
|
+
};
|
|
2086
|
+
if (options.includeArgs) {
|
|
2087
|
+
entryData["args"] = args;
|
|
2088
|
+
}
|
|
2089
|
+
logger[level](`[Enter] ${baseMessage}`, entryData);
|
|
2090
|
+
}
|
|
2091
|
+
const startTime = Date.now();
|
|
2092
|
+
try {
|
|
2093
|
+
const result = await originalMethod.apply(this, args);
|
|
2094
|
+
if (logExit) {
|
|
2095
|
+
const duration = Date.now() - startTime;
|
|
2096
|
+
const exitData = {
|
|
2097
|
+
class: className,
|
|
2098
|
+
method: methodName,
|
|
2099
|
+
duration: `${duration}ms`
|
|
2100
|
+
};
|
|
2101
|
+
if (options.includeResult) {
|
|
2102
|
+
exitData["result"] = result;
|
|
2103
|
+
}
|
|
2104
|
+
logger[level](`[Exit] ${baseMessage}`, exitData);
|
|
2105
|
+
}
|
|
2106
|
+
return result;
|
|
2107
|
+
} catch (error) {
|
|
2108
|
+
if (logError) {
|
|
2109
|
+
const duration = Date.now() - startTime;
|
|
2110
|
+
logger.error(`[Error] ${baseMessage}`, {
|
|
2111
|
+
class: className,
|
|
2112
|
+
method: methodName,
|
|
2113
|
+
duration: `${duration}ms`,
|
|
2114
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
throw error;
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
return descriptor;
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
__name(Log, "Log");
|
|
2124
|
+
function shouldSkipInstrumentation(skipOption, args) {
|
|
2125
|
+
if (!skipOption) {
|
|
2126
|
+
return false;
|
|
2127
|
+
}
|
|
2128
|
+
return typeof skipOption === "function" ? skipOption(args) : skipOption;
|
|
2129
|
+
}
|
|
2130
|
+
__name(shouldSkipInstrumentation, "shouldSkipInstrumentation");
|
|
2131
|
+
function startInstrumentationSpan(traceOpts, operationName, operationType, methodName, className, args) {
|
|
2132
|
+
if (traceOpts === null || !isFeatureEnabled("tracing")) {
|
|
2133
|
+
return null;
|
|
2134
|
+
}
|
|
2135
|
+
const tracer = getTracer();
|
|
2136
|
+
const span = tracer.startSpan(traceOpts?.["name"] || operationName, traceOpts?.["kind"] || SpanKind.INTERNAL);
|
|
2137
|
+
span.setAttributes({
|
|
2138
|
+
"operation.type": operationType,
|
|
2139
|
+
"code.function": methodName,
|
|
2140
|
+
"code.namespace": className,
|
|
2141
|
+
...traceOpts?.["attributes"]
|
|
2142
|
+
});
|
|
2143
|
+
if (traceOpts?.["extractAttributes"]) {
|
|
2144
|
+
try {
|
|
2145
|
+
const extractFn = traceOpts["extractAttributes"];
|
|
2146
|
+
span.setAttributes(extractFn(args));
|
|
2147
|
+
} catch {
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
return span;
|
|
2151
|
+
}
|
|
2152
|
+
__name(startInstrumentationSpan, "startInstrumentationSpan");
|
|
2153
|
+
function logInstrumentationEntry(logOpts, operationName, operationType, args) {
|
|
2154
|
+
if (logOpts === null || !isFeatureEnabled("logging")) {
|
|
2155
|
+
return;
|
|
2156
|
+
}
|
|
2157
|
+
if (logOpts?.["logEntry"] === false) {
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2160
|
+
const level = logOpts?.["level"] || "debug";
|
|
2161
|
+
logger[level](`[Enter] ${operationName}`, {
|
|
2162
|
+
operation: operationName,
|
|
2163
|
+
type: operationType,
|
|
2164
|
+
...logOpts?.["includeArgs"] ? {
|
|
2165
|
+
args
|
|
2166
|
+
} : {}
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
__name(logInstrumentationEntry, "logInstrumentationEntry");
|
|
2170
|
+
function handleInstrumentationSuccess(span, traceOpts, result) {
|
|
2171
|
+
if (!span) {
|
|
2172
|
+
return;
|
|
2173
|
+
}
|
|
2174
|
+
span.setStatus(SpanStatus.OK);
|
|
2175
|
+
if (traceOpts?.["includeResult"]) {
|
|
2176
|
+
try {
|
|
2177
|
+
span.setAttribute("result", JSON.stringify(result).substring(0, 500));
|
|
2178
|
+
} catch {
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
__name(handleInstrumentationSuccess, "handleInstrumentationSuccess");
|
|
2183
|
+
function handleInstrumentationError(span, logOpts, operationName, operationType, error, startTime) {
|
|
2184
|
+
if (span && error instanceof Error) {
|
|
2185
|
+
span.recordException(error);
|
|
2186
|
+
}
|
|
2187
|
+
if (logOpts !== null && isFeatureEnabled("logging") && logOpts?.["logError"] !== false) {
|
|
2188
|
+
logger.error(`[Error] ${operationName}`, {
|
|
2189
|
+
operation: operationName,
|
|
2190
|
+
type: operationType,
|
|
2191
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2192
|
+
duration: `${Date.now() - startTime}ms`
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
__name(handleInstrumentationError, "handleInstrumentationError");
|
|
2197
|
+
function recordInstrumentationMetrics(metricOpts, durationHistogram, totalCounter, errorCounter, duration, args, result, hasError) {
|
|
2198
|
+
if (metricOpts === null || !isFeatureEnabled("metrics")) {
|
|
2199
|
+
return;
|
|
2200
|
+
}
|
|
2201
|
+
const labelsFn = metricOpts?.["labels"];
|
|
2202
|
+
const labelsObj = metricOpts?.["labels"];
|
|
2203
|
+
const labels = typeof metricOpts?.["labels"] === "function" ? labelsFn?.(args, result) : labelsObj || {};
|
|
2204
|
+
if (durationHistogram && metricOpts?.["recordDuration"] !== false) {
|
|
2205
|
+
durationHistogram.record(duration, labels);
|
|
2206
|
+
}
|
|
2207
|
+
if (totalCounter && metricOpts?.["recordCount"] !== false) {
|
|
2208
|
+
totalCounter.inc({
|
|
2209
|
+
...labels,
|
|
2210
|
+
status: hasError ? "error" : "success"
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
if (errorCounter && hasError) {
|
|
2214
|
+
errorCounter.inc(labels);
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
__name(recordInstrumentationMetrics, "recordInstrumentationMetrics");
|
|
2218
|
+
function logInstrumentationExit(logOpts, operationName, operationType, duration, result, hasError) {
|
|
2219
|
+
if (logOpts === null || !isFeatureEnabled("logging")) {
|
|
2220
|
+
return;
|
|
2221
|
+
}
|
|
2222
|
+
if (logOpts?.["logExit"] === false || hasError) {
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
const level = logOpts?.["level"] || "debug";
|
|
2226
|
+
logger[level](`[Exit] ${operationName}`, {
|
|
2227
|
+
operation: operationName,
|
|
2228
|
+
type: operationType,
|
|
2229
|
+
duration: `${duration}ms`,
|
|
2230
|
+
...logOpts?.["includeResult"] ? {
|
|
2231
|
+
result
|
|
2232
|
+
} : {}
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
__name(logInstrumentationExit, "logInstrumentationExit");
|
|
2236
|
+
function Instrument(options = {}) {
|
|
2237
|
+
return function(target, propertyKey, descriptor) {
|
|
2238
|
+
const originalMethod = descriptor.value;
|
|
2239
|
+
if (typeof originalMethod !== "function") {
|
|
2240
|
+
return descriptor;
|
|
2241
|
+
}
|
|
2242
|
+
const className = target.constructor.name;
|
|
2243
|
+
const methodName = String(propertyKey);
|
|
2244
|
+
const operationName = options.operationName || `${className}.${methodName}`;
|
|
2245
|
+
const operationType = options.operationType || "internal";
|
|
2246
|
+
let traceOpts;
|
|
2247
|
+
if (options.trace === true) {
|
|
2248
|
+
traceOpts = {};
|
|
2249
|
+
} else if (options.trace === false || options.trace === void 0) {
|
|
2250
|
+
traceOpts = null;
|
|
2251
|
+
} else {
|
|
2252
|
+
traceOpts = options.trace;
|
|
2253
|
+
}
|
|
2254
|
+
let metricOpts;
|
|
2255
|
+
if (options.metrics === true) {
|
|
2256
|
+
metricOpts = {};
|
|
2257
|
+
} else if (options.metrics === false || options.metrics === void 0) {
|
|
2258
|
+
metricOpts = null;
|
|
2259
|
+
} else {
|
|
2260
|
+
metricOpts = options.metrics;
|
|
2261
|
+
}
|
|
2262
|
+
let logOpts;
|
|
2263
|
+
if (options.log === true) {
|
|
2264
|
+
logOpts = {};
|
|
2265
|
+
} else if (options.log === false || options.log === void 0) {
|
|
2266
|
+
logOpts = null;
|
|
2267
|
+
} else {
|
|
2268
|
+
logOpts = options.log;
|
|
2269
|
+
}
|
|
2270
|
+
let durationHistogram = null;
|
|
2271
|
+
let totalCounter = null;
|
|
2272
|
+
let errorCounter = null;
|
|
2273
|
+
if (metricOpts !== null) {
|
|
2274
|
+
const baseName = metricOpts?.["name"] || `${className.toLowerCase()}_${methodName.toLowerCase()}`;
|
|
2275
|
+
durationHistogram = createHistogram(`${baseName}_duration_ms`, `Duration of ${operationName} in ms`);
|
|
2276
|
+
totalCounter = createCounter(`${baseName}_total`, `Total calls to ${operationName}`);
|
|
2277
|
+
errorCounter = createCounter(`${baseName}_errors_total`, `Total errors in ${operationName}`);
|
|
2278
|
+
}
|
|
2279
|
+
descriptor.value = async function(...args) {
|
|
2280
|
+
if (shouldSkipInstrumentation(options.skip, args)) {
|
|
2281
|
+
return originalMethod.apply(this, args);
|
|
2282
|
+
}
|
|
2283
|
+
const startTime = Date.now();
|
|
2284
|
+
let hasError = false;
|
|
2285
|
+
let result;
|
|
2286
|
+
const span = startInstrumentationSpan(traceOpts, operationName, operationType, methodName, className, args);
|
|
2287
|
+
logInstrumentationEntry(logOpts, operationName, operationType, args);
|
|
2288
|
+
try {
|
|
2289
|
+
result = await originalMethod.apply(this, args);
|
|
2290
|
+
handleInstrumentationSuccess(span, traceOpts, result);
|
|
2291
|
+
return result;
|
|
2292
|
+
} catch (error) {
|
|
2293
|
+
hasError = true;
|
|
2294
|
+
handleInstrumentationError(span, logOpts, operationName, operationType, error, startTime);
|
|
2295
|
+
throw error;
|
|
2296
|
+
} finally {
|
|
2297
|
+
const duration = Date.now() - startTime;
|
|
2298
|
+
if (span) {
|
|
2299
|
+
span.end();
|
|
2300
|
+
}
|
|
2301
|
+
recordInstrumentationMetrics(metricOpts, durationHistogram, totalCounter, errorCounter, duration, args, result, hasError);
|
|
2302
|
+
logInstrumentationExit(logOpts, operationName, operationType, duration, result, hasError);
|
|
2303
|
+
}
|
|
2304
|
+
};
|
|
2305
|
+
return descriptor;
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
__name(Instrument, "Instrument");
|
|
2309
|
+
function traced(name, fn, options) {
|
|
2310
|
+
return async (...args) => {
|
|
2311
|
+
if (!isFeatureEnabled("tracing")) {
|
|
2312
|
+
return fn(...args);
|
|
2313
|
+
}
|
|
2314
|
+
const tracer = getTracer();
|
|
2315
|
+
const span = tracer.startSpan(name, options?.kind || SpanKind.INTERNAL);
|
|
2316
|
+
if (options?.attributes) {
|
|
2317
|
+
span.setAttributes(options.attributes);
|
|
2318
|
+
}
|
|
2319
|
+
try {
|
|
2320
|
+
const result = await fn(...args);
|
|
2321
|
+
span.setStatus(SpanStatus.OK);
|
|
2322
|
+
return result;
|
|
2323
|
+
} catch (error) {
|
|
2324
|
+
if (error instanceof Error) {
|
|
2325
|
+
span.recordException(error);
|
|
2326
|
+
}
|
|
2327
|
+
throw error;
|
|
2328
|
+
} finally {
|
|
2329
|
+
span.end();
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
__name(traced, "traced");
|
|
2334
|
+
function instrumented(name, fn, options) {
|
|
2335
|
+
const operationType = options?.operationType || "internal";
|
|
2336
|
+
const durationHistogram = options?.metrics !== false ? createHistogram(`${name.toLowerCase()}_duration_ms`, `Duration of ${name} in ms`) : null;
|
|
2337
|
+
const totalCounter = options?.metrics !== false ? createCounter(`${name.toLowerCase()}_total`, `Total calls to ${name}`) : null;
|
|
2338
|
+
return async (...args) => {
|
|
2339
|
+
const startTime = Date.now();
|
|
2340
|
+
let span = null;
|
|
2341
|
+
let hasError = false;
|
|
2342
|
+
if (options?.trace !== false && isFeatureEnabled("tracing")) {
|
|
2343
|
+
span = getTracer().startSpan(name, SpanKind.INTERNAL);
|
|
2344
|
+
span.setAttribute("operation.type", operationType);
|
|
2345
|
+
}
|
|
2346
|
+
if (options?.log !== false && isFeatureEnabled("logging")) {
|
|
2347
|
+
logger.debug(`[Enter] ${name}`, {
|
|
2348
|
+
operation: name,
|
|
2349
|
+
type: operationType
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
try {
|
|
2353
|
+
const result = await fn(...args);
|
|
2354
|
+
if (span) span.setStatus(SpanStatus.OK);
|
|
2355
|
+
return result;
|
|
2356
|
+
} catch (error) {
|
|
2357
|
+
hasError = true;
|
|
2358
|
+
if (span && error instanceof Error) span.recordException(error);
|
|
2359
|
+
throw error;
|
|
2360
|
+
} finally {
|
|
2361
|
+
const duration = Date.now() - startTime;
|
|
2362
|
+
if (span) span.end();
|
|
2363
|
+
if (durationHistogram && isFeatureEnabled("metrics")) {
|
|
2364
|
+
durationHistogram.record(duration, {
|
|
2365
|
+
status: hasError ? "error" : "success"
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
if (totalCounter && isFeatureEnabled("metrics")) {
|
|
2369
|
+
totalCounter.inc({
|
|
2370
|
+
status: hasError ? "error" : "success"
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
if (options?.log !== false && isFeatureEnabled("logging")) {
|
|
2374
|
+
if (hasError) {
|
|
2375
|
+
logger.error(`[Error] ${name}`, {
|
|
2376
|
+
operation: name,
|
|
2377
|
+
duration: `${duration}ms`
|
|
2378
|
+
});
|
|
2379
|
+
} else {
|
|
2380
|
+
logger.debug(`[Exit] ${name}`, {
|
|
2381
|
+
operation: name,
|
|
2382
|
+
duration: `${duration}ms`
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
__name(instrumented, "instrumented");
|
|
2390
|
+
|
|
2391
|
+
// src/instrumentation/index.ts
|
|
2392
|
+
function getLogger() {
|
|
2393
|
+
return getActiveTelemetryLogger() ?? logger;
|
|
2394
|
+
}
|
|
2395
|
+
__name(getLogger, "getLogger");
|
|
2396
|
+
function initializeInstrumentation(serviceName, options) {
|
|
2397
|
+
initializeInstrumentationConfig(serviceName, options);
|
|
2398
|
+
initializeTracer(serviceName);
|
|
2399
|
+
initializeMetricsRegistry(serviceName);
|
|
2400
|
+
return {
|
|
2401
|
+
tracer: getTracer(),
|
|
2402
|
+
metrics: getMetricsRegistry(),
|
|
2403
|
+
config: getInstrumentationConfig()
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
__name(initializeInstrumentation, "initializeInstrumentation");
|
|
2407
|
+
function isInstrumentationInitialized() {
|
|
2408
|
+
return isInstrumentationConfigInitialized() && isTracerInitialized() && isMetricsRegistryInitialized();
|
|
2409
|
+
}
|
|
2410
|
+
__name(isInstrumentationInitialized, "isInstrumentationInitialized");
|
|
2411
|
+
function resetInstrumentation() {
|
|
2412
|
+
resetInstrumentationConfig();
|
|
2413
|
+
resetMetricsRegistry();
|
|
2414
|
+
}
|
|
2415
|
+
__name(resetInstrumentation, "resetInstrumentation");
|
|
2416
|
+
function setupInstrumentation(serviceName, options) {
|
|
2417
|
+
const { tracer, metrics, config } = initializeInstrumentation(serviceName, options);
|
|
2418
|
+
const plugins = [];
|
|
2419
|
+
const useApollo = options?.useApolloInlineTrace ?? true;
|
|
2420
|
+
if (useApollo) {
|
|
2421
|
+
const apolloPlugin = createApolloInlineTracePlugin();
|
|
2422
|
+
if (apolloPlugin) {
|
|
2423
|
+
plugins.push(apolloPlugin);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
const usePrometheus = options?.usePrometheus ?? true;
|
|
2427
|
+
if (usePrometheus) {
|
|
2428
|
+
const prometheusPlugin = createPrometheusPlugin(options?.prometheus);
|
|
2429
|
+
if (prometheusPlugin) {
|
|
2430
|
+
plugins.push(prometheusPlugin);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
return {
|
|
2434
|
+
tracer,
|
|
2435
|
+
metrics,
|
|
2436
|
+
config,
|
|
2437
|
+
plugins
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
__name(setupInstrumentation, "setupInstrumentation");
|
|
2441
|
+
|
|
2442
|
+
export { DEFAULT_CACHE_CONFIG, DEFAULT_DATABASE_CONFIG, DEFAULT_EVENT_QUEUE_CONFIG, DEFAULT_FEATURE_FLAGS, DEFAULT_GRAPHQL_CONFIG, DEFAULT_HTTP_CONFIG, DEFAULT_LOGGING_CONFIG, DEFAULT_METRICS_CONFIG, DEFAULT_TRACING_CONFIG, ENV_VARS, Instrument, Log, Metric, MetricsRegistry, STANDARD_METRICS, SpanKind, SpanStatus, Trace, Tracer, buildDatabaseConfig, buildFeatureFlags, buildGraphQLConfig, buildInstrumentationConfig, buildMetricsConfig, buildTracingConfig, createApolloInlineTracePlugin, createCounter, createGauge, createGraphQLInstrumentationPlugin, createHistogram, createPrometheusPlugin, createUpDownCounter, extractOperationInfo, extractTraceContext, getGraphQLOperationFromContext, getGraphQLSpanFromContext, getInstrumentationConfig, getLogger, getMetricsRegistry, getTraceContext, getTracer, initializeInstrumentation, initializeInstrumentationConfig, initializeMetricsRegistry, initializeTracer, injectTraceContext, instrumentResolver, instrumentResolverMap, instrumentation_exports, instrumented, isApolloInlineTraceAvailable, isFeatureEnabled, isInstrumentationConfigInitialized, isInstrumentationInitialized, isMetricsRegistryInitialized, isPrometheusAvailable, isTracerInitialized, resetInstrumentation, resetInstrumentationConfig, resetMetricsRegistry, setActiveTelemetryLogger, setupInstrumentation, startSpan, traced, updateInstrumentationConfig, withSpan };
|
|
2443
|
+
//# sourceMappingURL=chunk-4XAEES25.js.map
|
|
2444
|
+
//# sourceMappingURL=chunk-4XAEES25.js.map
|