@frontmcp/observability 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +201 -0
  2. package/index.js +3010 -0
  3. package/package.json +86 -0
package/index.js ADDED
@@ -0,0 +1,3010 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __esm = (fn, res) => function __init() {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __decorateClass = (decorators, target, key, kind) => {
23
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
24
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
25
+ if (decorator = decorators[i])
26
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
27
+ if (kind && result) __defProp(target, key, result);
28
+ return result;
29
+ };
30
+
31
+ // libs/observability/src/logging/sinks/winston.sink.ts
32
+ var winston_sink_exports = {};
33
+ __export(winston_sink_exports, {
34
+ WinstonSink: () => WinstonSink
35
+ });
36
+ function mapToWinstonLevel(level) {
37
+ switch (level) {
38
+ case "debug":
39
+ case "verbose":
40
+ return "debug";
41
+ case "info":
42
+ return "info";
43
+ case "warn":
44
+ return "warn";
45
+ case "error":
46
+ return "error";
47
+ default:
48
+ return "info";
49
+ }
50
+ }
51
+ var WinstonSink;
52
+ var init_winston_sink = __esm({
53
+ "libs/observability/src/logging/sinks/winston.sink.ts"() {
54
+ "use strict";
55
+ WinstonSink = class {
56
+ constructor(logger) {
57
+ this.logger = logger;
58
+ }
59
+ write(entry) {
60
+ const { message, level, ...meta } = entry;
61
+ const winstonLevel = mapToWinstonLevel(level);
62
+ switch (winstonLevel) {
63
+ case "debug":
64
+ this.logger.debug(message, meta);
65
+ break;
66
+ case "info":
67
+ this.logger.info(message, meta);
68
+ break;
69
+ case "warn":
70
+ this.logger.warn(message, meta);
71
+ break;
72
+ case "error":
73
+ this.logger.error(message, meta);
74
+ break;
75
+ }
76
+ }
77
+ };
78
+ }
79
+ });
80
+
81
+ // libs/observability/src/logging/sinks/pino.sink.ts
82
+ var pino_sink_exports = {};
83
+ __export(pino_sink_exports, {
84
+ PinoSink: () => PinoSink
85
+ });
86
+ function mapToPinoLevel(level) {
87
+ switch (level) {
88
+ case "debug":
89
+ case "verbose":
90
+ return "debug";
91
+ case "info":
92
+ return "info";
93
+ case "warn":
94
+ return "warn";
95
+ case "error":
96
+ return "error";
97
+ default:
98
+ return "info";
99
+ }
100
+ }
101
+ var PinoSink;
102
+ var init_pino_sink = __esm({
103
+ "libs/observability/src/logging/sinks/pino.sink.ts"() {
104
+ "use strict";
105
+ PinoSink = class {
106
+ constructor(logger) {
107
+ this.logger = logger;
108
+ }
109
+ write(entry) {
110
+ const { message, level, ...obj } = entry;
111
+ const pinoLevel = mapToPinoLevel(level);
112
+ switch (pinoLevel) {
113
+ case "debug":
114
+ this.logger.debug(obj, message);
115
+ break;
116
+ case "info":
117
+ this.logger.info(obj, message);
118
+ break;
119
+ case "warn":
120
+ this.logger.warn(obj, message);
121
+ break;
122
+ case "error":
123
+ this.logger.error(obj, message);
124
+ break;
125
+ }
126
+ }
127
+ };
128
+ }
129
+ });
130
+
131
+ // libs/observability/src/logging/sinks/otlp.sink.ts
132
+ var otlp_sink_exports = {};
133
+ __export(otlp_sink_exports, {
134
+ OtlpSink: () => OtlpSink
135
+ });
136
+ var OtlpSink;
137
+ var init_otlp_sink = __esm({
138
+ "libs/observability/src/logging/sinks/otlp.sink.ts"() {
139
+ "use strict";
140
+ OtlpSink = class {
141
+ constructor(options) {
142
+ this.batch = [];
143
+ let base = options.endpoint;
144
+ while (base.endsWith("/")) {
145
+ base = base.slice(0, -1);
146
+ }
147
+ this.endpoint = `${base}/v1/logs`;
148
+ this.headers = {
149
+ "Content-Type": "application/json",
150
+ ...options.headers ?? {}
151
+ };
152
+ this.batchSize = options.batchSize ?? 100;
153
+ this.maxQueueSize = options.maxQueueSize ?? 5e3;
154
+ this.serviceName = options.serviceName ?? (typeof process !== "undefined" ? process.env?.["OTEL_SERVICE_NAME"] : void 0) ?? "frontmcp-server";
155
+ const flushMs = options.flushIntervalMs ?? 5e3;
156
+ if (flushMs > 0) {
157
+ this.flushTimer = setInterval(() => {
158
+ void this.flush();
159
+ }, flushMs);
160
+ if (this.flushTimer && typeof this.flushTimer === "object" && "unref" in this.flushTimer) {
161
+ this.flushTimer.unref();
162
+ }
163
+ }
164
+ }
165
+ write(entry) {
166
+ this.batch.push(entry);
167
+ this.enforceCapacity();
168
+ if (this.batch.length >= this.batchSize) {
169
+ void this.flush();
170
+ }
171
+ }
172
+ async flush() {
173
+ if (this.batch.length === 0) return;
174
+ const entries = this.batch.splice(0);
175
+ const payload = this.buildOtlpPayload(entries);
176
+ try {
177
+ const controller = new AbortController();
178
+ const timeout = setTimeout(() => controller.abort(), 1e4);
179
+ try {
180
+ const response = await fetch(this.endpoint, {
181
+ method: "POST",
182
+ headers: this.headers,
183
+ body: JSON.stringify(payload),
184
+ signal: controller.signal
185
+ });
186
+ clearTimeout(timeout);
187
+ if (!response.ok) {
188
+ const body = await response.text().catch(() => "");
189
+ console.error(`[OtlpSink] Export failed: HTTP ${response.status} \u2014 ${body.slice(0, 200)}`);
190
+ this.requeue(entries);
191
+ }
192
+ } catch (err) {
193
+ clearTimeout(timeout);
194
+ console.debug(
195
+ `[OtlpSink] Export error (${entries.length} entries): ${err instanceof Error ? err.message : err}`
196
+ );
197
+ this.requeue(entries);
198
+ }
199
+ } catch {
200
+ }
201
+ }
202
+ requeue(entries) {
203
+ this.batch.unshift(...entries);
204
+ this.enforceCapacity();
205
+ }
206
+ enforceCapacity() {
207
+ if (this.batch.length > this.maxQueueSize) {
208
+ this.batch.splice(0, this.batch.length - this.maxQueueSize);
209
+ }
210
+ }
211
+ async close() {
212
+ if (this.flushTimer) {
213
+ clearInterval(this.flushTimer);
214
+ this.flushTimer = void 0;
215
+ }
216
+ await this.flush();
217
+ }
218
+ /**
219
+ * Build OTLP Logs JSON payload per the OTel spec.
220
+ *
221
+ * @see https://opentelemetry.io/docs/specs/otlp/#otlphttp-request
222
+ * @see https://opentelemetry.io/docs/specs/otel/logs/data-model/
223
+ */
224
+ buildOtlpPayload(entries) {
225
+ return {
226
+ resourceLogs: [
227
+ {
228
+ resource: {
229
+ attributes: [{ key: "service.name", value: { stringValue: this.serviceName } }]
230
+ },
231
+ scopeLogs: [
232
+ {
233
+ scope: { name: "@frontmcp/observability" },
234
+ logRecords: entries.map((entry) => this.entryToLogRecord(entry))
235
+ }
236
+ ]
237
+ }
238
+ ]
239
+ };
240
+ }
241
+ entryToLogRecord(entry) {
242
+ const attrs = [];
243
+ const record = {
244
+ timeUnixNano: String(new Date(entry.timestamp).getTime() * 1e6),
245
+ severityNumber: entry.severity_number,
246
+ severityText: entry.level.toUpperCase(),
247
+ body: { stringValue: entry.message },
248
+ attributes: attrs
249
+ };
250
+ if (entry.trace_id) {
251
+ record.traceId = entry.trace_id;
252
+ }
253
+ if (entry.span_id) {
254
+ record.spanId = entry.span_id;
255
+ }
256
+ if (entry.trace_flags !== void 0) {
257
+ record.flags = entry.trace_flags;
258
+ }
259
+ if (entry.request_id) {
260
+ attrs.push({ key: "frontmcp.request.id", value: { stringValue: entry.request_id } });
261
+ }
262
+ if (entry.session_id_hash) {
263
+ attrs.push({ key: "mcp.session.id", value: { stringValue: entry.session_id_hash } });
264
+ }
265
+ if (entry.scope_id) {
266
+ attrs.push({ key: "frontmcp.scope.id", value: { stringValue: entry.scope_id } });
267
+ }
268
+ if (entry.flow_name) {
269
+ attrs.push({ key: "frontmcp.flow.name", value: { stringValue: entry.flow_name } });
270
+ }
271
+ if (entry.prefix) {
272
+ attrs.push({ key: "log.prefix", value: { stringValue: entry.prefix } });
273
+ }
274
+ if (entry.elapsed_ms !== void 0) {
275
+ attrs.push({
276
+ key: "elapsed_ms",
277
+ value: Number.isInteger(entry.elapsed_ms) ? { intValue: String(entry.elapsed_ms) } : { doubleValue: entry.elapsed_ms }
278
+ });
279
+ }
280
+ if (entry.error) {
281
+ attrs.push({ key: "error.type", value: { stringValue: entry.error.type } });
282
+ attrs.push({ key: "error.message", value: { stringValue: entry.error.message } });
283
+ if (entry.error.code) {
284
+ attrs.push({ key: "error.code", value: { stringValue: entry.error.code } });
285
+ }
286
+ if (entry.error.error_id) {
287
+ attrs.push({ key: "error.id", value: { stringValue: entry.error.error_id } });
288
+ }
289
+ if (entry.error.stack) {
290
+ attrs.push({ key: "error.stack", value: { stringValue: entry.error.stack } });
291
+ }
292
+ }
293
+ if (entry.attributes) {
294
+ for (const [key, value] of Object.entries(entry.attributes)) {
295
+ if (value == null) continue;
296
+ if (typeof value === "string") {
297
+ attrs.push({ key, value: { stringValue: value } });
298
+ } else if (typeof value === "number") {
299
+ attrs.push({
300
+ key,
301
+ value: Number.isInteger(value) ? { intValue: String(value) } : { doubleValue: value }
302
+ });
303
+ } else if (typeof value === "boolean") {
304
+ attrs.push({ key, value: { boolValue: value } });
305
+ } else {
306
+ attrs.push({ key, value: { stringValue: JSON.stringify(value) } });
307
+ }
308
+ }
309
+ }
310
+ return record;
311
+ }
312
+ };
313
+ }
314
+ });
315
+
316
+ // libs/observability/src/index.ts
317
+ var index_exports = {};
318
+ __export(index_exports, {
319
+ CallbackSink: () => CallbackSink,
320
+ ConsoleSink: () => ConsoleSink,
321
+ EnduserAttributes: () => EnduserAttributes,
322
+ FrontMcpAttributes: () => FrontMcpAttributes,
323
+ FrontMcpPropagator: () => FrontMcpPropagator,
324
+ HttpAttributes: () => HttpAttributes,
325
+ LOG_LEVEL_TO_OTEL_SEVERITY: () => LOG_LEVEL_TO_OTEL_SEVERITY,
326
+ McpAttributes: () => McpAttributes,
327
+ OTEL_CONFIG: () => OTEL_CONFIG,
328
+ OTEL_TRACER: () => OTEL_TRACER,
329
+ ObservabilityPlugin: () => ObservabilityPlugin,
330
+ OtlpSink: () => OtlpSink,
331
+ PinoSink: () => PinoSink,
332
+ PrettySpanExporter: () => PrettySpanExporter,
333
+ REQUEST_LOG_COLLECTOR: () => REQUEST_LOG_COLLECTOR,
334
+ RequestLogCollector: () => RequestLogCollector,
335
+ RpcAttributes: () => RpcAttributes,
336
+ StdoutSink: () => StdoutSink,
337
+ StructuredLogTransport: () => StructuredLogTransport,
338
+ TELEMETRY_ACCESSOR: () => TELEMETRY_ACCESSOR,
339
+ TelemetryAccessor: () => TelemetryAccessor,
340
+ TelemetrySpan: () => TelemetrySpan,
341
+ WinstonSink: () => WinstonSink,
342
+ assertSpanAttribute: () => assertSpanAttribute,
343
+ assertSpanExists: () => assertSpanExists,
344
+ createOTelContextFromTrace: () => createOTelContextFromTrace,
345
+ createSink: () => createSink,
346
+ createSinks: () => createSinks,
347
+ createTestTracer: () => createTestTracer,
348
+ emitStartupReport: () => emitStartupReport,
349
+ endSpanError: () => endSpanError,
350
+ endSpanOk: () => endSpanOk,
351
+ findSpan: () => findSpan,
352
+ findSpansByAttribute: () => findSpansByAttribute,
353
+ frontmcpToOTelSpanContext: () => frontmcpToOTelSpanContext,
354
+ getFinishedSpans: () => getFinishedSpans,
355
+ otelToFrontmcpContext: () => otelToFrontmcpContext,
356
+ recordHookEvent: () => recordHookEvent,
357
+ redactFields: () => redactFields,
358
+ reportStartup: () => reportStartup,
359
+ sessionTracingId: () => sessionTracingId,
360
+ setAuthMode: () => setAuthMode,
361
+ setAuthResult: () => setAuthResult,
362
+ setFetchResponseStatus: () => setFetchResponseStatus,
363
+ setHttpResponseStatus: () => setHttpResponseStatus,
364
+ setTransportRequestType: () => setTransportRequestType,
365
+ setupOTel: () => setupOTel,
366
+ startAuthSpan: () => startAuthSpan,
367
+ startFetchSpan: () => startFetchSpan,
368
+ startHookSpan: () => startHookSpan,
369
+ startHttpServerSpan: () => startHttpServerSpan,
370
+ startPromptSpan: () => startPromptSpan,
371
+ startResourceSpan: () => startResourceSpan,
372
+ startRpcSpan: () => startRpcSpan,
373
+ startSpan: () => startSpan,
374
+ startToolSpan: () => startToolSpan,
375
+ startTransportSpan: () => startTransportSpan,
376
+ withSpan: () => withSpan
377
+ });
378
+ module.exports = __toCommonJS(index_exports);
379
+
380
+ // libs/observability/src/plugin/observability.plugin.ts
381
+ var import_sdk2 = require("@frontmcp/sdk");
382
+ var import_api14 = require("@opentelemetry/api");
383
+
384
+ // libs/observability/src/otel/otel.tokens.ts
385
+ var OTEL_TRACER = /* @__PURE__ */ Symbol.for("frontmcp:observability:otel-tracer");
386
+ var OTEL_CONFIG = /* @__PURE__ */ Symbol.for("frontmcp:observability:otel-config");
387
+
388
+ // libs/observability/src/request-log/request-log.tokens.ts
389
+ var REQUEST_LOG_COLLECTOR = /* @__PURE__ */ Symbol.for("frontmcp:observability:request-log-collector");
390
+
391
+ // libs/observability/src/request-log/request-log.collector.ts
392
+ var RequestLogCollector = class {
393
+ constructor(context, options) {
394
+ this.entries = [];
395
+ this.hooksTriggered = /* @__PURE__ */ new Set();
396
+ this.authenticated = false;
397
+ this.status = "ok";
398
+ this.finalized = false;
399
+ this.requestId = context.requestId;
400
+ this.traceId = context.traceId;
401
+ this.sessionIdHash = context.sessionIdHash;
402
+ this.scopeId = context.scopeId;
403
+ this.startTime = /* @__PURE__ */ new Date();
404
+ this.maxEntries = options?.maxEntries ?? 500;
405
+ this.onComplete = options?.onRequestComplete;
406
+ }
407
+ /**
408
+ * Add a structured log entry to this request's log.
409
+ * Called by StructuredLogTransport for each log record that
410
+ * matches this request's requestId.
411
+ */
412
+ addEntry(entry) {
413
+ if (this.finalized || this.entries.length >= this.maxEntries) return;
414
+ const logEntry = {
415
+ timestamp: entry.timestamp,
416
+ level: entry.level,
417
+ message: entry.message
418
+ };
419
+ if (entry.flow_name) {
420
+ logEntry.stage = entry.flow_name;
421
+ }
422
+ if (entry.elapsed_ms !== void 0) {
423
+ logEntry.elapsed_ms = entry.elapsed_ms;
424
+ }
425
+ if (entry.attributes && Object.keys(entry.attributes).length > 0) {
426
+ logEntry.attributes = entry.attributes;
427
+ }
428
+ this.entries.push(logEntry);
429
+ }
430
+ /**
431
+ * Record a hook stage that was triggered during this request.
432
+ */
433
+ addHook(stage) {
434
+ this.hooksTriggered.add(stage);
435
+ }
436
+ /**
437
+ * Set HTTP request metadata.
438
+ */
439
+ setHttpInfo(method, path) {
440
+ this.httpMethod = method;
441
+ this.httpPath = path;
442
+ }
443
+ /**
444
+ * Set the MCP JSON-RPC method being invoked.
445
+ */
446
+ setRpcMethod(method) {
447
+ this.rpcMethod = method;
448
+ }
449
+ /**
450
+ * Set the tool name being invoked.
451
+ */
452
+ setToolName(name) {
453
+ this.toolName = name;
454
+ }
455
+ /**
456
+ * Set the resource URI being read.
457
+ */
458
+ setResourceUri(uri) {
459
+ this.resourceUri = uri;
460
+ }
461
+ /**
462
+ * Set the prompt name being invoked.
463
+ */
464
+ setPromptName(name) {
465
+ this.promptName = name;
466
+ }
467
+ /**
468
+ * Set authentication info.
469
+ */
470
+ setAuthInfo(type, authenticated) {
471
+ this.authType = type;
472
+ this.authenticated = authenticated;
473
+ }
474
+ /**
475
+ * Set request status.
476
+ */
477
+ setStatus(status, statusCode) {
478
+ this.status = status;
479
+ this.statusCode = statusCode;
480
+ }
481
+ /**
482
+ * Set error details.
483
+ */
484
+ setError(error) {
485
+ this.error = error;
486
+ this.status = "error";
487
+ }
488
+ /**
489
+ * Finalize and produce the complete RequestLog.
490
+ * Fires the onRequestComplete callback if configured.
491
+ */
492
+ async finalize() {
493
+ if (this.finalized) {
494
+ return this.finalizedLog;
495
+ }
496
+ this.finalized = true;
497
+ const log = this.toRequestLog();
498
+ this.finalizedLog = log;
499
+ if (this.onComplete) {
500
+ try {
501
+ await this.onComplete(log);
502
+ } catch {
503
+ }
504
+ }
505
+ return log;
506
+ }
507
+ /**
508
+ * Build the RequestLog object from accumulated state.
509
+ */
510
+ toRequestLog() {
511
+ const endTime = /* @__PURE__ */ new Date();
512
+ return {
513
+ request_id: this.requestId,
514
+ trace_id: this.traceId,
515
+ session_id_hash: this.sessionIdHash,
516
+ scope_id: this.scopeId,
517
+ start_time: this.startTime.toISOString(),
518
+ end_time: endTime.toISOString(),
519
+ duration_ms: endTime.getTime() - this.startTime.getTime(),
520
+ http_method: this.httpMethod,
521
+ http_path: this.httpPath,
522
+ rpc_method: this.rpcMethod,
523
+ tool_name: this.toolName,
524
+ resource_uri: this.resourceUri,
525
+ prompt_name: this.promptName,
526
+ auth_type: this.authType,
527
+ authenticated: this.authenticated,
528
+ status: this.status,
529
+ status_code: this.statusCode,
530
+ error: this.error,
531
+ hooks_triggered: Array.from(this.hooksTriggered),
532
+ entries: [...this.entries]
533
+ };
534
+ }
535
+ /**
536
+ * Check if the collector has been finalized.
537
+ */
538
+ isFinalized() {
539
+ return this.finalized;
540
+ }
541
+ /**
542
+ * Get the number of accumulated entries.
543
+ */
544
+ getEntryCount() {
545
+ return this.entries.length;
546
+ }
547
+ };
548
+
549
+ // libs/observability/src/logging/structured-log-transport.ts
550
+ var import_sdk = require("@frontmcp/sdk");
551
+
552
+ // libs/observability/src/logging/structured-log.types.ts
553
+ var LOG_LEVEL_TO_OTEL_SEVERITY = {
554
+ debug: 5,
555
+ // DEBUG
556
+ verbose: 6,
557
+ // DEBUG2
558
+ info: 9,
559
+ // INFO
560
+ warn: 13,
561
+ // WARN
562
+ error: 17
563
+ // ERROR
564
+ };
565
+
566
+ // libs/observability/src/logging/redaction.ts
567
+ var REDACTED = "[REDACTED]";
568
+ function redactFields(obj, fields, maxDepth = 5) {
569
+ if (fields.length === 0) return obj;
570
+ const lowerFields = new Set(fields.map((f) => f.toLowerCase()));
571
+ return redactRecursive(obj, lowerFields, 0, maxDepth);
572
+ }
573
+ function redactRecursive(obj, fields, depth, maxDepth) {
574
+ if (depth >= maxDepth) return obj;
575
+ const result = {};
576
+ for (const [key, value] of Object.entries(obj)) {
577
+ if (fields.has(key.toLowerCase())) {
578
+ result[key] = REDACTED;
579
+ } else if (isPlainObject(value)) {
580
+ result[key] = redactRecursive(value, fields, depth + 1, maxDepth);
581
+ } else if (Array.isArray(value)) {
582
+ result[key] = value.map(
583
+ (item) => isPlainObject(item) ? redactRecursive(item, fields, depth + 1, maxDepth) : item
584
+ );
585
+ } else {
586
+ result[key] = value;
587
+ }
588
+ }
589
+ return result;
590
+ }
591
+ function isPlainObject(value) {
592
+ if (typeof value !== "object" || value === null) return false;
593
+ const proto = Object.getPrototypeOf(value);
594
+ return proto === Object.prototype || proto === null;
595
+ }
596
+
597
+ // libs/observability/src/logging/structured-log-transport.ts
598
+ var StructuredLogTransport = class extends import_sdk.LogTransportInterface {
599
+ constructor(sinks, options, contextAccessor) {
600
+ super();
601
+ this.sinks = sinks;
602
+ this.redactFieldNames = options?.redactFields ?? [];
603
+ this.includeStacks = options?.includeStacks ?? true;
604
+ this.staticFields = options?.staticFields ?? {};
605
+ this.getContext = contextAccessor;
606
+ }
607
+ log(rec) {
608
+ const entry = this.buildEntry(rec);
609
+ if (this.onEntry) {
610
+ try {
611
+ this.onEntry(entry);
612
+ } catch {
613
+ }
614
+ }
615
+ for (const sink of this.sinks) {
616
+ try {
617
+ sink.write(entry);
618
+ } catch {
619
+ }
620
+ }
621
+ }
622
+ buildEntry(rec) {
623
+ const levelName = import_sdk.LogLevelName[rec.level] ?? "info";
624
+ const entry = {
625
+ ...this.staticFields,
626
+ timestamp: rec.timestamp.toISOString(),
627
+ level: levelName,
628
+ severity_number: LOG_LEVEL_TO_OTEL_SEVERITY[levelName] ?? 9,
629
+ message: String(rec.message)
630
+ };
631
+ if (rec.prefix) {
632
+ entry.prefix = rec.prefix;
633
+ }
634
+ const ctx = this.getContext?.();
635
+ if (ctx) {
636
+ entry.trace_id = ctx.traceContext.traceId;
637
+ entry.span_id = ctx.traceContext.parentId;
638
+ entry.trace_flags = ctx.traceContext.traceFlags;
639
+ entry.request_id = ctx.requestId;
640
+ entry.session_id_hash = ctx.sessionIdHash;
641
+ entry.scope_id = ctx.scopeId;
642
+ if (ctx.flowName) {
643
+ entry.flow_name = ctx.flowName;
644
+ }
645
+ entry.elapsed_ms = ctx.elapsed;
646
+ }
647
+ this.processArgs(rec.args, entry);
648
+ return entry;
649
+ }
650
+ processArgs(args, entry) {
651
+ const attributes = {};
652
+ let hasAttributes = false;
653
+ for (const arg of args) {
654
+ if (arg instanceof Error) {
655
+ entry.error = this.buildError(arg);
656
+ } else if (typeof arg === "object" && arg !== null && !Array.isArray(arg)) {
657
+ const obj = arg;
658
+ const redacted = this.redactFieldNames.length > 0 ? redactFields(obj, this.redactFieldNames) : obj;
659
+ Object.assign(attributes, redacted);
660
+ hasAttributes = true;
661
+ }
662
+ }
663
+ if (hasAttributes) {
664
+ entry.attributes = attributes;
665
+ }
666
+ }
667
+ buildError(err) {
668
+ const result = {
669
+ type: err.constructor.name,
670
+ message: err.message
671
+ };
672
+ if ("code" in err && typeof err.code === "number") {
673
+ result.code = String(err.code);
674
+ }
675
+ if ("errorId" in err && typeof err.errorId === "string") {
676
+ result.error_id = err.errorId;
677
+ }
678
+ if (this.includeStacks && err.stack) {
679
+ result.stack = err.stack;
680
+ }
681
+ return result;
682
+ }
683
+ };
684
+ StructuredLogTransport = __decorateClass([
685
+ (0, import_sdk.LogTransport)({
686
+ name: "StructuredLogTransport",
687
+ description: "Produces structured log objects and forwards to configurable sinks"
688
+ })
689
+ ], StructuredLogTransport);
690
+
691
+ // libs/observability/src/logging/sinks/stdout.sink.ts
692
+ var StdoutSink = class {
693
+ constructor(options) {
694
+ this.stream = options?.stream ?? process.stdout;
695
+ this.pretty = options?.pretty ?? false;
696
+ }
697
+ write(entry) {
698
+ const line = this.pretty ? JSON.stringify(entry, null, 2) : JSON.stringify(entry);
699
+ this.stream.write(line + "\n");
700
+ }
701
+ };
702
+
703
+ // libs/observability/src/logging/sinks/console.sink.ts
704
+ var ConsoleSink = class {
705
+ write(entry) {
706
+ const method = levelToConsoleMethod(entry.level);
707
+ const formatted = formatEntry(entry);
708
+ method(formatted);
709
+ }
710
+ };
711
+ function formatEntry(entry) {
712
+ const useAnsi = typeof process !== "undefined" && !!process.stdout?.isTTY;
713
+ const ts = entry.timestamp.slice(11, 23);
714
+ const level = entry.level.toUpperCase().padEnd(7);
715
+ const traceShort = entry.trace_id ? entry.trace_id.slice(0, 8) : "";
716
+ const reqShort = entry.request_id ? entry.request_id.slice(0, 8) : "";
717
+ const parts = [];
718
+ const DIM2 = useAnsi ? "\x1B[2m" : "";
719
+ const BOLD2 = useAnsi ? "\x1B[1m" : "";
720
+ const RESET2 = useAnsi ? "\x1B[0m" : "";
721
+ const levelColor = useAnsi ? LEVEL_COLORS[entry.level] ?? "" : "";
722
+ parts.push(`${DIM2}[${ts}]${RESET2}`);
723
+ parts.push(`${BOLD2}${levelColor}${level}${RESET2}`);
724
+ if (traceShort || reqShort) {
725
+ parts.push(`${DIM2}[${traceShort}${reqShort ? ":" + reqShort : ""}]${RESET2}`);
726
+ }
727
+ if (entry.prefix) parts.push(`${DIM2}[${entry.prefix}]${RESET2}`);
728
+ parts.push(entry.message);
729
+ if (entry.attributes && Object.keys(entry.attributes).length > 0) {
730
+ const attrs = Object.entries(entry.attributes).map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`).join(" ");
731
+ parts.push(`${DIM2}{ ${attrs} }${RESET2}`);
732
+ }
733
+ if (entry.error) {
734
+ parts.push(`[${entry.error.type}: ${entry.error.message}]`);
735
+ }
736
+ if (entry.elapsed_ms !== void 0) {
737
+ parts.push(`${DIM2}(${entry.elapsed_ms}ms)${RESET2}`);
738
+ }
739
+ return parts.join(" ");
740
+ }
741
+ var LEVEL_COLORS = {
742
+ debug: "\x1B[34m",
743
+ verbose: "\x1B[90m",
744
+ info: "\x1B[32m",
745
+ warn: "\x1B[33m",
746
+ error: "\x1B[31m"
747
+ };
748
+ function levelToConsoleMethod(level) {
749
+ switch (level) {
750
+ case "debug":
751
+ case "verbose":
752
+ return console.debug;
753
+ case "info":
754
+ return console.info;
755
+ case "warn":
756
+ return console.warn;
757
+ case "error":
758
+ return console.error;
759
+ default:
760
+ return console.log;
761
+ }
762
+ }
763
+
764
+ // libs/observability/src/logging/sinks/callback.sink.ts
765
+ var CallbackSink = class {
766
+ constructor(fn) {
767
+ this.fn = fn;
768
+ }
769
+ write(entry) {
770
+ this.fn(entry);
771
+ }
772
+ };
773
+
774
+ // libs/observability/src/logging/sink.factory.ts
775
+ function createSink(config) {
776
+ switch (config.type) {
777
+ case "stdout":
778
+ return new StdoutSink({ stream: config.stream, pretty: config.pretty });
779
+ case "console":
780
+ return new ConsoleSink();
781
+ case "winston": {
782
+ const { WinstonSink: WinstonSink2 } = (init_winston_sink(), __toCommonJS(winston_sink_exports));
783
+ return new WinstonSink2(config.logger);
784
+ }
785
+ case "pino": {
786
+ const { PinoSink: PinoSink2 } = (init_pino_sink(), __toCommonJS(pino_sink_exports));
787
+ return new PinoSink2(config.logger);
788
+ }
789
+ case "callback":
790
+ return new CallbackSink(config.fn);
791
+ case "otlp": {
792
+ const { OtlpSink: OtlpSink2 } = (init_otlp_sink(), __toCommonJS(otlp_sink_exports));
793
+ return new OtlpSink2({
794
+ endpoint: config.endpoint ?? (typeof process !== "undefined" ? process.env?.["OTEL_EXPORTER_OTLP_ENDPOINT"] : void 0) ?? "http://localhost:4318",
795
+ headers: config.headers,
796
+ batchSize: config.batchSize,
797
+ flushIntervalMs: config.flushIntervalMs,
798
+ serviceName: config.serviceName
799
+ });
800
+ }
801
+ default:
802
+ throw new Error(`Unknown sink type: ${config.type}`);
803
+ }
804
+ }
805
+ function createSinks(configs) {
806
+ if (configs && configs.length > 0) {
807
+ return configs.map(createSink);
808
+ }
809
+ return [];
810
+ }
811
+
812
+ // libs/observability/src/telemetry/telemetry.accessor.ts
813
+ var import_api13 = require("@opentelemetry/api");
814
+
815
+ // libs/observability/src/otel/trace-context-bridge.ts
816
+ var import_api = require("@opentelemetry/api");
817
+ function frontmcpToOTelSpanContext(tc) {
818
+ return {
819
+ traceId: tc.traceId,
820
+ spanId: tc.parentId,
821
+ traceFlags: tc.traceFlags & import_api.TraceFlags.SAMPLED ? import_api.TraceFlags.SAMPLED : import_api.TraceFlags.NONE,
822
+ isRemote: true
823
+ };
824
+ }
825
+ function otelToFrontmcpContext(sc) {
826
+ const flags = sc.traceFlags.toString(16).padStart(2, "0");
827
+ return {
828
+ traceId: sc.traceId,
829
+ parentId: sc.spanId,
830
+ traceFlags: sc.traceFlags,
831
+ raw: `00-${sc.traceId}-${sc.spanId}-${flags}`
832
+ };
833
+ }
834
+ function createOTelContextFromTrace(tc) {
835
+ const spanContext = frontmcpToOTelSpanContext(tc);
836
+ const span = import_api.trace.wrapSpanContext(spanContext);
837
+ return import_api.trace.setSpan(import_api.context.active(), span);
838
+ }
839
+
840
+ // libs/observability/src/plugin/observability.hooks.ts
841
+ var import_utils = require("@frontmcp/utils");
842
+ var import_api12 = require("@opentelemetry/api");
843
+
844
+ // libs/observability/src/otel/spans/http-server.span.ts
845
+ var import_api3 = require("@opentelemetry/api");
846
+
847
+ // libs/observability/src/otel/otel.types.ts
848
+ var McpAttributes = {
849
+ /** MCP protocol method name (e.g., "tools/call", "resources/read") */
850
+ METHOD_NAME: "mcp.method.name",
851
+ /** MCP session identifier (hashed for privacy) */
852
+ SESSION_ID: "mcp.session.id",
853
+ /** MCP resource URI */
854
+ RESOURCE_URI: "mcp.resource.uri",
855
+ /** MCP component type: "tool" | "resource" | "prompt" | "resource_template" */
856
+ COMPONENT_TYPE: "mcp.component.type",
857
+ /** MCP component key (e.g., "tool:get_weather", "resource:config://db") */
858
+ COMPONENT_KEY: "mcp.component.key"
859
+ };
860
+ var FrontMcpAttributes = {
861
+ /** Scope identifier */
862
+ SCOPE_ID: "frontmcp.scope.id",
863
+ /** Server/scope name */
864
+ SERVER_NAME: "frontmcp.server.name",
865
+ /** Tool name being executed */
866
+ TOOL_NAME: "frontmcp.tool.name",
867
+ /** Tool owner class name */
868
+ TOOL_OWNER: "frontmcp.tool.owner",
869
+ /** Resource URI being read */
870
+ RESOURCE_URI: "frontmcp.resource.uri",
871
+ /** Resource name */
872
+ RESOURCE_NAME: "frontmcp.resource.name",
873
+ /** Prompt name being invoked */
874
+ PROMPT_NAME: "frontmcp.prompt.name",
875
+ /** Flow name (e.g., "tools:call-tool") */
876
+ FLOW_NAME: "frontmcp.flow.name",
877
+ /** Flow stage (e.g., "willExecute") */
878
+ FLOW_STAGE: "frontmcp.flow.stage",
879
+ /** Hook stage (e.g., "willValidateInput") */
880
+ HOOK_STAGE: "frontmcp.hook.stage",
881
+ /** Hook owner identifier */
882
+ HOOK_OWNER: "frontmcp.hook.owner",
883
+ /** Hashed session ID (for trace correlation, not the real session ID) */
884
+ SESSION_ID_HASH: "frontmcp.session.id_hash",
885
+ /** Authentication type */
886
+ AUTH_TYPE: "frontmcp.auth.type",
887
+ /** Request identifier */
888
+ REQUEST_ID: "frontmcp.request.id",
889
+ /** Provider type (e.g., "local", "adapter", "remote") */
890
+ PROVIDER_TYPE: "frontmcp.provider.type",
891
+ /** Delegation — original name before namespacing */
892
+ DELEGATE_ORIGINAL_NAME: "frontmcp.delegate.original_name",
893
+ // ── Transport ──
894
+ /** Transport type: "legacy-sse" | "streamable-http" | "stateless-http" */
895
+ TRANSPORT_TYPE: "frontmcp.transport.type",
896
+ /** Transport request type: "initialize" | "message" | "elicitResult" | "sseListener" | "extApps" */
897
+ TRANSPORT_REQUEST_TYPE: "frontmcp.transport.request_type",
898
+ /** Session protocol */
899
+ SESSION_PROTOCOL: "frontmcp.session.protocol",
900
+ /** Whether a new session was created */
901
+ SESSION_CREATED: "frontmcp.session.created",
902
+ // ── Auth ──
903
+ /** Auth mode: "public" | "transparent" | "orchestrated" */
904
+ AUTH_MODE: "frontmcp.auth.mode",
905
+ /** Auth result: "authorized" | "unauthorized" | "anonymous" */
906
+ AUTH_RESULT: "frontmcp.auth.result",
907
+ // ── OAuth ──
908
+ /** OAuth grant type: "authorization_code" | "refresh_token" | "anonymous" */
909
+ OAUTH_GRANT_TYPE: "frontmcp.oauth.grant_type",
910
+ // ── Elicitation ──
911
+ /** Elicitation request ID */
912
+ ELICITATION_ID: "frontmcp.elicitation.id",
913
+ // ── Agent ──
914
+ /** Agent name */
915
+ AGENT_NAME: "frontmcp.agent.name",
916
+ /** Agent execution loop iterations */
917
+ AGENT_ITERATIONS: "frontmcp.agent.iterations",
918
+ /** Agent execution duration in ms */
919
+ AGENT_EXECUTION_DURATION_MS: "frontmcp.agent.execution_duration_ms",
920
+ // ── Startup ──
921
+ /** Total tools registered at startup */
922
+ STARTUP_TOOLS_COUNT: "frontmcp.startup.tools_count",
923
+ /** Total resources registered at startup */
924
+ STARTUP_RESOURCES_COUNT: "frontmcp.startup.resources_count",
925
+ /** Total prompts registered at startup */
926
+ STARTUP_PROMPTS_COUNT: "frontmcp.startup.prompts_count",
927
+ /** Total plugins loaded at startup */
928
+ STARTUP_PLUGINS_COUNT: "frontmcp.startup.plugins_count",
929
+ /** Startup initialization duration in ms */
930
+ STARTUP_DURATION_MS: "frontmcp.startup.duration_ms"
931
+ };
932
+ var HttpAttributes = {
933
+ METHOD: "http.request.method",
934
+ STATUS_CODE: "http.response.status_code",
935
+ URL_PATH: "url.path",
936
+ URL_FULL: "url.full",
937
+ URL_SCHEME: "url.scheme",
938
+ SERVER_ADDRESS: "server.address",
939
+ SERVER_PORT: "server.port"
940
+ };
941
+ var RpcAttributes = {
942
+ /** RPC system — "mcp" for MCP protocol */
943
+ SYSTEM: "rpc.system",
944
+ /** RPC service name */
945
+ SERVICE: "rpc.service",
946
+ /** RPC method */
947
+ METHOD: "rpc.method",
948
+ /** JSON-RPC version */
949
+ JSONRPC_VERSION: "rpc.jsonrpc.version",
950
+ /** JSON-RPC request ID */
951
+ JSONRPC_REQUEST_ID: "rpc.jsonrpc.request_id"
952
+ };
953
+ var EnduserAttributes = {
954
+ /** Client/user ID from auth token */
955
+ ID: "enduser.id",
956
+ /** OAuth scopes (space-separated) */
957
+ SCOPE: "enduser.scope"
958
+ };
959
+
960
+ // libs/observability/src/otel/spans/span.utils.ts
961
+ var import_api2 = require("@opentelemetry/api");
962
+ function startSpan(tracer, options) {
963
+ const parentCtx = options.parentContext ?? import_api2.context.active();
964
+ const span = tracer.startSpan(
965
+ options.name,
966
+ {
967
+ kind: options.kind ?? import_api2.SpanKind.INTERNAL,
968
+ attributes: options.attributes
969
+ },
970
+ parentCtx
971
+ );
972
+ const spanContext = import_api2.trace.setSpan(parentCtx, span);
973
+ return { span, context: spanContext };
974
+ }
975
+ function endSpanOk(span) {
976
+ span.setStatus({ code: import_api2.SpanStatusCode.OK });
977
+ span.end();
978
+ }
979
+ function endSpanError(span, error) {
980
+ const message = typeof error === "string" ? error : error.message;
981
+ span.setStatus({ code: import_api2.SpanStatusCode.ERROR, message });
982
+ if (error instanceof Error) {
983
+ span.recordException(error);
984
+ }
985
+ span.end();
986
+ }
987
+ async function withSpan(tracer, options, fn) {
988
+ const { span, context: spanContext } = startSpan(tracer, options);
989
+ return import_api2.context.with(spanContext, async () => {
990
+ try {
991
+ const result = await fn(span);
992
+ endSpanOk(span);
993
+ return result;
994
+ } catch (err) {
995
+ endSpanError(span, err instanceof Error ? err : String(err));
996
+ throw err;
997
+ }
998
+ });
999
+ }
1000
+
1001
+ // libs/observability/src/otel/spans/http-server.span.ts
1002
+ function startHttpServerSpan(tracer, options) {
1003
+ const attributes = {
1004
+ [HttpAttributes.METHOD]: options.method.toUpperCase(),
1005
+ [HttpAttributes.URL_PATH]: options.path
1006
+ };
1007
+ if (options.scheme) {
1008
+ attributes[HttpAttributes.URL_SCHEME] = options.scheme;
1009
+ }
1010
+ if (options.serverAddress) {
1011
+ attributes[HttpAttributes.SERVER_ADDRESS] = options.serverAddress;
1012
+ }
1013
+ if (options.serverPort) {
1014
+ attributes[HttpAttributes.SERVER_PORT] = options.serverPort;
1015
+ }
1016
+ if (options.scopeId) {
1017
+ attributes[FrontMcpAttributes.SCOPE_ID] = options.scopeId;
1018
+ }
1019
+ if (options.requestId) {
1020
+ attributes[FrontMcpAttributes.REQUEST_ID] = options.requestId;
1021
+ }
1022
+ return startSpan(tracer, {
1023
+ name: `${options.method.toUpperCase()} ${options.path}`,
1024
+ kind: import_api3.SpanKind.SERVER,
1025
+ attributes,
1026
+ parentContext: options.parentContext
1027
+ });
1028
+ }
1029
+ function setHttpResponseStatus(span, statusCode) {
1030
+ span.setAttribute(HttpAttributes.STATUS_CODE, statusCode);
1031
+ }
1032
+
1033
+ // libs/observability/src/otel/spans/rpc.span.ts
1034
+ var import_api4 = require("@opentelemetry/api");
1035
+ function startRpcSpan(tracer, options) {
1036
+ const attributes = {
1037
+ [RpcAttributes.SYSTEM]: "mcp",
1038
+ [RpcAttributes.METHOD]: options.method,
1039
+ [RpcAttributes.JSONRPC_VERSION]: "2.0",
1040
+ [McpAttributes.METHOD_NAME]: options.method
1041
+ };
1042
+ if (options.requestId !== void 0) {
1043
+ attributes[RpcAttributes.JSONRPC_REQUEST_ID] = String(options.requestId);
1044
+ }
1045
+ if (options.scopeId) {
1046
+ attributes[FrontMcpAttributes.SCOPE_ID] = options.scopeId;
1047
+ }
1048
+ if (options.serviceName) {
1049
+ attributes[RpcAttributes.SERVICE] = options.serviceName;
1050
+ attributes[FrontMcpAttributes.SERVER_NAME] = options.serviceName;
1051
+ }
1052
+ if (options.sessionIdHash) {
1053
+ attributes[McpAttributes.SESSION_ID] = options.sessionIdHash;
1054
+ attributes[FrontMcpAttributes.SESSION_ID_HASH] = options.sessionIdHash;
1055
+ }
1056
+ return startSpan(tracer, {
1057
+ name: options.method,
1058
+ kind: import_api4.SpanKind.SERVER,
1059
+ attributes,
1060
+ parentContext: options.parentContext
1061
+ });
1062
+ }
1063
+
1064
+ // libs/observability/src/otel/spans/tool.span.ts
1065
+ var import_api5 = require("@opentelemetry/api");
1066
+ function startToolSpan(tracer, options) {
1067
+ const attributes = {
1068
+ [FrontMcpAttributes.TOOL_NAME]: options.name,
1069
+ [McpAttributes.COMPONENT_TYPE]: "tool",
1070
+ [McpAttributes.COMPONENT_KEY]: `tool:${options.name}`
1071
+ };
1072
+ if (options.owner) {
1073
+ attributes[FrontMcpAttributes.TOOL_OWNER] = options.owner;
1074
+ }
1075
+ if (options.enduserId) {
1076
+ attributes[EnduserAttributes.ID] = options.enduserId;
1077
+ }
1078
+ if (options.enduserScope) {
1079
+ attributes[EnduserAttributes.SCOPE] = options.enduserScope;
1080
+ }
1081
+ return startSpan(tracer, {
1082
+ name: `tool ${options.name}`,
1083
+ kind: import_api5.SpanKind.INTERNAL,
1084
+ attributes,
1085
+ parentContext: options.parentContext
1086
+ });
1087
+ }
1088
+
1089
+ // libs/observability/src/otel/spans/resource.span.ts
1090
+ var import_api6 = require("@opentelemetry/api");
1091
+ function startResourceSpan(tracer, options) {
1092
+ const attributes = {
1093
+ [FrontMcpAttributes.RESOURCE_URI]: options.uri,
1094
+ [McpAttributes.RESOURCE_URI]: options.uri,
1095
+ [McpAttributes.COMPONENT_TYPE]: "resource",
1096
+ [McpAttributes.COMPONENT_KEY]: `resource:${options.uri}`
1097
+ };
1098
+ if (options.name) {
1099
+ attributes[FrontMcpAttributes.RESOURCE_NAME] = options.name;
1100
+ }
1101
+ return startSpan(tracer, {
1102
+ name: `resource ${options.uri}`,
1103
+ kind: import_api6.SpanKind.INTERNAL,
1104
+ attributes,
1105
+ parentContext: options.parentContext
1106
+ });
1107
+ }
1108
+
1109
+ // libs/observability/src/otel/spans/prompt.span.ts
1110
+ var import_api7 = require("@opentelemetry/api");
1111
+ function startPromptSpan(tracer, options) {
1112
+ return startSpan(tracer, {
1113
+ name: `prompt ${options.name}`,
1114
+ kind: import_api7.SpanKind.INTERNAL,
1115
+ attributes: {
1116
+ [FrontMcpAttributes.PROMPT_NAME]: options.name,
1117
+ [McpAttributes.COMPONENT_TYPE]: "prompt",
1118
+ [McpAttributes.COMPONENT_KEY]: `prompt:${options.name}`
1119
+ },
1120
+ parentContext: options.parentContext
1121
+ });
1122
+ }
1123
+
1124
+ // libs/observability/src/otel/spans/transport.span.ts
1125
+ var import_api8 = require("@opentelemetry/api");
1126
+ function startTransportSpan(tracer, options) {
1127
+ const attributes = {
1128
+ [FrontMcpAttributes.TRANSPORT_TYPE]: options.type
1129
+ };
1130
+ if (options.sessionIdHash) {
1131
+ attributes[FrontMcpAttributes.SESSION_ID_HASH] = options.sessionIdHash;
1132
+ }
1133
+ if (options.sessionCreated !== void 0) {
1134
+ attributes[FrontMcpAttributes.SESSION_CREATED] = options.sessionCreated;
1135
+ }
1136
+ return startSpan(tracer, {
1137
+ name: `transport ${options.type}`,
1138
+ kind: import_api8.SpanKind.INTERNAL,
1139
+ attributes,
1140
+ parentContext: options.parentContext
1141
+ });
1142
+ }
1143
+ function setTransportRequestType(span, requestType) {
1144
+ span.setAttribute(FrontMcpAttributes.TRANSPORT_REQUEST_TYPE, requestType);
1145
+ }
1146
+
1147
+ // libs/observability/src/otel/spans/auth.span.ts
1148
+ var import_api9 = require("@opentelemetry/api");
1149
+ function startAuthSpan(tracer, options) {
1150
+ return startSpan(tracer, {
1151
+ name: `auth ${options.flowName}`,
1152
+ kind: import_api9.SpanKind.INTERNAL,
1153
+ attributes: {
1154
+ [FrontMcpAttributes.FLOW_NAME]: options.flowName
1155
+ },
1156
+ parentContext: options.parentContext
1157
+ });
1158
+ }
1159
+ function setAuthMode(span, mode) {
1160
+ span.setAttribute(FrontMcpAttributes.AUTH_MODE, mode);
1161
+ }
1162
+ function setAuthResult(span, result) {
1163
+ span.setAttribute(FrontMcpAttributes.AUTH_RESULT, result);
1164
+ }
1165
+
1166
+ // libs/observability/src/otel/spans/fetch.span.ts
1167
+ var import_api10 = require("@opentelemetry/api");
1168
+ function startFetchSpan(tracer, options) {
1169
+ return startSpan(tracer, {
1170
+ name: options.method.toUpperCase(),
1171
+ kind: import_api10.SpanKind.CLIENT,
1172
+ attributes: {
1173
+ [HttpAttributes.METHOD]: options.method.toUpperCase(),
1174
+ [HttpAttributes.URL_FULL]: options.url
1175
+ },
1176
+ parentContext: options.parentContext
1177
+ });
1178
+ }
1179
+ function setFetchResponseStatus(span, statusCode) {
1180
+ span.setAttribute(HttpAttributes.STATUS_CODE, statusCode);
1181
+ }
1182
+
1183
+ // libs/observability/src/otel/spans/startup.span.ts
1184
+ var import_api11 = require("@opentelemetry/api");
1185
+ function emitStartupReport(tracer, data) {
1186
+ const attributes = {
1187
+ [FrontMcpAttributes.STARTUP_TOOLS_COUNT]: data.toolsCount,
1188
+ [FrontMcpAttributes.STARTUP_RESOURCES_COUNT]: data.resourcesCount,
1189
+ [FrontMcpAttributes.STARTUP_PROMPTS_COUNT]: data.promptsCount,
1190
+ [FrontMcpAttributes.STARTUP_PLUGINS_COUNT]: data.pluginsCount,
1191
+ [FrontMcpAttributes.STARTUP_DURATION_MS]: data.durationMs
1192
+ };
1193
+ if (data.scopeId) {
1194
+ attributes[FrontMcpAttributes.SCOPE_ID] = data.scopeId;
1195
+ }
1196
+ const { span } = startSpan(tracer, {
1197
+ name: "frontmcp.startup",
1198
+ kind: import_api11.SpanKind.INTERNAL,
1199
+ attributes
1200
+ });
1201
+ endSpanOk(span);
1202
+ }
1203
+
1204
+ // libs/observability/src/plugin/observability.hooks.ts
1205
+ var SPAN_KEY = /* @__PURE__ */ Symbol.for("frontmcp:otel:span");
1206
+ var SPAN_CTX_KEY = /* @__PURE__ */ Symbol.for("frontmcp:otel:span-ctx");
1207
+ var EXEC_SPAN_KEY = /* @__PURE__ */ Symbol.for("frontmcp:otel:exec-span");
1208
+ var ACTIVE_SPAN_KEY = /* @__PURE__ */ Symbol.for("frontmcp:otel:active-span");
1209
+ var ACTIVE_OTEL_CTX_KEY = /* @__PURE__ */ Symbol.for("frontmcp:otel:active-otel-ctx");
1210
+ var STAGE_TS_KEY = /* @__PURE__ */ Symbol.for("frontmcp:otel:stage-ts");
1211
+ function sessionTracingId(sessionId) {
1212
+ return (0, import_utils.sha256Hex)(sessionId).slice(0, 16);
1213
+ }
1214
+ function getTracer() {
1215
+ return import_api12.trace.getTracer("@frontmcp/observability");
1216
+ }
1217
+ function extractContext(flowCtx) {
1218
+ try {
1219
+ const ctx = flowCtx.get?.(/* @__PURE__ */ Symbol.for("frontmcp:CONTEXT"));
1220
+ if (ctx) return ctx;
1221
+ } catch {
1222
+ }
1223
+ return flowCtx.state?.ctx ?? flowCtx.state?.frontmcpContext;
1224
+ }
1225
+ function storeActiveSpan(flowCtx, span, otelCtx) {
1226
+ try {
1227
+ const ctx = flowCtx.get?.(/* @__PURE__ */ Symbol.for("frontmcp:CONTEXT"));
1228
+ if (ctx && typeof ctx.set === "function") {
1229
+ ctx.set(ACTIVE_SPAN_KEY, span);
1230
+ ctx.set(ACTIVE_OTEL_CTX_KEY, otelCtx);
1231
+ }
1232
+ } catch {
1233
+ }
1234
+ }
1235
+ function clearActiveSpan(flowCtx) {
1236
+ try {
1237
+ const ctx = flowCtx.get?.(/* @__PURE__ */ Symbol.for("frontmcp:CONTEXT"));
1238
+ if (ctx && typeof ctx.delete === "function") {
1239
+ ctx.delete(ACTIVE_SPAN_KEY);
1240
+ ctx.delete(ACTIVE_OTEL_CTX_KEY);
1241
+ }
1242
+ } catch {
1243
+ }
1244
+ }
1245
+ function recordStageEvent(span, stageName, state) {
1246
+ const now = Date.now();
1247
+ const prev = state[STAGE_TS_KEY];
1248
+ const attributes = {};
1249
+ if (prev) {
1250
+ attributes["duration_ms"] = now - prev;
1251
+ }
1252
+ state[STAGE_TS_KEY] = now;
1253
+ span.addEvent(`stage.${stageName}`, attributes);
1254
+ }
1255
+ function onHttpWillTrace(options, flowCtx) {
1256
+ if (options.httpSpans === false) return;
1257
+ const ctx = extractContext(flowCtx);
1258
+ if (!ctx) return;
1259
+ const tracer = getTracer();
1260
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1261
+ const sessionHash = sessionTracingId(ctx.sessionId);
1262
+ const { span, context: spanCtx } = startHttpServerSpan(tracer, {
1263
+ method: ctx.metadata?.customHeaders?.["x-http-method"] ?? "POST",
1264
+ path: ctx.metadata?.customHeaders?.["x-url-path"] ?? "/",
1265
+ scopeId: ctx.scopeId,
1266
+ requestId: ctx.requestId,
1267
+ parentContext: parentOTelCtx
1268
+ });
1269
+ span.setAttribute(McpAttributes.SESSION_ID, sessionHash);
1270
+ span.setAttribute(FrontMcpAttributes.SESSION_ID_HASH, sessionHash);
1271
+ flowCtx.state[SPAN_KEY] = span;
1272
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1273
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1274
+ recordStageEvent(span, "traceRequest", flowCtx.state);
1275
+ }
1276
+ function onHttpWillAcquireQuota(flowCtx) {
1277
+ const span = flowCtx.state?.[SPAN_KEY];
1278
+ if (span) recordStageEvent(span, "acquireQuota", flowCtx.state);
1279
+ }
1280
+ function onHttpDidAcquireQuota(flowCtx) {
1281
+ const span = flowCtx.state?.[SPAN_KEY];
1282
+ if (span) recordStageEvent(span, "acquireQuota.done", flowCtx.state);
1283
+ }
1284
+ function onHttpWillCheckAuth(flowCtx) {
1285
+ const span = flowCtx.state?.[SPAN_KEY];
1286
+ if (span) recordStageEvent(span, "checkAuthorization", flowCtx.state);
1287
+ }
1288
+ function onHttpDidCheckAuth(flowCtx) {
1289
+ const span = flowCtx.state?.[SPAN_KEY];
1290
+ if (span) recordStageEvent(span, "checkAuthorization.done", flowCtx.state);
1291
+ }
1292
+ function onHttpWillRoute(flowCtx) {
1293
+ const span = flowCtx.state?.[SPAN_KEY];
1294
+ if (span) recordStageEvent(span, "router", flowCtx.state);
1295
+ }
1296
+ function onHttpDidRoute(flowCtx) {
1297
+ const span = flowCtx.state?.[SPAN_KEY];
1298
+ if (span) recordStageEvent(span, "router.done", flowCtx.state);
1299
+ }
1300
+ function onHttpDidFinalize(flowCtx) {
1301
+ const span = flowCtx.state?.[SPAN_KEY];
1302
+ if (!span) return;
1303
+ recordStageEvent(span, "finalize", flowCtx.state);
1304
+ const statusCode = flowCtx.state?.statusCode ?? 200;
1305
+ setHttpResponseStatus(span, statusCode);
1306
+ if (statusCode >= 400) {
1307
+ endSpanError(span, `HTTP ${statusCode}`);
1308
+ } else {
1309
+ endSpanOk(span);
1310
+ }
1311
+ }
1312
+ function onToolWillParse(options, flowCtx) {
1313
+ if (options.executionSpans === false) return;
1314
+ const ctx = extractContext(flowCtx);
1315
+ if (!ctx) return;
1316
+ const tracer = getTracer();
1317
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1318
+ const sessionHash = sessionTracingId(ctx.sessionId);
1319
+ const { span, context: spanCtx } = startRpcSpan(tracer, {
1320
+ method: "tools/call",
1321
+ scopeId: ctx.scopeId,
1322
+ sessionIdHash: sessionHash,
1323
+ parentContext: parentOTelCtx
1324
+ });
1325
+ flowCtx.state[SPAN_KEY] = span;
1326
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1327
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1328
+ recordStageEvent(span, "parseInput", flowCtx.state);
1329
+ }
1330
+ function onToolWillFindTool(flowCtx) {
1331
+ const span = flowCtx.state?.[SPAN_KEY];
1332
+ if (span) recordStageEvent(span, "findTool", flowCtx.state);
1333
+ }
1334
+ function onToolWillCheckAuth(flowCtx) {
1335
+ const span = flowCtx.state?.[SPAN_KEY];
1336
+ if (span) recordStageEvent(span, "checkToolAuthorization", flowCtx.state);
1337
+ }
1338
+ function onToolWillCreateContext(flowCtx) {
1339
+ const span = flowCtx.state?.[SPAN_KEY];
1340
+ if (span) recordStageEvent(span, "createToolCallContext", flowCtx.state);
1341
+ }
1342
+ function onToolWillValidateInput(flowCtx) {
1343
+ const span = flowCtx.state?.[SPAN_KEY];
1344
+ if (span) recordStageEvent(span, "validateInput", flowCtx.state);
1345
+ }
1346
+ function onToolWillExecute(options, flowCtx) {
1347
+ if (options.executionSpans === false) return;
1348
+ const ctx = extractContext(flowCtx);
1349
+ const rpcCtx = flowCtx.state?.[SPAN_CTX_KEY];
1350
+ const tracer = getTracer();
1351
+ const toolName = flowCtx.state?.input?.name ?? "unknown";
1352
+ const toolOwner = flowCtx.state?._toolOwnerId;
1353
+ const enduser = ctx?.authInfo;
1354
+ const { span: toolSpan, context: toolOTelCtx } = startToolSpan(tracer, {
1355
+ name: toolName,
1356
+ owner: toolOwner,
1357
+ enduserId: enduser?.clientId ?? enduser?.extra?.sub,
1358
+ enduserScope: Array.isArray(enduser?.scopes) ? enduser.scopes.join(" ") : void 0,
1359
+ parentContext: rpcCtx
1360
+ });
1361
+ flowCtx.state[EXEC_SPAN_KEY] = toolSpan;
1362
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1363
+ recordStageEvent(toolSpan, "execute.start", flowCtx.state);
1364
+ storeActiveSpan(flowCtx, toolSpan, toolOTelCtx);
1365
+ }
1366
+ function onToolDidExecute(options, flowCtx) {
1367
+ const toolSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1368
+ if (!toolSpan) return;
1369
+ recordStageEvent(toolSpan, "execute.done", flowCtx.state);
1370
+ endSpanOk(toolSpan);
1371
+ flowCtx.state[EXEC_SPAN_KEY] = void 0;
1372
+ clearActiveSpan(flowCtx);
1373
+ }
1374
+ function onToolWillValidateOutput(flowCtx) {
1375
+ const span = flowCtx.state?.[SPAN_KEY];
1376
+ if (span) recordStageEvent(span, "validateOutput", flowCtx.state);
1377
+ }
1378
+ function onToolWillApplyUI(flowCtx) {
1379
+ const span = flowCtx.state?.[SPAN_KEY];
1380
+ if (span) recordStageEvent(span, "applyUI", flowCtx.state);
1381
+ }
1382
+ function onToolDidFinalize(flowCtx) {
1383
+ const rpcSpan = flowCtx.state?.[SPAN_KEY];
1384
+ const toolSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1385
+ const error = flowCtx.state?.error;
1386
+ if (error) {
1387
+ if (toolSpan) endSpanError(toolSpan, error instanceof Error ? error : String(error));
1388
+ if (rpcSpan) endSpanError(rpcSpan, error instanceof Error ? error : String(error));
1389
+ } else if (rpcSpan) {
1390
+ recordStageEvent(rpcSpan, "finalize", flowCtx.state);
1391
+ endSpanOk(rpcSpan);
1392
+ }
1393
+ }
1394
+ function onResourceWillParse(options, flowCtx) {
1395
+ if (options.executionSpans === false) return;
1396
+ const ctx = extractContext(flowCtx);
1397
+ if (!ctx) return;
1398
+ const tracer = getTracer();
1399
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1400
+ const sessionHash = sessionTracingId(ctx.sessionId);
1401
+ const { span, context: spanCtx } = startRpcSpan(tracer, {
1402
+ method: "resources/read",
1403
+ scopeId: ctx.scopeId,
1404
+ sessionIdHash: sessionHash,
1405
+ parentContext: parentOTelCtx
1406
+ });
1407
+ flowCtx.state[SPAN_KEY] = span;
1408
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1409
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1410
+ recordStageEvent(span, "parseInput", flowCtx.state);
1411
+ }
1412
+ function onResourceWillFind(flowCtx) {
1413
+ const span = flowCtx.state?.[SPAN_KEY];
1414
+ if (span) recordStageEvent(span, "findResource", flowCtx.state);
1415
+ }
1416
+ function onResourceWillExecute(options, flowCtx) {
1417
+ if (options.executionSpans === false) return;
1418
+ const rpcCtx = flowCtx.state?.[SPAN_CTX_KEY];
1419
+ const tracer = getTracer();
1420
+ const uri = flowCtx.state?.input?.uri ?? "unknown";
1421
+ const { span: resSpan, context: resOTelCtx } = startResourceSpan(tracer, { uri, parentContext: rpcCtx });
1422
+ flowCtx.state[EXEC_SPAN_KEY] = resSpan;
1423
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1424
+ recordStageEvent(resSpan, "execute.start", flowCtx.state);
1425
+ storeActiveSpan(flowCtx, resSpan, resOTelCtx);
1426
+ }
1427
+ function onResourceDidExecute(flowCtx) {
1428
+ const resSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1429
+ if (!resSpan) return;
1430
+ recordStageEvent(resSpan, "execute.done", flowCtx.state);
1431
+ endSpanOk(resSpan);
1432
+ flowCtx.state[EXEC_SPAN_KEY] = void 0;
1433
+ clearActiveSpan(flowCtx);
1434
+ }
1435
+ function onResourceDidFinalize(flowCtx) {
1436
+ const rpcSpan = flowCtx.state?.[SPAN_KEY];
1437
+ const resSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1438
+ const error = flowCtx.state?.error;
1439
+ if (error) {
1440
+ if (resSpan) endSpanError(resSpan, error instanceof Error ? error : String(error));
1441
+ if (rpcSpan) endSpanError(rpcSpan, error instanceof Error ? error : String(error));
1442
+ } else if (rpcSpan) {
1443
+ recordStageEvent(rpcSpan, "finalize", flowCtx.state);
1444
+ endSpanOk(rpcSpan);
1445
+ }
1446
+ }
1447
+ function onPromptWillParse(options, flowCtx) {
1448
+ if (options.executionSpans === false) return;
1449
+ const ctx = extractContext(flowCtx);
1450
+ if (!ctx) return;
1451
+ const tracer = getTracer();
1452
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1453
+ const sessionHash = sessionTracingId(ctx.sessionId);
1454
+ const { span, context: spanCtx } = startRpcSpan(tracer, {
1455
+ method: "prompts/get",
1456
+ scopeId: ctx.scopeId,
1457
+ sessionIdHash: sessionHash,
1458
+ parentContext: parentOTelCtx
1459
+ });
1460
+ flowCtx.state[SPAN_KEY] = span;
1461
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1462
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1463
+ recordStageEvent(span, "parseInput", flowCtx.state);
1464
+ }
1465
+ function onPromptWillFind(flowCtx) {
1466
+ const span = flowCtx.state?.[SPAN_KEY];
1467
+ if (span) recordStageEvent(span, "findPrompt", flowCtx.state);
1468
+ }
1469
+ function onPromptWillExecute(options, flowCtx) {
1470
+ if (options.executionSpans === false) return;
1471
+ const rpcCtx = flowCtx.state?.[SPAN_CTX_KEY];
1472
+ const tracer = getTracer();
1473
+ const promptName = flowCtx.state?.input?.name ?? "unknown";
1474
+ const { span: promptSpan, context: promptOTelCtx } = startPromptSpan(tracer, {
1475
+ name: promptName,
1476
+ parentContext: rpcCtx
1477
+ });
1478
+ flowCtx.state[EXEC_SPAN_KEY] = promptSpan;
1479
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1480
+ recordStageEvent(promptSpan, "execute.start", flowCtx.state);
1481
+ storeActiveSpan(flowCtx, promptSpan, promptOTelCtx);
1482
+ }
1483
+ function onPromptDidExecute(flowCtx) {
1484
+ const promptSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1485
+ if (!promptSpan) return;
1486
+ recordStageEvent(promptSpan, "execute.done", flowCtx.state);
1487
+ endSpanOk(promptSpan);
1488
+ flowCtx.state[EXEC_SPAN_KEY] = void 0;
1489
+ clearActiveSpan(flowCtx);
1490
+ }
1491
+ function onPromptDidFinalize(flowCtx) {
1492
+ const rpcSpan = flowCtx.state?.[SPAN_KEY];
1493
+ const promptSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1494
+ const error = flowCtx.state?.error;
1495
+ if (error) {
1496
+ if (promptSpan) endSpanError(promptSpan, error instanceof Error ? error : String(error));
1497
+ if (rpcSpan) endSpanError(rpcSpan, error instanceof Error ? error : String(error));
1498
+ } else if (rpcSpan) {
1499
+ recordStageEvent(rpcSpan, "finalize", flowCtx.state);
1500
+ endSpanOk(rpcSpan);
1501
+ }
1502
+ }
1503
+ function onAgentWillParse(options, flowCtx) {
1504
+ if (options.executionSpans === false) return;
1505
+ const ctx = extractContext(flowCtx);
1506
+ if (!ctx) return;
1507
+ const tracer = getTracer();
1508
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1509
+ const sessionHash = sessionTracingId(ctx.sessionId);
1510
+ const { span, context: spanCtx } = startRpcSpan(tracer, {
1511
+ method: "agents/call",
1512
+ scopeId: ctx.scopeId,
1513
+ sessionIdHash: sessionHash,
1514
+ parentContext: parentOTelCtx
1515
+ });
1516
+ flowCtx.state[SPAN_KEY] = span;
1517
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1518
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1519
+ recordStageEvent(span, "parseInput", flowCtx.state);
1520
+ }
1521
+ function onAgentWillFind(flowCtx) {
1522
+ const span = flowCtx.state?.[SPAN_KEY];
1523
+ if (span) recordStageEvent(span, "findAgent", flowCtx.state);
1524
+ }
1525
+ function onAgentWillExecute(options, flowCtx) {
1526
+ if (options.executionSpans === false) return;
1527
+ const rpcCtx = flowCtx.state?.[SPAN_CTX_KEY];
1528
+ const tracer = getTracer();
1529
+ const agentName = flowCtx.state?.input?.name ?? "unknown";
1530
+ const { span: agentSpan } = startSpan(tracer, {
1531
+ name: `agent ${agentName}`,
1532
+ kind: import_api12.SpanKind.INTERNAL,
1533
+ attributes: {
1534
+ [FrontMcpAttributes.FLOW_NAME]: "agents:call-agent",
1535
+ [McpAttributes.COMPONENT_TYPE]: "agent",
1536
+ [McpAttributes.COMPONENT_KEY]: `agent:${agentName}`
1537
+ },
1538
+ parentContext: rpcCtx
1539
+ });
1540
+ const agentOTelCtx = import_api12.trace.setSpan(rpcCtx ?? import_api12.context.active(), agentSpan);
1541
+ flowCtx.state[EXEC_SPAN_KEY] = agentSpan;
1542
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1543
+ recordStageEvent(agentSpan, "execute.start", flowCtx.state);
1544
+ storeActiveSpan(flowCtx, agentSpan, agentOTelCtx);
1545
+ }
1546
+ function onAgentDidExecute(flowCtx) {
1547
+ const agentSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1548
+ if (!agentSpan) return;
1549
+ recordStageEvent(agentSpan, "execute.done", flowCtx.state);
1550
+ endSpanOk(agentSpan);
1551
+ flowCtx.state[EXEC_SPAN_KEY] = void 0;
1552
+ clearActiveSpan(flowCtx);
1553
+ }
1554
+ function onAgentDidFinalize(flowCtx) {
1555
+ const rpcSpan = flowCtx.state?.[SPAN_KEY];
1556
+ const agentSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1557
+ const error = flowCtx.state?.error;
1558
+ if (error) {
1559
+ if (agentSpan) endSpanError(agentSpan, error instanceof Error ? error : String(error));
1560
+ if (rpcSpan) endSpanError(rpcSpan, error instanceof Error ? error : String(error));
1561
+ } else if (rpcSpan) {
1562
+ recordStageEvent(rpcSpan, "finalize", flowCtx.state);
1563
+ endSpanOk(rpcSpan);
1564
+ }
1565
+ }
1566
+ function onGenericFlowWillStart(flowName, options, flowCtx) {
1567
+ if (options.executionSpans === false) return;
1568
+ const ctx = extractContext(flowCtx);
1569
+ if (!ctx) return;
1570
+ const tracer = getTracer();
1571
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1572
+ const sessionHash = sessionTracingId(ctx.sessionId);
1573
+ const { span, context: spanCtx } = startSpan(tracer, {
1574
+ name: flowName,
1575
+ kind: import_api12.SpanKind.INTERNAL,
1576
+ attributes: {
1577
+ [FrontMcpAttributes.FLOW_NAME]: flowName,
1578
+ [McpAttributes.SESSION_ID]: sessionHash,
1579
+ [FrontMcpAttributes.SESSION_ID_HASH]: sessionHash,
1580
+ [FrontMcpAttributes.SCOPE_ID]: ctx.scopeId,
1581
+ [FrontMcpAttributes.REQUEST_ID]: ctx.requestId
1582
+ },
1583
+ parentContext: parentOTelCtx
1584
+ });
1585
+ flowCtx.state[SPAN_KEY] = span;
1586
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1587
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1588
+ }
1589
+ function onGenericFlowStage(stageName, flowCtx) {
1590
+ const span = flowCtx.state?.[SPAN_KEY];
1591
+ if (span) recordStageEvent(span, stageName, flowCtx.state);
1592
+ }
1593
+ function onGenericFlowDidFinalize(flowCtx) {
1594
+ const span = flowCtx.state?.[SPAN_KEY];
1595
+ if (!span) return;
1596
+ const error = flowCtx.state?.error;
1597
+ if (error) {
1598
+ endSpanError(span, error instanceof Error ? error : String(error));
1599
+ } else {
1600
+ endSpanOk(span);
1601
+ }
1602
+ }
1603
+ function onTransportWillStart(transportType, options, flowCtx) {
1604
+ if (options.transportSpans === false) return;
1605
+ const ctx = extractContext(flowCtx);
1606
+ if (!ctx) return;
1607
+ const tracer = getTracer();
1608
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1609
+ const sessionHash = sessionTracingId(ctx.sessionId);
1610
+ const { span, context: spanCtx } = startTransportSpan(tracer, {
1611
+ type: transportType,
1612
+ sessionIdHash: sessionHash,
1613
+ parentContext: parentOTelCtx
1614
+ });
1615
+ flowCtx.state[SPAN_KEY] = span;
1616
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1617
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1618
+ recordStageEvent(span, "parseInput", flowCtx.state);
1619
+ }
1620
+ function onTransportDidRoute(flowCtx) {
1621
+ const span = flowCtx.state?.[SPAN_KEY];
1622
+ if (!span) return;
1623
+ recordStageEvent(span, "router", flowCtx.state);
1624
+ const requestType = flowCtx.state?.requestType;
1625
+ if (requestType) setTransportRequestType(span, requestType);
1626
+ }
1627
+ function onTransportStage(stageName, flowCtx) {
1628
+ const span = flowCtx.state?.[SPAN_KEY];
1629
+ if (span) recordStageEvent(span, stageName, flowCtx.state);
1630
+ }
1631
+ function onTransportDidFinalize(flowCtx) {
1632
+ const span = flowCtx.state?.[SPAN_KEY];
1633
+ if (!span) return;
1634
+ recordStageEvent(span, "cleanup", flowCtx.state);
1635
+ const error = flowCtx.state?.error;
1636
+ if (error) {
1637
+ endSpanError(span, error instanceof Error ? error : String(error));
1638
+ } else {
1639
+ endSpanOk(span);
1640
+ }
1641
+ }
1642
+ function onAuthWillStart(flowName, options, flowCtx) {
1643
+ if (options.authSpans === false) return;
1644
+ const ctx = extractContext(flowCtx);
1645
+ if (!ctx) return;
1646
+ const tracer = getTracer();
1647
+ const parentOTelCtx = createOTelContextFromTrace(ctx.traceContext);
1648
+ const { span, context: spanCtx } = startAuthSpan(tracer, {
1649
+ flowName,
1650
+ parentContext: parentOTelCtx
1651
+ });
1652
+ flowCtx.state[SPAN_KEY] = span;
1653
+ flowCtx.state[SPAN_CTX_KEY] = spanCtx;
1654
+ flowCtx.state[STAGE_TS_KEY] = Date.now();
1655
+ recordStageEvent(span, "parseInput", flowCtx.state);
1656
+ }
1657
+ function onAuthDidDetermineMode(flowCtx) {
1658
+ const span = flowCtx.state?.[SPAN_KEY];
1659
+ if (!span) return;
1660
+ recordStageEvent(span, "determineAuthMode", flowCtx.state);
1661
+ const mode = flowCtx.state?.authMode;
1662
+ if (mode) setAuthMode(span, mode);
1663
+ }
1664
+ function onAuthStage(stageName, flowCtx) {
1665
+ const span = flowCtx.state?.[SPAN_KEY];
1666
+ if (span) recordStageEvent(span, stageName, flowCtx.state);
1667
+ }
1668
+ function onAuthDidFinalize(flowCtx) {
1669
+ const span = flowCtx.state?.[SPAN_KEY];
1670
+ if (!span) return;
1671
+ const error = flowCtx.state?.error;
1672
+ if (error) {
1673
+ setAuthResult(span, "unauthorized");
1674
+ endSpanError(span, error instanceof Error ? error : String(error));
1675
+ } else {
1676
+ setAuthResult(span, "authorized");
1677
+ endSpanOk(span);
1678
+ }
1679
+ }
1680
+ function wrapContextFetch(options, flowCtx) {
1681
+ if (options.fetchSpans === false) return;
1682
+ const toolCtx = flowCtx.state?.toolContext ?? flowCtx.state?.toolCallContext;
1683
+ if (!toolCtx || typeof toolCtx.fetch !== "function") return;
1684
+ const originalFetch = toolCtx.fetch.bind(toolCtx);
1685
+ const parentOTelCtx = flowCtx.state?.[SPAN_CTX_KEY];
1686
+ toolCtx.fetch = async (input, init) => {
1687
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
1688
+ const method = init?.method ?? "GET";
1689
+ const tracer = getTracer();
1690
+ const { span } = startFetchSpan(tracer, { method, url, parentContext: parentOTelCtx });
1691
+ try {
1692
+ const response = await originalFetch(input, init);
1693
+ setFetchResponseStatus(span, response.status);
1694
+ endSpanOk(span);
1695
+ return response;
1696
+ } catch (err) {
1697
+ endSpanError(span, err instanceof Error ? err : String(err));
1698
+ throw err;
1699
+ }
1700
+ };
1701
+ }
1702
+ function onAgentDidExecuteEnrich(flowCtx) {
1703
+ const agentSpan = flowCtx.state?.[EXEC_SPAN_KEY];
1704
+ if (!agentSpan) return;
1705
+ const meta = flowCtx.state?.executionMeta;
1706
+ if (meta) {
1707
+ if (typeof meta.iterations === "number") {
1708
+ agentSpan.setAttribute(FrontMcpAttributes.AGENT_ITERATIONS, meta.iterations);
1709
+ }
1710
+ if (typeof meta.durationMs === "number") {
1711
+ agentSpan.setAttribute(FrontMcpAttributes.AGENT_EXECUTION_DURATION_MS, meta.durationMs);
1712
+ }
1713
+ }
1714
+ }
1715
+ function reportStartup(data) {
1716
+ const tracer = getTracer();
1717
+ emitStartupReport(tracer, data);
1718
+ }
1719
+
1720
+ // libs/observability/src/telemetry/telemetry.accessor.ts
1721
+ var TelemetrySpan = class {
1722
+ constructor(span) {
1723
+ this.span = span;
1724
+ this.hasError = false;
1725
+ }
1726
+ /** Set a string/number/boolean attribute */
1727
+ setAttribute(key, value) {
1728
+ this.span.setAttribute(key, value);
1729
+ return this;
1730
+ }
1731
+ /** Set multiple attributes at once */
1732
+ setAttributes(attrs) {
1733
+ this.span.setAttributes(attrs);
1734
+ return this;
1735
+ }
1736
+ /** Add a named event (with optional attributes) */
1737
+ addEvent(name, attributes) {
1738
+ this.span.addEvent(name, attributes);
1739
+ return this;
1740
+ }
1741
+ /** Record an error on this span */
1742
+ recordError(error) {
1743
+ this.span.recordException(error);
1744
+ this.span.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: error.message });
1745
+ this.hasError = true;
1746
+ return this;
1747
+ }
1748
+ /** End the span (preserves ERROR status if already set) */
1749
+ end() {
1750
+ if (!this.hasError) {
1751
+ this.span.setStatus({ code: import_api13.SpanStatusCode.OK });
1752
+ }
1753
+ this.span.end();
1754
+ }
1755
+ /** End the span with error */
1756
+ endWithError(error) {
1757
+ const msg = typeof error === "string" ? error : error.message;
1758
+ if (error instanceof Error) this.span.recordException(error);
1759
+ this.span.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: msg });
1760
+ this.span.end();
1761
+ }
1762
+ /** Get the underlying OTel span (escape hatch) */
1763
+ get raw() {
1764
+ return this.span;
1765
+ }
1766
+ };
1767
+ var TelemetryAccessor = class {
1768
+ constructor(ctx) {
1769
+ this.ctx = ctx;
1770
+ this.tracer = import_api13.trace.getTracer("@frontmcp/observability");
1771
+ this.fallbackContext = createOTelContextFromTrace(ctx.traceContext);
1772
+ this.sessionHash = sessionTracingId(ctx.sessionId);
1773
+ this.baseAttributes = {
1774
+ [FrontMcpAttributes.REQUEST_ID]: ctx.requestId,
1775
+ [FrontMcpAttributes.SCOPE_ID]: ctx.scopeId,
1776
+ [McpAttributes.SESSION_ID]: this.sessionHash
1777
+ };
1778
+ }
1779
+ /**
1780
+ * Get the active OTel context — prefers the execution span's context
1781
+ * (set by hooks during willExecute), falls back to the request-level trace.
1782
+ */
1783
+ getActiveContext() {
1784
+ const otelCtx = this.ctx.get?.(ACTIVE_OTEL_CTX_KEY);
1785
+ return otelCtx ?? this.fallbackContext;
1786
+ }
1787
+ /**
1788
+ * Get the active execution span (set by auto-instrumentation hooks).
1789
+ * Returns undefined if not inside an instrumented execution stage.
1790
+ */
1791
+ getActiveSpan() {
1792
+ return this.ctx.get?.(ACTIVE_SPAN_KEY);
1793
+ }
1794
+ /**
1795
+ * Start a new child span under the current execution span.
1796
+ *
1797
+ * If called inside a tool's execute(), the span is a child of
1798
+ * the tool execution span. Otherwise falls back to the request trace.
1799
+ *
1800
+ * You MUST call `span.end()` or `span.endWithError()` when done.
1801
+ */
1802
+ startSpan(name, attributes) {
1803
+ const span = this.tracer.startSpan(
1804
+ name,
1805
+ {
1806
+ kind: import_api13.SpanKind.INTERNAL,
1807
+ attributes: { ...this.baseAttributes, ...attributes }
1808
+ },
1809
+ this.getActiveContext()
1810
+ );
1811
+ return new TelemetrySpan(span);
1812
+ }
1813
+ /**
1814
+ * Run a function within a child span. Automatically ended on
1815
+ * success (OK) or error (ERROR + exception recorded).
1816
+ *
1817
+ * @example
1818
+ * ```typescript
1819
+ * const data = await this.telemetry.withSpan('fetch-api', async (span) => {
1820
+ * span.addEvent('request-sent');
1821
+ * const res = await this.fetch(url);
1822
+ * span.setAttribute('status', res.status);
1823
+ * return res.json();
1824
+ * });
1825
+ * ```
1826
+ */
1827
+ async withSpan(name, fn, attributes) {
1828
+ const telemetrySpan = this.startSpan(name, attributes);
1829
+ try {
1830
+ const result = await fn(telemetrySpan);
1831
+ telemetrySpan.end();
1832
+ return result;
1833
+ } catch (err) {
1834
+ telemetrySpan.endWithError(err instanceof Error ? err : String(err));
1835
+ throw err;
1836
+ }
1837
+ }
1838
+ /**
1839
+ * Add an event to the **active flow execution span**.
1840
+ *
1841
+ * If called inside a tool's execute(), the event appears on the
1842
+ * tool execution span. If no active span exists, creates a
1843
+ * lightweight child span carrying the event.
1844
+ *
1845
+ * @param name — event name (e.g., 'validation-complete', 'cache-hit')
1846
+ * @param attributes — optional event attributes
1847
+ */
1848
+ addEvent(name, attributes) {
1849
+ const activeSpan = this.getActiveSpan();
1850
+ if (activeSpan) {
1851
+ activeSpan.addEvent(name, attributes);
1852
+ } else {
1853
+ const span = this.tracer.startSpan(
1854
+ name,
1855
+ { kind: import_api13.SpanKind.INTERNAL, attributes: this.baseAttributes },
1856
+ this.fallbackContext
1857
+ );
1858
+ if (attributes) span.addEvent(name, attributes);
1859
+ span.setStatus({ code: import_api13.SpanStatusCode.OK });
1860
+ span.end();
1861
+ }
1862
+ }
1863
+ /**
1864
+ * Set attributes on the **active flow execution span**.
1865
+ *
1866
+ * If called inside a tool's execute(), attributes are set on the
1867
+ * tool execution span. If no active span exists, this is a no-op.
1868
+ *
1869
+ * @param attrs — key-value attributes
1870
+ */
1871
+ setAttributes(attrs) {
1872
+ const activeSpan = this.getActiveSpan();
1873
+ if (activeSpan) {
1874
+ activeSpan.setAttributes(attrs);
1875
+ }
1876
+ }
1877
+ /**
1878
+ * Get the trace ID of the current request.
1879
+ * Useful for including in external API calls or logs.
1880
+ */
1881
+ get traceId() {
1882
+ return import_api13.trace.getSpan(this.fallbackContext)?.spanContext().traceId ?? "";
1883
+ }
1884
+ /**
1885
+ * Get the session tracing ID (privacy-safe hash).
1886
+ */
1887
+ get sessionId() {
1888
+ return this.sessionHash;
1889
+ }
1890
+ };
1891
+
1892
+ // libs/observability/src/telemetry/telemetry.tokens.ts
1893
+ var TELEMETRY_ACCESSOR = /* @__PURE__ */ Symbol.for("frontmcp:observability:telemetry-accessor");
1894
+
1895
+ // libs/observability/src/plugin/observability.plugin.ts
1896
+ var PromptHook = (0, import_sdk2.FlowHooksOf)("prompts:get-prompt");
1897
+ var ListPromptsHook = (0, import_sdk2.FlowHooksOf)("prompts:list-prompts");
1898
+ var SkillSearchHook = (0, import_sdk2.FlowHooksOf)("skills:search");
1899
+ var SkillLoadHook = (0, import_sdk2.FlowHooksOf)("skills:load");
1900
+ var CompletionHook = (0, import_sdk2.FlowHooksOf)("completion:complete");
1901
+ var LegacySseHook = (0, import_sdk2.FlowHooksOf)("handle:legacy-sse");
1902
+ var StreamableHttpHook = (0, import_sdk2.FlowHooksOf)("handle:streamable-http");
1903
+ var StatelessHttpHook = (0, import_sdk2.FlowHooksOf)("handle:stateless-http");
1904
+ var AuthVerifyHook = (0, import_sdk2.FlowHooksOf)("auth:verify");
1905
+ var SessionVerifyHook = (0, import_sdk2.FlowHooksOf)("session:verify");
1906
+ var OAuthTokenHook = (0, import_sdk2.FlowHooksOf)("oauth:token");
1907
+ var OAuthAuthorizeHook = (0, import_sdk2.FlowHooksOf)("oauth:authorize");
1908
+ var OAuthCallbackHook = (0, import_sdk2.FlowHooksOf)("oauth:callback");
1909
+ var OAuthProviderCallbackHook = (0, import_sdk2.FlowHooksOf)("oauth:provider-callback");
1910
+ var OAuthRegisterHook = (0, import_sdk2.FlowHooksOf)("oauth:register");
1911
+ var ElicitRequestHook = (0, import_sdk2.FlowHooksOf)("elicitation:request");
1912
+ var ElicitResultHook = (0, import_sdk2.FlowHooksOf)("elicitation:result");
1913
+ var SubscribeResourceHook = (0, import_sdk2.FlowHooksOf)("resources:subscribe");
1914
+ var UnsubscribeResourceHook = (0, import_sdk2.FlowHooksOf)("resources:unsubscribe");
1915
+ var SkillsHttpLlmTxtHook = (0, import_sdk2.FlowHooksOf)("skills-http:llm-txt");
1916
+ var SkillsHttpLlmFullTxtHook = (0, import_sdk2.FlowHooksOf)("skills-http:llm-full-txt");
1917
+ var SkillsHttpApiHook = (0, import_sdk2.FlowHooksOf)("skills-http:api");
1918
+ var WellKnownJwksHook = (0, import_sdk2.FlowHooksOf)("well-known.jwks");
1919
+ var WellKnownOAuthServerHook = (0, import_sdk2.FlowHooksOf)("well-known.oauth-authorization-server");
1920
+ var WellKnownPrmHook = (0, import_sdk2.FlowHooksOf)("well-known.prm");
1921
+ var LoggingSetLevelHook = (0, import_sdk2.FlowHooksOf)("logging:set-level");
1922
+ var DEFAULT_TRACING = {
1923
+ httpSpans: true,
1924
+ executionSpans: true,
1925
+ hookSpans: false,
1926
+ fetchSpans: true,
1927
+ flowStageEvents: true,
1928
+ transportSpans: true,
1929
+ authSpans: true,
1930
+ oauthSpans: true,
1931
+ elicitationSpans: true,
1932
+ startupReport: true
1933
+ };
1934
+ var ObservabilityPlugin = class extends import_sdk2.DynamicPlugin {
1935
+ constructor(options = {}) {
1936
+ super();
1937
+ this.options = resolveOptions(options);
1938
+ this.tracingOpts = this.options.tracing !== false ? this.options.tracing : DEFAULT_TRACING;
1939
+ }
1940
+ get tracingEnabled() {
1941
+ return this.options.tracing !== false;
1942
+ }
1943
+ _httpWillTrace(ctx) {
1944
+ if (this.tracingEnabled) onHttpWillTrace(this.tracingOpts, ctx);
1945
+ }
1946
+ _httpWillQuota(ctx) {
1947
+ if (this.tracingEnabled) onHttpWillAcquireQuota(ctx);
1948
+ }
1949
+ _httpDidSemaphore(ctx) {
1950
+ if (this.tracingEnabled) onHttpDidAcquireQuota(ctx);
1951
+ }
1952
+ _httpWillAuth(ctx) {
1953
+ if (this.tracingEnabled) onHttpWillCheckAuth(ctx);
1954
+ }
1955
+ _httpDidAuth(ctx) {
1956
+ if (this.tracingEnabled) onHttpDidCheckAuth(ctx);
1957
+ }
1958
+ _httpWillRoute(ctx) {
1959
+ if (this.tracingEnabled) onHttpWillRoute(ctx);
1960
+ }
1961
+ _httpDidRoute(ctx) {
1962
+ if (this.tracingEnabled) onHttpDidRoute(ctx);
1963
+ }
1964
+ _httpDidFinalize(ctx) {
1965
+ if (this.tracingEnabled) onHttpDidFinalize(ctx);
1966
+ }
1967
+ _toolWillParse(ctx) {
1968
+ if (this.tracingEnabled) onToolWillParse(this.tracingOpts, ctx);
1969
+ }
1970
+ _toolWillFind(ctx) {
1971
+ if (this.tracingEnabled) onToolWillFindTool(ctx);
1972
+ }
1973
+ _toolWillCheckAuth(ctx) {
1974
+ if (this.tracingEnabled) onToolWillCheckAuth(ctx);
1975
+ }
1976
+ _toolWillCreateCtx(ctx) {
1977
+ if (this.tracingEnabled) onToolWillCreateContext(ctx);
1978
+ }
1979
+ _toolWillValidate(ctx) {
1980
+ if (this.tracingEnabled) onToolWillValidateInput(ctx);
1981
+ }
1982
+ _toolWillExecute(ctx) {
1983
+ if (this.tracingEnabled) onToolWillExecute(this.tracingOpts, ctx);
1984
+ }
1985
+ _toolDidExecute(ctx) {
1986
+ if (this.tracingEnabled) onToolDidExecute(this.tracingOpts, ctx);
1987
+ }
1988
+ _toolWillValidateOut(ctx) {
1989
+ if (this.tracingEnabled) onToolWillValidateOutput(ctx);
1990
+ }
1991
+ _toolWillApplyUI(ctx) {
1992
+ if (this.tracingEnabled) onToolWillApplyUI(ctx);
1993
+ }
1994
+ _toolDidFinalize(ctx) {
1995
+ if (this.tracingEnabled) onToolDidFinalize(ctx);
1996
+ }
1997
+ _resourceWillParse(ctx) {
1998
+ if (this.tracingEnabled) onResourceWillParse(this.tracingOpts, ctx);
1999
+ }
2000
+ _resourceWillFind(ctx) {
2001
+ if (this.tracingEnabled) onResourceWillFind(ctx);
2002
+ }
2003
+ _resourceWillExecute(ctx) {
2004
+ if (this.tracingEnabled) onResourceWillExecute(this.tracingOpts, ctx);
2005
+ }
2006
+ _resourceDidExecute(ctx) {
2007
+ if (this.tracingEnabled) onResourceDidExecute(ctx);
2008
+ }
2009
+ _resourceDidFinalize(ctx) {
2010
+ if (this.tracingEnabled) onResourceDidFinalize(ctx);
2011
+ }
2012
+ _promptWillParse(ctx) {
2013
+ if (this.tracingEnabled) onPromptWillParse(this.tracingOpts, ctx);
2014
+ }
2015
+ _promptWillFind(ctx) {
2016
+ if (this.tracingEnabled) onPromptWillFind(ctx);
2017
+ }
2018
+ _promptWillExecute(ctx) {
2019
+ if (this.tracingEnabled) onPromptWillExecute(this.tracingOpts, ctx);
2020
+ }
2021
+ _promptDidExecute(ctx) {
2022
+ if (this.tracingEnabled) onPromptDidExecute(ctx);
2023
+ }
2024
+ _promptDidFinalize(ctx) {
2025
+ if (this.tracingEnabled) onPromptDidFinalize(ctx);
2026
+ }
2027
+ _agentWillParse(ctx) {
2028
+ if (this.tracingEnabled) onAgentWillParse(this.tracingOpts, ctx);
2029
+ }
2030
+ _agentWillFind(ctx) {
2031
+ if (this.tracingEnabled) onAgentWillFind(ctx);
2032
+ }
2033
+ _agentWillExecute(ctx) {
2034
+ if (this.tracingEnabled) onAgentWillExecute(this.tracingOpts, ctx);
2035
+ }
2036
+ _agentDidExecute(ctx) {
2037
+ if (this.tracingEnabled) onAgentDidExecute(ctx);
2038
+ }
2039
+ _agentDidFinalize(ctx) {
2040
+ if (this.tracingEnabled) onAgentDidFinalize(ctx);
2041
+ }
2042
+ _listToolsWill(ctx) {
2043
+ if (this.tracingEnabled) onGenericFlowWillStart("tools/list", this.tracingOpts, ctx);
2044
+ }
2045
+ _listToolsDidFind(ctx) {
2046
+ if (this.tracingEnabled) onGenericFlowStage("findTools", ctx);
2047
+ }
2048
+ _listToolsDone(ctx) {
2049
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2050
+ }
2051
+ _listResourcesWill(ctx) {
2052
+ if (this.tracingEnabled) onGenericFlowWillStart("resources/list", this.tracingOpts, ctx);
2053
+ }
2054
+ _listResourcesDone(ctx) {
2055
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2056
+ }
2057
+ _listTemplatesWill(ctx) {
2058
+ if (this.tracingEnabled) onGenericFlowWillStart("resources/listTemplates", this.tracingOpts, ctx);
2059
+ }
2060
+ _listTemplatesDone(ctx) {
2061
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2062
+ }
2063
+ _listPromptsWill(ctx) {
2064
+ if (this.tracingEnabled) onGenericFlowWillStart("prompts/list", this.tracingOpts, ctx);
2065
+ }
2066
+ _listPromptsDone(ctx) {
2067
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2068
+ }
2069
+ _skillSearchWill(ctx) {
2070
+ if (this.tracingEnabled) onGenericFlowWillStart("skills/search", this.tracingOpts, ctx);
2071
+ }
2072
+ _skillSearchDone(ctx) {
2073
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2074
+ }
2075
+ _skillLoadWill(ctx) {
2076
+ if (this.tracingEnabled) onGenericFlowWillStart("skills/load", this.tracingOpts, ctx);
2077
+ }
2078
+ _skillLoadStage(ctx) {
2079
+ if (this.tracingEnabled) onGenericFlowStage("loadSkills", ctx);
2080
+ }
2081
+ _skillLoadDone(ctx) {
2082
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2083
+ }
2084
+ _completionWill(ctx) {
2085
+ if (this.tracingEnabled) onGenericFlowWillStart("completion/complete", this.tracingOpts, ctx);
2086
+ }
2087
+ _completionDone(ctx) {
2088
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2089
+ }
2090
+ _sseWillParse(ctx) {
2091
+ if (this.tracingEnabled) onTransportWillStart("legacy-sse", this.tracingOpts, ctx);
2092
+ }
2093
+ _sseDidRoute(ctx) {
2094
+ if (this.tracingEnabled) onTransportDidRoute(ctx);
2095
+ }
2096
+ _sseDidInit(ctx) {
2097
+ if (this.tracingEnabled) onTransportStage("onInitialize", ctx);
2098
+ }
2099
+ _sseDidMsg(ctx) {
2100
+ if (this.tracingEnabled) onTransportStage("onMessage", ctx);
2101
+ }
2102
+ _sseDidElicit(ctx) {
2103
+ if (this.tracingEnabled) onTransportStage("onElicitResult", ctx);
2104
+ }
2105
+ _sseDidCleanup(ctx) {
2106
+ if (this.tracingEnabled) onTransportDidFinalize(ctx);
2107
+ }
2108
+ _shttpWillParse(ctx) {
2109
+ if (this.tracingEnabled) onTransportWillStart("streamable-http", this.tracingOpts, ctx);
2110
+ }
2111
+ _shttpDidRoute(ctx) {
2112
+ if (this.tracingEnabled) onTransportDidRoute(ctx);
2113
+ }
2114
+ _shttpDidInit(ctx) {
2115
+ if (this.tracingEnabled) onTransportStage("onInitialize", ctx);
2116
+ }
2117
+ _shttpDidMsg(ctx) {
2118
+ if (this.tracingEnabled) onTransportStage("onMessage", ctx);
2119
+ }
2120
+ _shttpDidElicit(ctx) {
2121
+ if (this.tracingEnabled) onTransportStage("onElicitResult", ctx);
2122
+ }
2123
+ _shttpDidSse(ctx) {
2124
+ if (this.tracingEnabled) onTransportStage("onSseListener", ctx);
2125
+ }
2126
+ _shttpDidExtApps(ctx) {
2127
+ if (this.tracingEnabled) onTransportStage("onExtApps", ctx);
2128
+ }
2129
+ _shttpDidCleanup(ctx) {
2130
+ if (this.tracingEnabled) onTransportDidFinalize(ctx);
2131
+ }
2132
+ _slhttpWillParse(ctx) {
2133
+ if (this.tracingEnabled) onTransportWillStart("stateless-http", this.tracingOpts, ctx);
2134
+ }
2135
+ _slhttpDidHandle(ctx) {
2136
+ if (this.tracingEnabled) onTransportStage("handleRequest", ctx);
2137
+ }
2138
+ _slhttpDidCleanup(ctx) {
2139
+ if (this.tracingEnabled) onTransportDidFinalize(ctx);
2140
+ }
2141
+ _authVerifyWill(ctx) {
2142
+ if (this.tracingEnabled) onAuthWillStart("auth:verify", this.tracingOpts, ctx);
2143
+ }
2144
+ _authVerifyDidMode(ctx) {
2145
+ if (this.tracingEnabled) onAuthDidDetermineMode(ctx);
2146
+ }
2147
+ _authVerifyDidToken(ctx) {
2148
+ if (this.tracingEnabled) onAuthStage("verifyToken", ctx);
2149
+ }
2150
+ _authVerifyDidBuild(ctx) {
2151
+ if (this.tracingEnabled) onAuthDidFinalize(ctx);
2152
+ }
2153
+ _sessionVerifyWill(ctx) {
2154
+ if (this.tracingEnabled) onAuthWillStart("session:verify", this.tracingOpts, ctx);
2155
+ }
2156
+ _sessionVerifyDidJwt(ctx) {
2157
+ if (this.tracingEnabled) onAuthStage("verifyIfJwt", ctx);
2158
+ }
2159
+ _sessionVerifyDidBuild(ctx) {
2160
+ if (this.tracingEnabled) onAuthDidFinalize(ctx);
2161
+ }
2162
+ _oauthTokenWill(ctx) {
2163
+ if (this.tracingEnabled) onGenericFlowWillStart("oauth/token", this.tracingOpts, ctx);
2164
+ }
2165
+ _oauthTokenDone(ctx) {
2166
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2167
+ }
2168
+ _oauthAuthzWill(ctx) {
2169
+ if (this.tracingEnabled) onGenericFlowWillStart("oauth/authorize", this.tracingOpts, ctx);
2170
+ }
2171
+ _oauthAuthzDone(ctx) {
2172
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2173
+ }
2174
+ _oauthCallbackWill(ctx) {
2175
+ if (this.tracingEnabled) onGenericFlowWillStart("oauth/callback", this.tracingOpts, ctx);
2176
+ }
2177
+ _oauthCallbackDone(ctx) {
2178
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2179
+ }
2180
+ _oauthProviderWill(ctx) {
2181
+ if (this.tracingEnabled) onGenericFlowWillStart("oauth/provider-callback", this.tracingOpts, ctx);
2182
+ }
2183
+ _oauthProviderDone(ctx) {
2184
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2185
+ }
2186
+ _oauthRegisterWill(ctx) {
2187
+ if (this.tracingEnabled) onGenericFlowWillStart("oauth/register", this.tracingOpts, ctx);
2188
+ }
2189
+ _oauthRegisterDone(ctx) {
2190
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2191
+ }
2192
+ _elicitReqWill(ctx) {
2193
+ if (this.tracingEnabled) onGenericFlowWillStart("elicitation/request", this.tracingOpts, ctx);
2194
+ }
2195
+ _elicitReqDone(ctx) {
2196
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2197
+ }
2198
+ _elicitResWill(ctx) {
2199
+ if (this.tracingEnabled) onGenericFlowWillStart("elicitation/result", this.tracingOpts, ctx);
2200
+ }
2201
+ _elicitResDone(ctx) {
2202
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2203
+ }
2204
+ _subscribeWill(ctx) {
2205
+ if (this.tracingEnabled) onGenericFlowWillStart("resources/subscribe", this.tracingOpts, ctx);
2206
+ }
2207
+ _subscribeDone(ctx) {
2208
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2209
+ }
2210
+ _unsubscribeWill(ctx) {
2211
+ if (this.tracingEnabled) onGenericFlowWillStart("resources/unsubscribe", this.tracingOpts, ctx);
2212
+ }
2213
+ _unsubscribeDone(ctx) {
2214
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2215
+ }
2216
+ _skillsLlmTxtWill(ctx) {
2217
+ if (this.tracingEnabled) onGenericFlowWillStart("skills-http/llm-txt", this.tracingOpts, ctx);
2218
+ }
2219
+ _skillsLlmTxtDone(ctx) {
2220
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2221
+ }
2222
+ _skillsLlmFullTxtWill(ctx) {
2223
+ if (this.tracingEnabled) onGenericFlowWillStart("skills-http/llm-full-txt", this.tracingOpts, ctx);
2224
+ }
2225
+ _skillsLlmFullTxtDone(ctx) {
2226
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2227
+ }
2228
+ _skillsApiWill(ctx) {
2229
+ if (this.tracingEnabled) onGenericFlowWillStart("skills-http/api", this.tracingOpts, ctx);
2230
+ }
2231
+ _skillsApiDone(ctx) {
2232
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2233
+ }
2234
+ _jwksWill(ctx) {
2235
+ if (this.tracingEnabled) onGenericFlowWillStart("well-known/jwks", this.tracingOpts, ctx);
2236
+ }
2237
+ _jwksDone(ctx) {
2238
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2239
+ }
2240
+ _oauthServerWill(ctx) {
2241
+ if (this.tracingEnabled) onGenericFlowWillStart("well-known/oauth-server", this.tracingOpts, ctx);
2242
+ }
2243
+ _oauthServerDone(ctx) {
2244
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2245
+ }
2246
+ _prmWill(ctx) {
2247
+ if (this.tracingEnabled) onGenericFlowWillStart("well-known/prm", this.tracingOpts, ctx);
2248
+ }
2249
+ _prmDone(ctx) {
2250
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2251
+ }
2252
+ _setLevelWill(ctx) {
2253
+ if (this.tracingEnabled) onGenericFlowWillStart("logging/set-level", this.tracingOpts, ctx);
2254
+ }
2255
+ _setLevelDone(ctx) {
2256
+ if (this.tracingEnabled) onGenericFlowDidFinalize(ctx);
2257
+ }
2258
+ _toolDidCreateCtxFetch(ctx) {
2259
+ if (this.tracingEnabled) wrapContextFetch(this.tracingOpts, ctx);
2260
+ }
2261
+ _agentDidExecuteMeta(ctx) {
2262
+ if (this.tracingEnabled) onAgentDidExecuteEnrich(ctx);
2263
+ }
2264
+ // ═══════════════════════════════════════════════════════════════════════════
2265
+ // Startup Report (public method)
2266
+ // ═══════════════════════════════════════════════════════════════════════════
2267
+ /**
2268
+ * Emit startup telemetry report.
2269
+ * Call after scope.initialize() completes with component counts.
2270
+ */
2271
+ reportStartupTelemetry(data) {
2272
+ if (this.options.tracing === false) return;
2273
+ reportStartup(data);
2274
+ }
2275
+ };
2276
+ ObservabilityPlugin.defaultOptions = {
2277
+ tracing: DEFAULT_TRACING,
2278
+ logging: false,
2279
+ requestLogs: false
2280
+ };
2281
+ // ═══════════════════════════════════════════════════════════════════════════
2282
+ // Dynamic Providers
2283
+ // ═══════════════════════════════════════════════════════════════════════════
2284
+ ObservabilityPlugin.dynamicProviders = (input) => {
2285
+ const options = resolveOptions(input);
2286
+ const providers = [];
2287
+ if (options.tracing !== false) {
2288
+ providers.push({
2289
+ name: "observability:tracer",
2290
+ provide: OTEL_TRACER,
2291
+ useValue: import_api14.trace.getTracer("@frontmcp/observability")
2292
+ });
2293
+ providers.push({
2294
+ name: "observability:config",
2295
+ provide: OTEL_CONFIG,
2296
+ useValue: options.tracing
2297
+ });
2298
+ providers.push({
2299
+ name: "observability:telemetry-accessor",
2300
+ provide: TELEMETRY_ACCESSOR,
2301
+ scope: import_sdk2.ProviderScope.CONTEXT,
2302
+ inject: () => [import_sdk2.FRONTMCP_CONTEXT],
2303
+ useFactory: (ctx) => new TelemetryAccessor(ctx)
2304
+ });
2305
+ }
2306
+ if (options.logging !== false) {
2307
+ const loggingOpts = options.logging;
2308
+ const sinks = createSinks(loggingOpts.sinks);
2309
+ const transport = new StructuredLogTransport(
2310
+ sinks,
2311
+ {
2312
+ redactFields: loggingOpts.redactFields,
2313
+ includeStacks: loggingOpts.includeStacks,
2314
+ staticFields: loggingOpts.staticFields
2315
+ },
2316
+ void 0
2317
+ );
2318
+ providers.push({
2319
+ name: "observability:structured-log-transport",
2320
+ provide: StructuredLogTransport,
2321
+ useValue: transport
2322
+ });
2323
+ }
2324
+ if (options.requestLogs !== false) {
2325
+ const requestLogOpts = options.requestLogs;
2326
+ providers.push({
2327
+ name: "observability:request-log-collector",
2328
+ provide: REQUEST_LOG_COLLECTOR,
2329
+ scope: import_sdk2.ProviderScope.CONTEXT,
2330
+ inject: () => [import_sdk2.FRONTMCP_CONTEXT],
2331
+ useFactory: (ctx) => {
2332
+ return new RequestLogCollector(
2333
+ {
2334
+ requestId: ctx.requestId,
2335
+ traceId: ctx.traceContext.traceId,
2336
+ sessionIdHash: sessionTracingId(ctx.sessionId).slice(0, 12),
2337
+ scopeId: ctx.scopeId
2338
+ },
2339
+ requestLogOpts
2340
+ );
2341
+ }
2342
+ });
2343
+ }
2344
+ return providers;
2345
+ };
2346
+ __decorateClass([
2347
+ import_sdk2.HttpHook.Will("traceRequest", { priority: -1e3 })
2348
+ ], ObservabilityPlugin.prototype, "_httpWillTrace", 1);
2349
+ __decorateClass([
2350
+ import_sdk2.HttpHook.Will("acquireQuota", { priority: -1e3 })
2351
+ ], ObservabilityPlugin.prototype, "_httpWillQuota", 1);
2352
+ __decorateClass([
2353
+ import_sdk2.HttpHook.Did("acquireSemaphore", { priority: 1e3 })
2354
+ ], ObservabilityPlugin.prototype, "_httpDidSemaphore", 1);
2355
+ __decorateClass([
2356
+ import_sdk2.HttpHook.Will("checkAuthorization", { priority: -1e3 })
2357
+ ], ObservabilityPlugin.prototype, "_httpWillAuth", 1);
2358
+ __decorateClass([
2359
+ import_sdk2.HttpHook.Did("checkAuthorization", { priority: 1e3 })
2360
+ ], ObservabilityPlugin.prototype, "_httpDidAuth", 1);
2361
+ __decorateClass([
2362
+ import_sdk2.HttpHook.Will("router", { priority: -1e3 })
2363
+ ], ObservabilityPlugin.prototype, "_httpWillRoute", 1);
2364
+ __decorateClass([
2365
+ import_sdk2.HttpHook.Did("router", { priority: 1e3 })
2366
+ ], ObservabilityPlugin.prototype, "_httpDidRoute", 1);
2367
+ __decorateClass([
2368
+ import_sdk2.HttpHook.Did("finalize", { priority: 1e3 })
2369
+ ], ObservabilityPlugin.prototype, "_httpDidFinalize", 1);
2370
+ __decorateClass([
2371
+ import_sdk2.ToolHook.Will("parseInput", { priority: -1e3 })
2372
+ ], ObservabilityPlugin.prototype, "_toolWillParse", 1);
2373
+ __decorateClass([
2374
+ import_sdk2.ToolHook.Will("findTool", { priority: -1e3 })
2375
+ ], ObservabilityPlugin.prototype, "_toolWillFind", 1);
2376
+ __decorateClass([
2377
+ import_sdk2.ToolHook.Will("checkToolAuthorization", { priority: -1e3 })
2378
+ ], ObservabilityPlugin.prototype, "_toolWillCheckAuth", 1);
2379
+ __decorateClass([
2380
+ import_sdk2.ToolHook.Will("createToolCallContext", { priority: -1e3 })
2381
+ ], ObservabilityPlugin.prototype, "_toolWillCreateCtx", 1);
2382
+ __decorateClass([
2383
+ import_sdk2.ToolHook.Will("validateInput", { priority: -1e3 })
2384
+ ], ObservabilityPlugin.prototype, "_toolWillValidate", 1);
2385
+ __decorateClass([
2386
+ import_sdk2.ToolHook.Will("execute", { priority: -1e3 })
2387
+ ], ObservabilityPlugin.prototype, "_toolWillExecute", 1);
2388
+ __decorateClass([
2389
+ import_sdk2.ToolHook.Did("execute", { priority: 1e3 })
2390
+ ], ObservabilityPlugin.prototype, "_toolDidExecute", 1);
2391
+ __decorateClass([
2392
+ import_sdk2.ToolHook.Will("validateOutput", { priority: -1e3 })
2393
+ ], ObservabilityPlugin.prototype, "_toolWillValidateOut", 1);
2394
+ __decorateClass([
2395
+ import_sdk2.ToolHook.Will("applyUI", { priority: -1e3 })
2396
+ ], ObservabilityPlugin.prototype, "_toolWillApplyUI", 1);
2397
+ __decorateClass([
2398
+ import_sdk2.ToolHook.Did("finalize", { priority: 1e3 })
2399
+ ], ObservabilityPlugin.prototype, "_toolDidFinalize", 1);
2400
+ __decorateClass([
2401
+ import_sdk2.ResourceHook.Will("parseInput", { priority: -1e3 })
2402
+ ], ObservabilityPlugin.prototype, "_resourceWillParse", 1);
2403
+ __decorateClass([
2404
+ import_sdk2.ResourceHook.Will("findResource", { priority: -1e3 })
2405
+ ], ObservabilityPlugin.prototype, "_resourceWillFind", 1);
2406
+ __decorateClass([
2407
+ import_sdk2.ResourceHook.Will("execute", { priority: -1e3 })
2408
+ ], ObservabilityPlugin.prototype, "_resourceWillExecute", 1);
2409
+ __decorateClass([
2410
+ import_sdk2.ResourceHook.Did("execute", { priority: 1e3 })
2411
+ ], ObservabilityPlugin.prototype, "_resourceDidExecute", 1);
2412
+ __decorateClass([
2413
+ import_sdk2.ResourceHook.Did("finalize", { priority: 1e3 })
2414
+ ], ObservabilityPlugin.prototype, "_resourceDidFinalize", 1);
2415
+ __decorateClass([
2416
+ PromptHook.Will("parseInput", { priority: -1e3 })
2417
+ ], ObservabilityPlugin.prototype, "_promptWillParse", 1);
2418
+ __decorateClass([
2419
+ PromptHook.Will("findPrompt", { priority: -1e3 })
2420
+ ], ObservabilityPlugin.prototype, "_promptWillFind", 1);
2421
+ __decorateClass([
2422
+ PromptHook.Will("execute", { priority: -1e3 })
2423
+ ], ObservabilityPlugin.prototype, "_promptWillExecute", 1);
2424
+ __decorateClass([
2425
+ PromptHook.Did("execute", { priority: 1e3 })
2426
+ ], ObservabilityPlugin.prototype, "_promptDidExecute", 1);
2427
+ __decorateClass([
2428
+ PromptHook.Did("finalize", { priority: 1e3 })
2429
+ ], ObservabilityPlugin.prototype, "_promptDidFinalize", 1);
2430
+ __decorateClass([
2431
+ import_sdk2.AgentCallHook.Will("parseInput", { priority: -1e3 })
2432
+ ], ObservabilityPlugin.prototype, "_agentWillParse", 1);
2433
+ __decorateClass([
2434
+ import_sdk2.AgentCallHook.Will("findAgent", { priority: -1e3 })
2435
+ ], ObservabilityPlugin.prototype, "_agentWillFind", 1);
2436
+ __decorateClass([
2437
+ import_sdk2.AgentCallHook.Will("execute", { priority: -1e3 })
2438
+ ], ObservabilityPlugin.prototype, "_agentWillExecute", 1);
2439
+ __decorateClass([
2440
+ import_sdk2.AgentCallHook.Did("execute", { priority: 1e3 })
2441
+ ], ObservabilityPlugin.prototype, "_agentDidExecute", 1);
2442
+ __decorateClass([
2443
+ import_sdk2.AgentCallHook.Did("finalize", { priority: 1e3 })
2444
+ ], ObservabilityPlugin.prototype, "_agentDidFinalize", 1);
2445
+ __decorateClass([
2446
+ import_sdk2.ListToolsHook.Will("parseInput", { priority: -1e3 })
2447
+ ], ObservabilityPlugin.prototype, "_listToolsWill", 1);
2448
+ __decorateClass([
2449
+ import_sdk2.ListToolsHook.Did("findTools", { priority: 1e3 })
2450
+ ], ObservabilityPlugin.prototype, "_listToolsDidFind", 1);
2451
+ __decorateClass([
2452
+ import_sdk2.ListToolsHook.Did("parseTools", { priority: 1e3 })
2453
+ ], ObservabilityPlugin.prototype, "_listToolsDone", 1);
2454
+ __decorateClass([
2455
+ import_sdk2.ListResourcesHook.Will("parseInput", { priority: -1e3 })
2456
+ ], ObservabilityPlugin.prototype, "_listResourcesWill", 1);
2457
+ __decorateClass([
2458
+ import_sdk2.ListResourcesHook.Did("parseResources", { priority: 1e3 })
2459
+ ], ObservabilityPlugin.prototype, "_listResourcesDone", 1);
2460
+ __decorateClass([
2461
+ import_sdk2.ListResourceTemplatesHook.Will("parseInput", { priority: -1e3 })
2462
+ ], ObservabilityPlugin.prototype, "_listTemplatesWill", 1);
2463
+ __decorateClass([
2464
+ import_sdk2.ListResourceTemplatesHook.Did("parseTemplates", { priority: 1e3 })
2465
+ ], ObservabilityPlugin.prototype, "_listTemplatesDone", 1);
2466
+ __decorateClass([
2467
+ ListPromptsHook.Will("parseInput", { priority: -1e3 })
2468
+ ], ObservabilityPlugin.prototype, "_listPromptsWill", 1);
2469
+ __decorateClass([
2470
+ ListPromptsHook.Did("parsePrompts", { priority: 1e3 })
2471
+ ], ObservabilityPlugin.prototype, "_listPromptsDone", 1);
2472
+ __decorateClass([
2473
+ SkillSearchHook.Will("parseInput", { priority: -1e3 })
2474
+ ], ObservabilityPlugin.prototype, "_skillSearchWill", 1);
2475
+ __decorateClass([
2476
+ SkillSearchHook.Did("finalize", { priority: 1e3 })
2477
+ ], ObservabilityPlugin.prototype, "_skillSearchDone", 1);
2478
+ __decorateClass([
2479
+ SkillLoadHook.Will("parseInput", { priority: -1e3 })
2480
+ ], ObservabilityPlugin.prototype, "_skillLoadWill", 1);
2481
+ __decorateClass([
2482
+ SkillLoadHook.Will("loadSkills", { priority: -1e3 })
2483
+ ], ObservabilityPlugin.prototype, "_skillLoadStage", 1);
2484
+ __decorateClass([
2485
+ SkillLoadHook.Did("finalize", { priority: 1e3 })
2486
+ ], ObservabilityPlugin.prototype, "_skillLoadDone", 1);
2487
+ __decorateClass([
2488
+ CompletionHook.Will("parseInput", { priority: -1e3 })
2489
+ ], ObservabilityPlugin.prototype, "_completionWill", 1);
2490
+ __decorateClass([
2491
+ CompletionHook.Did("finalize", { priority: 1e3 })
2492
+ ], ObservabilityPlugin.prototype, "_completionDone", 1);
2493
+ __decorateClass([
2494
+ LegacySseHook.Will("parseInput", { priority: -1e3 })
2495
+ ], ObservabilityPlugin.prototype, "_sseWillParse", 1);
2496
+ __decorateClass([
2497
+ LegacySseHook.Did("router", { priority: 1e3 })
2498
+ ], ObservabilityPlugin.prototype, "_sseDidRoute", 1);
2499
+ __decorateClass([
2500
+ LegacySseHook.Did("onInitialize", { priority: 1e3 })
2501
+ ], ObservabilityPlugin.prototype, "_sseDidInit", 1);
2502
+ __decorateClass([
2503
+ LegacySseHook.Did("onMessage", { priority: 1e3 })
2504
+ ], ObservabilityPlugin.prototype, "_sseDidMsg", 1);
2505
+ __decorateClass([
2506
+ LegacySseHook.Did("onElicitResult", { priority: 1e3 })
2507
+ ], ObservabilityPlugin.prototype, "_sseDidElicit", 1);
2508
+ __decorateClass([
2509
+ LegacySseHook.Did("cleanup", { priority: 1e3 })
2510
+ ], ObservabilityPlugin.prototype, "_sseDidCleanup", 1);
2511
+ __decorateClass([
2512
+ StreamableHttpHook.Will("parseInput", { priority: -1e3 })
2513
+ ], ObservabilityPlugin.prototype, "_shttpWillParse", 1);
2514
+ __decorateClass([
2515
+ StreamableHttpHook.Did("router", { priority: 1e3 })
2516
+ ], ObservabilityPlugin.prototype, "_shttpDidRoute", 1);
2517
+ __decorateClass([
2518
+ StreamableHttpHook.Did("onInitialize", { priority: 1e3 })
2519
+ ], ObservabilityPlugin.prototype, "_shttpDidInit", 1);
2520
+ __decorateClass([
2521
+ StreamableHttpHook.Did("onMessage", { priority: 1e3 })
2522
+ ], ObservabilityPlugin.prototype, "_shttpDidMsg", 1);
2523
+ __decorateClass([
2524
+ StreamableHttpHook.Did("onElicitResult", { priority: 1e3 })
2525
+ ], ObservabilityPlugin.prototype, "_shttpDidElicit", 1);
2526
+ __decorateClass([
2527
+ StreamableHttpHook.Did("onSseListener", { priority: 1e3 })
2528
+ ], ObservabilityPlugin.prototype, "_shttpDidSse", 1);
2529
+ __decorateClass([
2530
+ StreamableHttpHook.Did("onExtApps", { priority: 1e3 })
2531
+ ], ObservabilityPlugin.prototype, "_shttpDidExtApps", 1);
2532
+ __decorateClass([
2533
+ StreamableHttpHook.Did("cleanup", { priority: 1e3 })
2534
+ ], ObservabilityPlugin.prototype, "_shttpDidCleanup", 1);
2535
+ __decorateClass([
2536
+ StatelessHttpHook.Will("parseInput", { priority: -1e3 })
2537
+ ], ObservabilityPlugin.prototype, "_slhttpWillParse", 1);
2538
+ __decorateClass([
2539
+ StatelessHttpHook.Did("handleRequest", { priority: 1e3 })
2540
+ ], ObservabilityPlugin.prototype, "_slhttpDidHandle", 1);
2541
+ __decorateClass([
2542
+ StatelessHttpHook.Did("cleanup", { priority: 1e3 })
2543
+ ], ObservabilityPlugin.prototype, "_slhttpDidCleanup", 1);
2544
+ __decorateClass([
2545
+ AuthVerifyHook.Will("parseInput", { priority: -1e3 })
2546
+ ], ObservabilityPlugin.prototype, "_authVerifyWill", 1);
2547
+ __decorateClass([
2548
+ AuthVerifyHook.Did("determineAuthMode", { priority: 1e3 })
2549
+ ], ObservabilityPlugin.prototype, "_authVerifyDidMode", 1);
2550
+ __decorateClass([
2551
+ AuthVerifyHook.Did("verifyToken", { priority: 1e3 })
2552
+ ], ObservabilityPlugin.prototype, "_authVerifyDidToken", 1);
2553
+ __decorateClass([
2554
+ AuthVerifyHook.Did("buildAuthorization", { priority: 1e3 })
2555
+ ], ObservabilityPlugin.prototype, "_authVerifyDidBuild", 1);
2556
+ __decorateClass([
2557
+ SessionVerifyHook.Will("parseInput", { priority: -1e3 })
2558
+ ], ObservabilityPlugin.prototype, "_sessionVerifyWill", 1);
2559
+ __decorateClass([
2560
+ SessionVerifyHook.Did("verifyIfJwt", { priority: 1e3 })
2561
+ ], ObservabilityPlugin.prototype, "_sessionVerifyDidJwt", 1);
2562
+ __decorateClass([
2563
+ SessionVerifyHook.Did("buildAuthorizedOutput", { priority: 1e3 })
2564
+ ], ObservabilityPlugin.prototype, "_sessionVerifyDidBuild", 1);
2565
+ __decorateClass([
2566
+ OAuthTokenHook.Will("parseInput", { priority: -1e3 })
2567
+ ], ObservabilityPlugin.prototype, "_oauthTokenWill", 1);
2568
+ __decorateClass([
2569
+ OAuthTokenHook.Did("buildTokenResponse", { priority: 1e3 })
2570
+ ], ObservabilityPlugin.prototype, "_oauthTokenDone", 1);
2571
+ __decorateClass([
2572
+ OAuthAuthorizeHook.Will("parseInput", { priority: -1e3 })
2573
+ ], ObservabilityPlugin.prototype, "_oauthAuthzWill", 1);
2574
+ __decorateClass([
2575
+ OAuthAuthorizeHook.Did("buildAuthorizeOutput", { priority: 1e3 })
2576
+ ], ObservabilityPlugin.prototype, "_oauthAuthzDone", 1);
2577
+ __decorateClass([
2578
+ OAuthCallbackHook.Will("parseInput", { priority: -1e3 })
2579
+ ], ObservabilityPlugin.prototype, "_oauthCallbackWill", 1);
2580
+ __decorateClass([
2581
+ OAuthCallbackHook.Did("redirectToClient", { priority: 1e3 })
2582
+ ], ObservabilityPlugin.prototype, "_oauthCallbackDone", 1);
2583
+ __decorateClass([
2584
+ OAuthProviderCallbackHook.Will("parseInput", { priority: -1e3 })
2585
+ ], ObservabilityPlugin.prototype, "_oauthProviderWill", 1);
2586
+ __decorateClass([
2587
+ OAuthProviderCallbackHook.Did("handleNextProviderOrComplete", { priority: 1e3 })
2588
+ ], ObservabilityPlugin.prototype, "_oauthProviderDone", 1);
2589
+ __decorateClass([
2590
+ OAuthRegisterHook.Will("parseInput", { priority: -1e3 })
2591
+ ], ObservabilityPlugin.prototype, "_oauthRegisterWill", 1);
2592
+ __decorateClass([
2593
+ OAuthRegisterHook.Did("respondRegistration", { priority: 1e3 })
2594
+ ], ObservabilityPlugin.prototype, "_oauthRegisterDone", 1);
2595
+ __decorateClass([
2596
+ ElicitRequestHook.Will("parseInput", { priority: -1e3 })
2597
+ ], ObservabilityPlugin.prototype, "_elicitReqWill", 1);
2598
+ __decorateClass([
2599
+ ElicitRequestHook.Did("finalize", { priority: 1e3 })
2600
+ ], ObservabilityPlugin.prototype, "_elicitReqDone", 1);
2601
+ __decorateClass([
2602
+ ElicitResultHook.Will("parseInput", { priority: -1e3 })
2603
+ ], ObservabilityPlugin.prototype, "_elicitResWill", 1);
2604
+ __decorateClass([
2605
+ ElicitResultHook.Did("finalize", { priority: 1e3 })
2606
+ ], ObservabilityPlugin.prototype, "_elicitResDone", 1);
2607
+ __decorateClass([
2608
+ SubscribeResourceHook.Will("parseInput", { priority: -1e3 })
2609
+ ], ObservabilityPlugin.prototype, "_subscribeWill", 1);
2610
+ __decorateClass([
2611
+ SubscribeResourceHook.Did("finalize", { priority: 1e3 })
2612
+ ], ObservabilityPlugin.prototype, "_subscribeDone", 1);
2613
+ __decorateClass([
2614
+ UnsubscribeResourceHook.Will("parseInput", { priority: -1e3 })
2615
+ ], ObservabilityPlugin.prototype, "_unsubscribeWill", 1);
2616
+ __decorateClass([
2617
+ UnsubscribeResourceHook.Did("finalize", { priority: 1e3 })
2618
+ ], ObservabilityPlugin.prototype, "_unsubscribeDone", 1);
2619
+ __decorateClass([
2620
+ SkillsHttpLlmTxtHook.Will("checkEnabled", { priority: -1e3 })
2621
+ ], ObservabilityPlugin.prototype, "_skillsLlmTxtWill", 1);
2622
+ __decorateClass([
2623
+ SkillsHttpLlmTxtHook.Did("generateContent", { priority: 1e3 })
2624
+ ], ObservabilityPlugin.prototype, "_skillsLlmTxtDone", 1);
2625
+ __decorateClass([
2626
+ SkillsHttpLlmFullTxtHook.Will("checkEnabled", { priority: -1e3 })
2627
+ ], ObservabilityPlugin.prototype, "_skillsLlmFullTxtWill", 1);
2628
+ __decorateClass([
2629
+ SkillsHttpLlmFullTxtHook.Did("generateContent", { priority: 1e3 })
2630
+ ], ObservabilityPlugin.prototype, "_skillsLlmFullTxtDone", 1);
2631
+ __decorateClass([
2632
+ SkillsHttpApiHook.Will("checkEnabled", { priority: -1e3 })
2633
+ ], ObservabilityPlugin.prototype, "_skillsApiWill", 1);
2634
+ __decorateClass([
2635
+ SkillsHttpApiHook.Did("handleRequest", { priority: 1e3 })
2636
+ ], ObservabilityPlugin.prototype, "_skillsApiDone", 1);
2637
+ __decorateClass([
2638
+ WellKnownJwksHook.Will("parseInput", { priority: -1e3 })
2639
+ ], ObservabilityPlugin.prototype, "_jwksWill", 1);
2640
+ __decorateClass([
2641
+ WellKnownJwksHook.Did("collectData", { priority: 1e3 })
2642
+ ], ObservabilityPlugin.prototype, "_jwksDone", 1);
2643
+ __decorateClass([
2644
+ WellKnownOAuthServerHook.Will("parseInput", { priority: -1e3 })
2645
+ ], ObservabilityPlugin.prototype, "_oauthServerWill", 1);
2646
+ __decorateClass([
2647
+ WellKnownOAuthServerHook.Did("collectData", { priority: 1e3 })
2648
+ ], ObservabilityPlugin.prototype, "_oauthServerDone", 1);
2649
+ __decorateClass([
2650
+ WellKnownPrmHook.Will("parseInput", { priority: -1e3 })
2651
+ ], ObservabilityPlugin.prototype, "_prmWill", 1);
2652
+ __decorateClass([
2653
+ WellKnownPrmHook.Did("collectData", { priority: 1e3 })
2654
+ ], ObservabilityPlugin.prototype, "_prmDone", 1);
2655
+ __decorateClass([
2656
+ LoggingSetLevelHook.Will("parseInput", { priority: -1e3 })
2657
+ ], ObservabilityPlugin.prototype, "_setLevelWill", 1);
2658
+ __decorateClass([
2659
+ LoggingSetLevelHook.Did("finalize", { priority: 1e3 })
2660
+ ], ObservabilityPlugin.prototype, "_setLevelDone", 1);
2661
+ __decorateClass([
2662
+ import_sdk2.ToolHook.Did("createToolCallContext", { priority: 999 })
2663
+ ], ObservabilityPlugin.prototype, "_toolDidCreateCtxFetch", 1);
2664
+ __decorateClass([
2665
+ import_sdk2.AgentCallHook.Did("execute", { priority: 999 })
2666
+ ], ObservabilityPlugin.prototype, "_agentDidExecuteMeta", 1);
2667
+ ObservabilityPlugin = __decorateClass([
2668
+ (0, import_sdk2.Plugin)({
2669
+ name: "observability",
2670
+ description: "Full-system OpenTelemetry instrumentation, structured logging, and request logs",
2671
+ providers: [],
2672
+ contextExtensions: [
2673
+ {
2674
+ property: "telemetry",
2675
+ token: TELEMETRY_ACCESSOR,
2676
+ errorMessage: "ObservabilityPlugin is not installed or tracing is disabled. Add ObservabilityPlugin.init() to your plugins array."
2677
+ }
2678
+ ]
2679
+ })
2680
+ ], ObservabilityPlugin);
2681
+ function resolveOptions(input) {
2682
+ return {
2683
+ tracing: resolveTracingOptions(input.tracing),
2684
+ logging: resolveLoggingOptions(input.logging),
2685
+ requestLogs: resolveRequestLogOptions(input.requestLogs)
2686
+ };
2687
+ }
2688
+ function resolveTracingOptions(input) {
2689
+ if (input === false) return false;
2690
+ if (input === true || input === void 0) return DEFAULT_TRACING;
2691
+ return { ...DEFAULT_TRACING, ...input };
2692
+ }
2693
+ function resolveLoggingOptions(input) {
2694
+ if (input === false || input === void 0) return false;
2695
+ if (input === true) return {};
2696
+ return input;
2697
+ }
2698
+ function resolveRequestLogOptions(input) {
2699
+ if (input === false || input === void 0) return false;
2700
+ if (input === true) return {};
2701
+ return input;
2702
+ }
2703
+
2704
+ // libs/observability/src/otel/context-propagator.ts
2705
+ var import_api15 = require("@opentelemetry/api");
2706
+ var TRACEPARENT_HEADER = "traceparent";
2707
+ var FrontMcpPropagator = class {
2708
+ inject(context, carrier, setter) {
2709
+ const span = import_api15.trace.getSpan(context);
2710
+ if (!span) return;
2711
+ const sc = span.spanContext();
2712
+ if (!sc || !isValidSpanContext(sc)) return;
2713
+ const flags = sc.traceFlags.toString(16).padStart(2, "0");
2714
+ const traceparent = `00-${sc.traceId}-${sc.spanId}-${flags}`;
2715
+ setter.set(carrier, TRACEPARENT_HEADER, traceparent);
2716
+ }
2717
+ extract(context, carrier, getter) {
2718
+ const traceparent = getter.get(carrier, TRACEPARENT_HEADER);
2719
+ const value = Array.isArray(traceparent) ? traceparent[0] : traceparent;
2720
+ if (!value) return context;
2721
+ const parsed = parseTraceparent(value);
2722
+ if (!parsed) return context;
2723
+ const spanContext = {
2724
+ traceId: parsed.traceId,
2725
+ spanId: parsed.parentId,
2726
+ traceFlags: parsed.traceFlags,
2727
+ isRemote: true
2728
+ };
2729
+ const span = import_api15.trace.wrapSpanContext(spanContext);
2730
+ return import_api15.trace.setSpan(context, span);
2731
+ }
2732
+ fields() {
2733
+ return [TRACEPARENT_HEADER];
2734
+ }
2735
+ };
2736
+ function parseTraceparent(value) {
2737
+ const parts = value.split("-");
2738
+ if (parts.length !== 4) return null;
2739
+ const [version, traceId, parentId, flags] = parts;
2740
+ if (version !== "00") return null;
2741
+ if (!/^[a-f0-9]{32}$/i.test(traceId) || traceId === "00000000000000000000000000000000") return null;
2742
+ if (!/^[a-f0-9]{16}$/i.test(parentId) || parentId === "0000000000000000") return null;
2743
+ if (!/^[0-9a-fA-F]{2}$/.test(flags)) return null;
2744
+ const traceFlags = parseInt(flags, 16);
2745
+ return {
2746
+ traceId: traceId.toLowerCase(),
2747
+ parentId: parentId.toLowerCase(),
2748
+ traceFlags
2749
+ };
2750
+ }
2751
+ function isValidSpanContext(sc) {
2752
+ return sc.traceId !== "00000000000000000000000000000000" && sc.spanId !== "0000000000000000" && sc.traceId.length === 32 && sc.spanId.length === 16;
2753
+ }
2754
+
2755
+ // libs/observability/src/otel/otel.setup.ts
2756
+ function setupOTel(options) {
2757
+ const serviceName = options?.serviceName ?? process.env["OTEL_SERVICE_NAME"] ?? "frontmcp-server";
2758
+ const exporterType = options?.exporter ?? "console";
2759
+ const endpoint = options?.endpoint ?? process.env["OTEL_EXPORTER_OTLP_ENDPOINT"] ?? "http://localhost:4318";
2760
+ let traceExporter;
2761
+ if (exporterType === "otlp") {
2762
+ try {
2763
+ const { OTLPTraceExporter } = require("@opentelemetry/exporter-trace-otlp-http");
2764
+ traceExporter = new OTLPTraceExporter({ url: `${endpoint}/v1/traces` });
2765
+ } catch {
2766
+ throw new Error(
2767
+ "setupOTel: @opentelemetry/exporter-trace-otlp-http is required for OTLP export. Install it with: npm install @opentelemetry/exporter-trace-otlp-http"
2768
+ );
2769
+ }
2770
+ } else if (exporterType === "console") {
2771
+ const { ConsoleSpanExporter } = require("@opentelemetry/sdk-trace-base");
2772
+ traceExporter = new ConsoleSpanExporter();
2773
+ }
2774
+ try {
2775
+ const { NodeSDK } = require("@opentelemetry/sdk-node");
2776
+ const { Resource } = require("@opentelemetry/resources");
2777
+ const { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } = require("@opentelemetry/semantic-conventions");
2778
+ const resource = new Resource({
2779
+ [ATTR_SERVICE_NAME]: serviceName,
2780
+ ...options?.serviceVersion ? { [ATTR_SERVICE_VERSION]: options.serviceVersion } : {}
2781
+ });
2782
+ const sdk = new NodeSDK({
2783
+ resource,
2784
+ traceExporter
2785
+ });
2786
+ sdk.start();
2787
+ return async () => {
2788
+ await sdk.shutdown();
2789
+ };
2790
+ } catch {
2791
+ throw new Error(
2792
+ "setupOTel: @opentelemetry/sdk-node is required. Install it with: npm install @opentelemetry/sdk-node @opentelemetry/resources @opentelemetry/semantic-conventions"
2793
+ );
2794
+ }
2795
+ }
2796
+
2797
+ // libs/observability/src/otel/spans/hook.span.ts
2798
+ var import_api16 = require("@opentelemetry/api");
2799
+ function recordHookEvent(parentSpan, stage, owner) {
2800
+ const attributes = {};
2801
+ if (owner) {
2802
+ attributes[FrontMcpAttributes.HOOK_OWNER] = owner;
2803
+ }
2804
+ parentSpan.addEvent(`hook.${stage}`, attributes);
2805
+ }
2806
+ function startHookSpan(tracer, options) {
2807
+ const attributes = {
2808
+ [FrontMcpAttributes.HOOK_STAGE]: options.stage
2809
+ };
2810
+ if (options.owner) {
2811
+ attributes[FrontMcpAttributes.HOOK_OWNER] = options.owner;
2812
+ }
2813
+ if (options.flowName) {
2814
+ attributes[FrontMcpAttributes.FLOW_NAME] = options.flowName;
2815
+ }
2816
+ return startSpan(tracer, {
2817
+ name: `hook ${options.stage}`,
2818
+ kind: import_api16.SpanKind.INTERNAL,
2819
+ attributes,
2820
+ parentContext: options.parentContext
2821
+ });
2822
+ }
2823
+
2824
+ // libs/observability/src/otel/spans/pretty-span-exporter.ts
2825
+ var import_api17 = require("@opentelemetry/api");
2826
+ var RESET = "\x1B[0m";
2827
+ var DIM = "\x1B[2m";
2828
+ var BOLD = "\x1B[1m";
2829
+ var CYAN = "\x1B[36m";
2830
+ var GREEN = "\x1B[32m";
2831
+ var RED = "\x1B[31m";
2832
+ var YELLOW = "\x1B[33m";
2833
+ var KIND_LABELS = {
2834
+ [import_api17.SpanKind.INTERNAL]: "INTERNAL",
2835
+ [import_api17.SpanKind.SERVER]: "SERVER",
2836
+ [import_api17.SpanKind.CLIENT]: "CLIENT",
2837
+ [import_api17.SpanKind.PRODUCER]: "PRODUCER",
2838
+ [import_api17.SpanKind.CONSUMER]: "CONSUMER"
2839
+ };
2840
+ var SHOW_ATTRS = /* @__PURE__ */ new Set([
2841
+ "rpc.system",
2842
+ "rpc.method",
2843
+ "rpc.service",
2844
+ "mcp.method.name",
2845
+ "mcp.session.id",
2846
+ "mcp.component.type",
2847
+ "mcp.component.key",
2848
+ "http.request.method",
2849
+ "http.response.status_code",
2850
+ "url.path",
2851
+ "frontmcp.tool.name",
2852
+ "frontmcp.tool.owner",
2853
+ "frontmcp.transport.type",
2854
+ "frontmcp.transport.request_type",
2855
+ "frontmcp.auth.mode",
2856
+ "frontmcp.auth.result",
2857
+ "frontmcp.flow.name",
2858
+ "enduser.id"
2859
+ ]);
2860
+ var PrettySpanExporter = class {
2861
+ constructor() {
2862
+ this.useAnsi = typeof process !== "undefined" && !!process.stdout?.isTTY;
2863
+ }
2864
+ export(spans, resultCallback) {
2865
+ for (const span of spans) {
2866
+ console.log(this.format(span));
2867
+ }
2868
+ resultCallback({ code: 0 });
2869
+ }
2870
+ shutdown() {
2871
+ return Promise.resolve();
2872
+ }
2873
+ format(span) {
2874
+ const traceShort = span.spanContext().traceId.slice(0, 8);
2875
+ const durationMs = (span.duration[0] * 1e3 + span.duration[1] / 1e6).toFixed(1);
2876
+ const kind = KIND_LABELS[span.kind] ?? "UNKNOWN";
2877
+ const statusOk = span.status.code !== import_api17.SpanStatusCode.ERROR;
2878
+ const attrs = Object.entries(span.attributes).filter(([k]) => SHOW_ATTRS.has(k)).map(([k, v]) => {
2879
+ const short = k.replace("frontmcp.", "").replace("mcp.", "");
2880
+ return `${short}=${v}`;
2881
+ }).join(" ");
2882
+ const eventCount = span.events.length;
2883
+ const eventSummary = eventCount > 0 ? ` (${eventCount} events)` : "";
2884
+ if (this.useAnsi) {
2885
+ const statusColor = statusOk ? GREEN : RED;
2886
+ const kindColor = span.kind === import_api17.SpanKind.SERVER ? CYAN : DIM;
2887
+ return [
2888
+ `${DIM}\u21B3${RESET}`,
2889
+ `${BOLD}${statusColor}SPAN${RESET}`,
2890
+ `${BOLD}${span.name}${RESET}`,
2891
+ `${DIM}[${traceShort}]${RESET}`,
2892
+ `${YELLOW}${durationMs}ms${RESET}`,
2893
+ `${kindColor}${kind}${RESET}`,
2894
+ attrs ? `${DIM}${attrs}${RESET}` : "",
2895
+ eventSummary ? `${DIM}${eventSummary}${RESET}` : ""
2896
+ ].filter(Boolean).join(" ");
2897
+ }
2898
+ return ["\u21B3 SPAN", span.name, `[${traceShort}]`, `${durationMs}ms`, kind, attrs, eventSummary].filter(Boolean).join(" ");
2899
+ }
2900
+ };
2901
+
2902
+ // libs/observability/src/logging/sinks/index.ts
2903
+ init_winston_sink();
2904
+ init_pino_sink();
2905
+ init_otlp_sink();
2906
+
2907
+ // libs/observability/src/testing/index.ts
2908
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
2909
+ function createTestTracer(name = "test") {
2910
+ const exporter = new import_sdk_trace_base.InMemorySpanExporter();
2911
+ const provider = new import_sdk_trace_base.BasicTracerProvider();
2912
+ provider.addSpanProcessor(new import_sdk_trace_base.SimpleSpanProcessor(exporter));
2913
+ const tracer = provider.getTracer(name);
2914
+ return {
2915
+ tracer,
2916
+ exporter,
2917
+ provider,
2918
+ cleanup: async () => {
2919
+ exporter.reset();
2920
+ await provider.forceFlush();
2921
+ await provider.shutdown();
2922
+ }
2923
+ };
2924
+ }
2925
+ function getFinishedSpans(exporter) {
2926
+ return exporter.getFinishedSpans();
2927
+ }
2928
+ function assertSpanExists(spans, name) {
2929
+ const match = spans.find((s) => s.name === name);
2930
+ if (!match) {
2931
+ const names = spans.map((s) => s.name).join(", ");
2932
+ throw new Error(`Expected span "${name}" but found: [${names}]`);
2933
+ }
2934
+ return match;
2935
+ }
2936
+ function assertSpanAttribute(span, key, value) {
2937
+ const actual = span.attributes[key];
2938
+ if (actual !== value) {
2939
+ throw new Error(
2940
+ `Expected span "${span.name}" attribute "${key}" to be ${JSON.stringify(value)} but got ${JSON.stringify(actual)}`
2941
+ );
2942
+ }
2943
+ }
2944
+ function findSpan(spans, name) {
2945
+ return spans.find((s) => s.name === name);
2946
+ }
2947
+ function findSpansByAttribute(spans, key, value) {
2948
+ return spans.filter((s) => s.attributes[key] === value);
2949
+ }
2950
+ // Annotate the CommonJS export names for ESM import in node:
2951
+ 0 && (module.exports = {
2952
+ CallbackSink,
2953
+ ConsoleSink,
2954
+ EnduserAttributes,
2955
+ FrontMcpAttributes,
2956
+ FrontMcpPropagator,
2957
+ HttpAttributes,
2958
+ LOG_LEVEL_TO_OTEL_SEVERITY,
2959
+ McpAttributes,
2960
+ OTEL_CONFIG,
2961
+ OTEL_TRACER,
2962
+ ObservabilityPlugin,
2963
+ OtlpSink,
2964
+ PinoSink,
2965
+ PrettySpanExporter,
2966
+ REQUEST_LOG_COLLECTOR,
2967
+ RequestLogCollector,
2968
+ RpcAttributes,
2969
+ StdoutSink,
2970
+ StructuredLogTransport,
2971
+ TELEMETRY_ACCESSOR,
2972
+ TelemetryAccessor,
2973
+ TelemetrySpan,
2974
+ WinstonSink,
2975
+ assertSpanAttribute,
2976
+ assertSpanExists,
2977
+ createOTelContextFromTrace,
2978
+ createSink,
2979
+ createSinks,
2980
+ createTestTracer,
2981
+ emitStartupReport,
2982
+ endSpanError,
2983
+ endSpanOk,
2984
+ findSpan,
2985
+ findSpansByAttribute,
2986
+ frontmcpToOTelSpanContext,
2987
+ getFinishedSpans,
2988
+ otelToFrontmcpContext,
2989
+ recordHookEvent,
2990
+ redactFields,
2991
+ reportStartup,
2992
+ sessionTracingId,
2993
+ setAuthMode,
2994
+ setAuthResult,
2995
+ setFetchResponseStatus,
2996
+ setHttpResponseStatus,
2997
+ setTransportRequestType,
2998
+ setupOTel,
2999
+ startAuthSpan,
3000
+ startFetchSpan,
3001
+ startHookSpan,
3002
+ startHttpServerSpan,
3003
+ startPromptSpan,
3004
+ startResourceSpan,
3005
+ startRpcSpan,
3006
+ startSpan,
3007
+ startToolSpan,
3008
+ startTransportSpan,
3009
+ withSpan
3010
+ });