@osfactory/otel-hook 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +159 -2
- package/dist/{adapter-BJiz6lqM.d.ts → adapter-B9RwW6TO.d.ts} +14 -2
- package/dist/cli.js +2514 -1238
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +5 -2
- package/dist/config.js +479 -169
- package/dist/config.js.map +1 -1
- package/dist/destinations-DWOkVxV1.d.ts +169 -0
- package/dist/diagnostics.d.ts +8 -0
- package/dist/diagnostics.js +2 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/{events-B3MHoJTD.d.ts → events-CSD_YiJ2.d.ts} +2 -0
- package/dist/{otlp-log-sink-zuHojHSP.d.ts → export-destinations-lORbe25J.d.ts} +241 -9
- package/dist/{filesystem-store-r-nNA3BA.d.ts → filesystem-store-DX3dGIgu.d.ts} +1 -1
- package/dist/{hook-Dh8OO4Wa.d.ts → hook-BAxXoKsp.d.ts} +10 -5
- package/dist/index.d.ts +15 -14
- package/dist/index.js +1936 -730
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +4 -4
- package/dist/install.js +31 -2
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +37 -12
- package/dist/integration.js +1942 -617
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +8 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-Bl9ANVff.d.ts → memory-aJilVG4R.d.ts} +2 -2
- package/dist/model.d.ts +1 -1
- package/dist/model.js +7 -0
- package/dist/model.js.map +1 -1
- package/dist/{payload-Ci8_ERm6.d.ts → payload-D7gc0-WQ.d.ts} +41 -2
- package/dist/{ports-n7KFOpKo.d.ts → ports-plO5MKrY.d.ts} +63 -2
- package/dist/providers.d.ts +146 -10
- package/dist/providers.js +397 -13
- package/dist/providers.js.map +1 -1
- package/dist/{registry-CIVvRlVK.d.ts → registry-C7XO4DzD.d.ts} +2 -2
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +1426 -1163
- package/dist/runtime.js.map +1 -1
- package/dist/{schema-Cn0-xz8L.d.ts → schema-CHb3GU1r.d.ts} +98 -3
- package/dist/{semconv-fPRb-dpU.d.ts → semconv-Dw7gcQcg.d.ts} +1 -1
- package/dist/state.d.ts +4 -4
- package/dist/state.js +607 -39
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +23 -66
- package/dist/telemetry.js +637 -34
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +10 -8
- package/dist/testing.js +868 -560
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -284,37 +284,361 @@ var sanitizeResourceAttributes = (attributes) => {
|
|
|
284
284
|
var describeResourceAttributeNames = (attributes) => Object.keys(attributes).sort();
|
|
285
285
|
|
|
286
286
|
// src/config/schema.ts
|
|
287
|
+
import { z as z5 } from "zod";
|
|
288
|
+
|
|
289
|
+
// src/config/destinations.ts
|
|
287
290
|
import { z as z4 } from "zod";
|
|
288
|
-
|
|
289
|
-
|
|
291
|
+
|
|
292
|
+
// src/config/header-value.ts
|
|
293
|
+
var isUnsafeHeaderValue = (value) => [...value].some((char) => {
|
|
294
|
+
const code = char.codePointAt(0) ?? 0;
|
|
295
|
+
return code < 32 && code !== 9 || code === 127 || code > 255;
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// src/config/otlp-headers.ts
|
|
299
|
+
var MAX_OTLP_HEADERS = 32;
|
|
300
|
+
var OTLP_HEADER_VARIABLES = Object.freeze({
|
|
301
|
+
generic: "OTEL_EXPORTER_OTLP_HEADERS",
|
|
302
|
+
traces: "OTEL_EXPORTER_OTLP_TRACES_HEADERS",
|
|
303
|
+
logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
|
|
304
|
+
});
|
|
305
|
+
var HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
306
|
+
var decode = (raw) => {
|
|
307
|
+
try {
|
|
308
|
+
return decodeURIComponent(raw);
|
|
309
|
+
} catch {
|
|
310
|
+
return void 0;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
var parseOtlpHeadersValue = (raw) => {
|
|
314
|
+
const headers = {};
|
|
315
|
+
const warnings = [];
|
|
316
|
+
let overflowed = false;
|
|
317
|
+
for (const [index, rawEntry] of raw.split(",").entries()) {
|
|
318
|
+
const position = String(index + 1);
|
|
319
|
+
const entry = rawEntry.trim();
|
|
320
|
+
if (entry === "") {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
const equals = entry.indexOf("=");
|
|
324
|
+
if (equals <= 0) {
|
|
325
|
+
warnings.push(`entry ${position} is not a key=value pair; ignored`);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const key = decode(entry.slice(0, equals).trim());
|
|
329
|
+
const value = decode(entry.slice(equals + 1).trim());
|
|
330
|
+
if (key === void 0 || value === void 0) {
|
|
331
|
+
warnings.push(`entry ${position} has malformed percent-encoding; ignored`);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const name = key.trim();
|
|
335
|
+
const trimmedValue = value.trim();
|
|
336
|
+
if (!HEADER_NAME_PATTERN.test(name)) {
|
|
337
|
+
warnings.push(`entry ${position} does not name a valid HTTP header; ignored`);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (trimmedValue === "") {
|
|
341
|
+
warnings.push(`entry ${position} has an empty value; ignored`);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (isUnsafeHeaderValue(trimmedValue)) {
|
|
345
|
+
warnings.push(`entry ${position} has a character not allowed in an HTTP header value; ignored`);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const existing = findHeaderName(headers, name);
|
|
349
|
+
if (existing === void 0 && Object.keys(headers).length >= MAX_OTLP_HEADERS) {
|
|
350
|
+
overflowed = true;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (existing !== void 0) {
|
|
354
|
+
delete headers[existing];
|
|
355
|
+
}
|
|
356
|
+
headers[name] = trimmedValue;
|
|
357
|
+
}
|
|
358
|
+
if (overflowed) {
|
|
359
|
+
warnings.push(`more than ${String(MAX_OTLP_HEADERS)} headers were supplied; the excess was ignored`);
|
|
360
|
+
}
|
|
361
|
+
return { headers, warnings };
|
|
362
|
+
};
|
|
363
|
+
var findHeaderName = (headers, name) => {
|
|
364
|
+
const lower = name.toLowerCase();
|
|
365
|
+
return Object.keys(headers).find((candidate) => candidate.toLowerCase() === lower);
|
|
366
|
+
};
|
|
367
|
+
var mergeOtlpHeaders = (...sources) => {
|
|
368
|
+
const merged = {};
|
|
369
|
+
for (const source of sources) {
|
|
370
|
+
for (const [name, value] of Object.entries(source)) {
|
|
371
|
+
const existing = findHeaderName(merged, name);
|
|
372
|
+
if (existing !== void 0) {
|
|
373
|
+
delete merged[existing];
|
|
374
|
+
}
|
|
375
|
+
merged[name] = value;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return merged;
|
|
379
|
+
};
|
|
380
|
+
var resolveOtlpHeaders = (env, explicit = {}) => {
|
|
381
|
+
const warnings = [];
|
|
382
|
+
const read = (variable) => {
|
|
383
|
+
const raw = env[variable];
|
|
384
|
+
if (raw === void 0 || raw.trim() === "") {
|
|
385
|
+
return {};
|
|
386
|
+
}
|
|
387
|
+
const parsed = parseOtlpHeadersValue(raw);
|
|
388
|
+
for (const detail of parsed.warnings) {
|
|
389
|
+
warnings.push({ variable, detail });
|
|
390
|
+
}
|
|
391
|
+
return parsed.headers;
|
|
392
|
+
};
|
|
393
|
+
const generic = read(OTLP_HEADER_VARIABLES.generic);
|
|
394
|
+
const traces = read(OTLP_HEADER_VARIABLES.traces);
|
|
395
|
+
const logs = read(OTLP_HEADER_VARIABLES.logs);
|
|
396
|
+
return {
|
|
397
|
+
traces: mergeOtlpHeaders(generic, traces, explicit),
|
|
398
|
+
logs: mergeOtlpHeaders(generic, logs, explicit),
|
|
399
|
+
warnings
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
var unionOtlpHeaderNames = (...lists) => {
|
|
403
|
+
const names = [];
|
|
404
|
+
const seen = /* @__PURE__ */ new Set();
|
|
405
|
+
for (const name of lists.flat()) {
|
|
406
|
+
if (!seen.has(name.toLowerCase())) {
|
|
407
|
+
seen.add(name.toLowerCase());
|
|
408
|
+
names.push(name);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return names.sort().slice(0, MAX_OTLP_HEADERS);
|
|
412
|
+
};
|
|
413
|
+
var describeOtlpHeaderNames = (...sources) => unionOtlpHeaderNames(...sources.map((source) => Object.keys(source)));
|
|
414
|
+
|
|
415
|
+
// src/config/destinations.ts
|
|
416
|
+
var DEFAULT_DESTINATION_NAME = "default";
|
|
417
|
+
var DESTINATION_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
418
|
+
var MAX_EXPORT_DESTINATIONS = 16;
|
|
419
|
+
var MAX_DESTINATION_HEADERS = MAX_OTLP_HEADERS;
|
|
420
|
+
var HEADER_ENV_REFERENCE_PREFIX = "env:";
|
|
421
|
+
var HEADER_NAME_PATTERN2 = /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;
|
|
422
|
+
var ENV_VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
423
|
+
var MAX_HEADER_VALUE_LENGTH = 8192;
|
|
424
|
+
var exportSignalSchema = z4.enum(["traces", "logs"]);
|
|
425
|
+
var headerValueSchema = z4.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
|
|
426
|
+
(value) => !isUnsafeHeaderValue(value),
|
|
427
|
+
"header values may not contain line breaks, control characters, or characters beyond Latin-1"
|
|
428
|
+
).refine(
|
|
429
|
+
(value) => !value.startsWith(HEADER_ENV_REFERENCE_PREFIX) || ENV_VARIABLE_NAME_PATTERN.test(value.slice(HEADER_ENV_REFERENCE_PREFIX.length)),
|
|
430
|
+
"an env: header reference must name an environment variable, e.g. env:COLLECTOR_TOKEN"
|
|
431
|
+
);
|
|
432
|
+
var endpointSchema = z4.string().url().max(2048);
|
|
433
|
+
var exportDestinationSchema = z4.strictObject({
|
|
434
|
+
/** Unique, lowercase, filesystem-safe. `default` is reserved for the single-endpoint settings. */
|
|
435
|
+
name: z4.string().regex(DESTINATION_NAME_PATTERN, "destination names are lowercase letters, digits, _ and -"),
|
|
436
|
+
/** Default true. A disabled destination is neither sent to nor drained. */
|
|
437
|
+
enabled: z4.boolean().optional(),
|
|
438
|
+
/**
|
|
439
|
+
* Traces URL, with the same meaning as `exporter.endpoint`: the logs URL is
|
|
440
|
+
* derived from it (`/v1/traces` becomes `/v1/logs`) unless `logsEndpoint` is set.
|
|
441
|
+
*/
|
|
442
|
+
endpoint: endpointSchema.optional(),
|
|
443
|
+
/** Per-signal override of `endpoint` for traces. */
|
|
444
|
+
tracesEndpoint: endpointSchema.optional(),
|
|
445
|
+
/** Per-signal override of the derived logs URL. */
|
|
446
|
+
logsEndpoint: endpointSchema.optional(),
|
|
447
|
+
/** Defaults to `exporter.protocol`. */
|
|
448
|
+
protocol: z4.enum(["http/protobuf", "http/json", "none"]).optional(),
|
|
449
|
+
/**
|
|
450
|
+
* Header name to value. A value of the form `env:NAME` is read from that
|
|
451
|
+
* environment variable at send time, so a credential never has to be written
|
|
452
|
+
* into the file. Values never appear in a snapshot, a diagnostic, or `doctor`.
|
|
453
|
+
*/
|
|
454
|
+
headers: z4.record(z4.string().regex(HEADER_NAME_PATTERN2, "not a valid header name"), headerValueSchema).refine(
|
|
455
|
+
(headers) => Object.keys(headers).length <= MAX_DESTINATION_HEADERS,
|
|
456
|
+
`at most ${String(MAX_DESTINATION_HEADERS)} headers per destination`
|
|
457
|
+
).optional(),
|
|
458
|
+
/**
|
|
459
|
+
* Which signals this destination receives. Default: both. The logs signal is
|
|
460
|
+
* still governed by `exporter.logs.enabled`, which stays the one opt-in for a
|
|
461
|
+
* second stream leaving the host.
|
|
462
|
+
*/
|
|
463
|
+
signals: z4.array(exportSignalSchema).min(1).max(2).readonly().optional()
|
|
464
|
+
}).refine(
|
|
465
|
+
(destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0,
|
|
466
|
+
"a destination needs an endpoint, or a tracesEndpoint / logsEndpoint"
|
|
467
|
+
);
|
|
468
|
+
var exportDestinationsSchema = z4.array(exportDestinationSchema).max(MAX_EXPORT_DESTINATIONS).readonly().superRefine((destinations, context) => {
|
|
469
|
+
const seen = /* @__PURE__ */ new Set();
|
|
470
|
+
destinations.forEach((destination, index) => {
|
|
471
|
+
if (destination.name === DEFAULT_DESTINATION_NAME) {
|
|
472
|
+
context.addIssue({
|
|
473
|
+
code: "custom",
|
|
474
|
+
path: [index, "name"],
|
|
475
|
+
message: 'the name "default" is reserved for exporter.endpoint and the OTEL_EXPORTER_OTLP_* variables'
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
if (seen.has(destination.name)) {
|
|
479
|
+
context.addIssue({
|
|
480
|
+
code: "custom",
|
|
481
|
+
path: [index, "name"],
|
|
482
|
+
message: `duplicate destination name "${destination.name}"`
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
seen.add(destination.name);
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
var spoolPolicySchema = z4.strictObject({
|
|
489
|
+
/** Total bytes of queued batches. Default 16 MiB. */
|
|
490
|
+
maxBytes: z4.number().int().min(1024).max(1073741824),
|
|
491
|
+
/** A batch older than this is dropped instead of sent. Default 72 hours. */
|
|
492
|
+
maxAgeMillis: z4.number().int().min(1e3).max(30 * 24 * 60 * 60 * 1e3),
|
|
493
|
+
/** Number of queued batches. Default 500. */
|
|
494
|
+
maxBatches: z4.number().int().min(1).max(65536)
|
|
495
|
+
});
|
|
496
|
+
var DEFAULT_SPOOL_POLICY = Object.freeze({
|
|
497
|
+
maxBytes: 16 * 1024 * 1024,
|
|
498
|
+
maxAgeMillis: 72 * 60 * 60 * 1e3,
|
|
499
|
+
maxBatches: 500
|
|
500
|
+
});
|
|
501
|
+
var effectiveSpoolPolicy = (exporter) => ({
|
|
502
|
+
maxBytes: exporter.spool?.maxBytes ?? DEFAULT_SPOOL_POLICY.maxBytes,
|
|
503
|
+
maxAgeMillis: exporter.spool?.maxAgeMillis ?? DEFAULT_SPOOL_POLICY.maxAgeMillis,
|
|
504
|
+
maxBatches: exporter.spool?.maxBatches ?? DEFAULT_SPOOL_POLICY.maxBatches
|
|
505
|
+
});
|
|
506
|
+
var legacyDestination = (exporter) => ({
|
|
507
|
+
name: DEFAULT_DESTINATION_NAME,
|
|
508
|
+
source: "exporter",
|
|
509
|
+
protocol: exporter.protocol,
|
|
510
|
+
...exporter.endpoint === void 0 ? {} : { endpoint: exporter.endpoint },
|
|
511
|
+
...exporter.logs.endpoint === void 0 ? {} : { logsEndpoint: exporter.logs.endpoint },
|
|
512
|
+
signals: { traces: true, logs: exporter.logs.enabled },
|
|
513
|
+
headers: {}
|
|
514
|
+
});
|
|
515
|
+
var hasConfiguredDestinations = (exporter) => exporter.destinations !== void 0 && exporter.destinations.length > 0;
|
|
516
|
+
var resolveExportDestinations = (exporter) => {
|
|
517
|
+
if (!hasConfiguredDestinations(exporter)) {
|
|
518
|
+
return [legacyDestination(exporter)];
|
|
519
|
+
}
|
|
520
|
+
const resolved = [];
|
|
521
|
+
if (exporter.endpoint !== void 0 || exporter.logs.endpoint !== void 0) {
|
|
522
|
+
resolved.push(legacyDestination(exporter));
|
|
523
|
+
}
|
|
524
|
+
for (const destination of exporter.destinations ?? []) {
|
|
525
|
+
if (destination.enabled === false) {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
const signals = destination.signals ?? exportSignalSchema.options;
|
|
529
|
+
resolved.push({
|
|
530
|
+
name: destination.name,
|
|
531
|
+
source: "destinations",
|
|
532
|
+
protocol: destination.protocol ?? exporter.protocol,
|
|
533
|
+
...destination.endpoint === void 0 ? {} : { endpoint: destination.endpoint },
|
|
534
|
+
...destination.tracesEndpoint === void 0 ? {} : { tracesEndpoint: destination.tracesEndpoint },
|
|
535
|
+
...destination.logsEndpoint === void 0 ? {} : { logsEndpoint: destination.logsEndpoint },
|
|
536
|
+
signals: {
|
|
537
|
+
traces: signals.includes("traces"),
|
|
538
|
+
logs: exporter.logs.enabled && signals.includes("logs")
|
|
539
|
+
},
|
|
540
|
+
headers: { ...destination.headers ?? {} }
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
return resolved;
|
|
544
|
+
};
|
|
545
|
+
var parseHeaderValueReference = (value) => value.startsWith(HEADER_ENV_REFERENCE_PREFIX) ? { kind: "env", variable: value.slice(HEADER_ENV_REFERENCE_PREFIX.length) } : { kind: "literal" };
|
|
546
|
+
var resolveDestinationHeaders = (headers, environment) => {
|
|
547
|
+
const values = {};
|
|
548
|
+
const missing = [];
|
|
549
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
550
|
+
const reference = parseHeaderValueReference(value);
|
|
551
|
+
if (reference.kind === "literal") {
|
|
552
|
+
values[name] = value;
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
const resolved = environment?.[reference.variable];
|
|
556
|
+
if (resolved === void 0 || resolved === "") {
|
|
557
|
+
missing.push(reference.variable);
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
values[name] = resolved;
|
|
561
|
+
}
|
|
562
|
+
return { values, missingVariables: [...new Set(missing)].sort() };
|
|
563
|
+
};
|
|
564
|
+
var endpointOrigin = (endpoint) => {
|
|
565
|
+
if (endpoint === void 0) {
|
|
566
|
+
return void 0;
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
return new URL(endpoint).origin;
|
|
570
|
+
} catch {
|
|
571
|
+
return "<unparsable>";
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
var describeExportDestinations = (exporter) => {
|
|
575
|
+
const describe = (destination, enabled2) => {
|
|
576
|
+
const tracesOrigin = endpointOrigin(destination.tracesEndpoint ?? destination.endpoint);
|
|
577
|
+
const logsOrigin = endpointOrigin(
|
|
578
|
+
destination.logsEndpoint ?? destination.endpoint ?? destination.tracesEndpoint
|
|
579
|
+
);
|
|
580
|
+
const variables = Object.values(destination.headers).map(parseHeaderValueReference).flatMap((reference) => reference.kind === "env" ? [reference.variable] : []);
|
|
581
|
+
return {
|
|
582
|
+
name: destination.name,
|
|
583
|
+
enabled: enabled2,
|
|
584
|
+
protocol: destination.protocol,
|
|
585
|
+
signals: exportSignalSchema.options.filter((signal) => destination.signals[signal]),
|
|
586
|
+
...tracesOrigin === void 0 || !destination.signals.traces ? {} : { tracesEndpointOrigin: tracesOrigin },
|
|
587
|
+
...logsOrigin === void 0 || !destination.signals.logs ? {} : { logsEndpointOrigin: logsOrigin },
|
|
588
|
+
headerNames: destination.source === "exporter" ? [...exporter.headerNames].sort() : Object.keys(destination.headers).sort(),
|
|
589
|
+
headerVariables: [...new Set(variables)].sort()
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
const enabled = resolveExportDestinations(exporter).map(
|
|
593
|
+
(destination) => describe(destination, true)
|
|
594
|
+
);
|
|
595
|
+
const disabled = (exporter.destinations ?? []).filter((destination) => destination.enabled === false).map(
|
|
596
|
+
(destination) => describe(
|
|
597
|
+
{
|
|
598
|
+
name: destination.name,
|
|
599
|
+
source: "destinations",
|
|
600
|
+
protocol: destination.protocol ?? exporter.protocol,
|
|
601
|
+
...destination.endpoint === void 0 ? {} : { endpoint: destination.endpoint },
|
|
602
|
+
signals: { traces: false, logs: false },
|
|
603
|
+
headers: { ...destination.headers ?? {} }
|
|
604
|
+
},
|
|
605
|
+
false
|
|
606
|
+
)
|
|
607
|
+
);
|
|
608
|
+
return [...enabled, ...disabled];
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
// src/config/schema.ts
|
|
612
|
+
var logsPolicySchema = z5.strictObject({
|
|
613
|
+
enabled: z5.boolean(),
|
|
290
614
|
/**
|
|
291
615
|
* Full URL for the logs signal.
|
|
292
616
|
*
|
|
293
617
|
* Absent, it is derived from `endpoint`: a trailing `/v1/traces` becomes
|
|
294
618
|
* `/v1/logs`, and an endpoint with no signal path has `/v1/logs` appended.
|
|
295
619
|
*/
|
|
296
|
-
endpoint:
|
|
297
|
-
includeContent:
|
|
298
|
-
maxBatchSize:
|
|
620
|
+
endpoint: z5.string().url().max(2048).optional(),
|
|
621
|
+
includeContent: z5.boolean(),
|
|
622
|
+
maxBatchSize: z5.number().int().min(1).max(4096)
|
|
299
623
|
});
|
|
300
624
|
var DEFAULT_LOGS_POLICY = Object.freeze({
|
|
301
625
|
enabled: false,
|
|
302
626
|
includeContent: false,
|
|
303
627
|
maxBatchSize: 128
|
|
304
628
|
});
|
|
305
|
-
var exporterPolicySchema =
|
|
306
|
-
enabled:
|
|
307
|
-
protocol:
|
|
308
|
-
endpoint:
|
|
629
|
+
var exporterPolicySchema = z5.strictObject({
|
|
630
|
+
enabled: z5.boolean(),
|
|
631
|
+
protocol: z5.enum(["http/protobuf", "http/json", "none"]),
|
|
632
|
+
endpoint: z5.string().url().max(2048).optional(),
|
|
309
633
|
/**
|
|
310
634
|
* Header names only. Values are supplied separately at construction time and
|
|
311
635
|
* are never part of a resolved-config snapshot, which is logged and exported.
|
|
312
636
|
*/
|
|
313
|
-
headerNames:
|
|
314
|
-
timeoutMillis:
|
|
315
|
-
maxBatchSize:
|
|
316
|
-
maxQueueSize:
|
|
317
|
-
maxRetryAttempts:
|
|
637
|
+
headerNames: z5.array(nonEmptyStringSchema).max(32).readonly(),
|
|
638
|
+
timeoutMillis: z5.number().int().min(1).max(6e5),
|
|
639
|
+
maxBatchSize: z5.number().int().min(1).max(4096),
|
|
640
|
+
maxQueueSize: z5.number().int().min(1).max(65536),
|
|
641
|
+
maxRetryAttempts: z5.number().int().min(0).max(10),
|
|
318
642
|
serviceName: nonEmptyStringSchema,
|
|
319
643
|
serviceNamespace: nonEmptyStringSchema.optional(),
|
|
320
644
|
/**
|
|
@@ -331,35 +655,65 @@ var exporterPolicySchema = z4.strictObject({
|
|
|
331
655
|
* headers, timeout, protocol, service identity, and resource attributes above —
|
|
332
656
|
* a second top-level section would invite two of each to drift apart.
|
|
333
657
|
*/
|
|
334
|
-
logs: logsPolicySchema
|
|
658
|
+
logs: logsPolicySchema,
|
|
659
|
+
/**
|
|
660
|
+
* Additional OTLP destinations, each sent every batch in parallel.
|
|
661
|
+
*
|
|
662
|
+
* Absent (the default), the exporter has exactly one destination — the
|
|
663
|
+
* single-endpoint settings above, named `default` — and behaves exactly as it
|
|
664
|
+
* did before this list existed. See `destinations.ts`.
|
|
665
|
+
*
|
|
666
|
+
* Merged as one leaf: a higher layer that sets the list replaces it whole,
|
|
667
|
+
* because "the union of two partial lists" has no answer an operator could
|
|
668
|
+
* predict.
|
|
669
|
+
*/
|
|
670
|
+
destinations: exportDestinationsSchema.optional(),
|
|
671
|
+
/**
|
|
672
|
+
* Per-destination retry spool bounds, each optional and merged per leaf; any
|
|
673
|
+
* bound left unset takes its value from `DEFAULT_SPOOL_POLICY`.
|
|
674
|
+
*/
|
|
675
|
+
spool: spoolPolicySchema.partial().optional()
|
|
335
676
|
});
|
|
336
|
-
var detectionPolicySchema =
|
|
677
|
+
var detectionPolicySchema = z5.strictObject({
|
|
337
678
|
/** Detections below this confidence resolve to the unknown provider. */
|
|
338
679
|
minimumConfidence: detectionConfidenceSchema,
|
|
339
680
|
/** When false, an ambiguous detection is an error rather than unknown. */
|
|
340
|
-
allowAmbiguousFallback:
|
|
681
|
+
allowAmbiguousFallback: z5.boolean(),
|
|
341
682
|
/** Optional allow-list of provider ids; empty means "any registered". */
|
|
342
|
-
allowedProviderIds:
|
|
683
|
+
allowedProviderIds: z5.array(nonEmptyStringSchema).max(32).readonly()
|
|
343
684
|
});
|
|
344
|
-
var diagnosticsPolicySchema =
|
|
345
|
-
logLevel:
|
|
685
|
+
var diagnosticsPolicySchema = z5.strictObject({
|
|
686
|
+
logLevel: z5.enum(["silent", "error", "warn", "info", "debug"]),
|
|
346
687
|
/** Emit `error.raised` events for contained failures. */
|
|
347
|
-
emitErrorEvents:
|
|
688
|
+
emitErrorEvents: z5.boolean()
|
|
689
|
+
});
|
|
690
|
+
var providersPolicySchema = z5.strictObject({
|
|
691
|
+
claudeCode: z5.strictObject({
|
|
692
|
+
readTranscriptUsage: z5.boolean()
|
|
693
|
+
}).optional()
|
|
348
694
|
});
|
|
349
|
-
var otelHookConfigSchema =
|
|
695
|
+
var otelHookConfigSchema = z5.strictObject({
|
|
350
696
|
exporter: exporterPolicySchema,
|
|
351
697
|
privacy: privacyPolicySchema,
|
|
352
698
|
detection: detectionPolicySchema,
|
|
353
|
-
diagnostics: diagnosticsPolicySchema
|
|
699
|
+
diagnostics: diagnosticsPolicySchema,
|
|
700
|
+
/** Optional so a hand-built configuration from before it existed stays valid. */
|
|
701
|
+
providers: providersPolicySchema.optional()
|
|
354
702
|
});
|
|
355
|
-
var otelHookConfigPatchSchema =
|
|
703
|
+
var otelHookConfigPatchSchema = z5.strictObject({
|
|
356
704
|
// `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
|
|
357
705
|
// merging happens per leaf, so a layer must be able to set `logs.enabled` alone
|
|
358
706
|
// without also restating the endpoint and the batch size.
|
|
359
|
-
exporter: exporterPolicySchema.omit({ logs: true }).partial().extend({
|
|
707
|
+
exporter: exporterPolicySchema.omit({ logs: true, spool: true }).partial().extend({
|
|
708
|
+
logs: logsPolicySchema.partial().optional(),
|
|
709
|
+
spool: spoolPolicySchema.partial().optional()
|
|
710
|
+
}).optional(),
|
|
360
711
|
privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
|
|
361
712
|
detection: detectionPolicySchema.partial().optional(),
|
|
362
|
-
diagnostics: diagnosticsPolicySchema.partial().optional()
|
|
713
|
+
diagnostics: diagnosticsPolicySchema.partial().optional(),
|
|
714
|
+
providers: z5.strictObject({
|
|
715
|
+
claudeCode: z5.strictObject({ readTranscriptUsage: z5.boolean() }).partial().optional()
|
|
716
|
+
}).partial().optional()
|
|
363
717
|
});
|
|
364
718
|
var DEFAULT_EXPORTER_POLICY = Object.freeze({
|
|
365
719
|
enabled: true,
|
|
@@ -382,22 +736,27 @@ var DEFAULT_DIAGNOSTICS_POLICY = Object.freeze({
|
|
|
382
736
|
logLevel: "warn",
|
|
383
737
|
emitErrorEvents: true
|
|
384
738
|
});
|
|
739
|
+
var DEFAULT_PROVIDERS_POLICY = Object.freeze({
|
|
740
|
+
claudeCode: Object.freeze({ readTranscriptUsage: false })
|
|
741
|
+
});
|
|
385
742
|
var DEFAULT_CONFIG = Object.freeze({
|
|
386
743
|
exporter: DEFAULT_EXPORTER_POLICY,
|
|
387
744
|
privacy: DEFAULT_PRIVACY_POLICY,
|
|
388
745
|
detection: DEFAULT_DETECTION_POLICY,
|
|
389
|
-
diagnostics: DEFAULT_DIAGNOSTICS_POLICY
|
|
746
|
+
diagnostics: DEFAULT_DIAGNOSTICS_POLICY,
|
|
747
|
+
providers: DEFAULT_PROVIDERS_POLICY
|
|
390
748
|
});
|
|
749
|
+
var readsClaudeTranscriptUsage = (config) => config.providers?.claudeCode?.readTranscriptUsage === true;
|
|
391
750
|
|
|
392
751
|
// src/config/resolve.ts
|
|
393
|
-
import { z as
|
|
752
|
+
import { z as z8 } from "zod";
|
|
394
753
|
|
|
395
754
|
// src/errors/index.ts
|
|
396
|
-
import { z as
|
|
755
|
+
import { z as z7 } from "zod";
|
|
397
756
|
|
|
398
757
|
// src/errors/taxonomy.ts
|
|
399
|
-
import { z as
|
|
400
|
-
var otelHookErrorCodeSchema =
|
|
758
|
+
import { z as z6 } from "zod";
|
|
759
|
+
var otelHookErrorCodeSchema = z6.enum([
|
|
401
760
|
/** Input was not usable at all (empty stdin, unparsable JSON). */
|
|
402
761
|
"invalid-input",
|
|
403
762
|
/** Input parsed but failed canonical schema validation. */
|
|
@@ -433,8 +792,8 @@ var otelHookErrorCodeSchema = z5.enum([
|
|
|
433
792
|
/** Anything unanticipated. Always reported, never fatal to the host. */
|
|
434
793
|
"internal-error"
|
|
435
794
|
]);
|
|
436
|
-
var errorSeveritySchema =
|
|
437
|
-
var errorPhaseSchema =
|
|
795
|
+
var errorSeveritySchema = z6.enum(["warning", "error"]);
|
|
796
|
+
var errorPhaseSchema = z6.enum([
|
|
438
797
|
"configuration",
|
|
439
798
|
"detection",
|
|
440
799
|
"identity",
|
|
@@ -445,7 +804,7 @@ var errorPhaseSchema = z5.enum([
|
|
|
445
804
|
"export",
|
|
446
805
|
"shutdown"
|
|
447
806
|
]);
|
|
448
|
-
var failurePostureSchema =
|
|
807
|
+
var failurePostureSchema = z6.enum(["fail-open", "fail-closed-attribution"]);
|
|
449
808
|
var ERROR_TAXONOMY = Object.freeze({
|
|
450
809
|
"invalid-input": {
|
|
451
810
|
code: "invalid-input",
|
|
@@ -570,7 +929,7 @@ var ERROR_TAXONOMY = Object.freeze({
|
|
|
570
929
|
}
|
|
571
930
|
});
|
|
572
931
|
var describeErrorCode = (code) => ERROR_TAXONOMY[code];
|
|
573
|
-
var attributionOutcomeSchema =
|
|
932
|
+
var attributionOutcomeSchema = z6.enum([
|
|
574
933
|
/** Identity resolved; events carry provider and session identity. */
|
|
575
934
|
"attributed",
|
|
576
935
|
/** Identity could not be established safely; nothing was attributed. */
|
|
@@ -580,7 +939,7 @@ var attributionOutcomeSchema = z5.enum([
|
|
|
580
939
|
/** Input was recognized but intentionally carried no telemetry. */
|
|
581
940
|
"not-applicable"
|
|
582
941
|
]);
|
|
583
|
-
var attributionReasonSchema =
|
|
942
|
+
var attributionReasonSchema = z6.enum([
|
|
584
943
|
"provider-unknown",
|
|
585
944
|
"provider-detection-ambiguous",
|
|
586
945
|
"identity-conflict",
|
|
@@ -592,13 +951,13 @@ var attributionReasonSchema = z5.enum([
|
|
|
592
951
|
]);
|
|
593
952
|
|
|
594
953
|
// src/errors/index.ts
|
|
595
|
-
var otelHookErrorInfoSchema =
|
|
954
|
+
var otelHookErrorInfoSchema = z7.strictObject({
|
|
596
955
|
code: otelHookErrorCodeSchema,
|
|
597
956
|
severity: errorSeveritySchema,
|
|
598
957
|
phase: errorPhaseSchema,
|
|
599
958
|
posture: failurePostureSchema,
|
|
600
|
-
retryable:
|
|
601
|
-
message:
|
|
959
|
+
retryable: z7.boolean(),
|
|
960
|
+
message: z7.string().min(1).max(512),
|
|
602
961
|
details: attributesSchema.optional(),
|
|
603
962
|
occurredAt: epochMillisSchema.optional()
|
|
604
963
|
});
|
|
@@ -619,7 +978,7 @@ var createErrorInfo = (input) => {
|
|
|
619
978
|
|
|
620
979
|
// src/config/resolve.ts
|
|
621
980
|
var CONFIG_SOURCE_PRECEDENCE = ["defaults", "file", "environment", "inline-override"];
|
|
622
|
-
var configSourceSchema =
|
|
981
|
+
var configSourceSchema = z8.enum(CONFIG_SOURCE_PRECEDENCE);
|
|
623
982
|
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
624
983
|
var mergeLeaf = (target, patch, source, provenance, path) => {
|
|
625
984
|
for (const [key, value] of Object.entries(patch)) {
|
|
@@ -628,8 +987,8 @@ var mergeLeaf = (target, patch, source, provenance, path) => {
|
|
|
628
987
|
}
|
|
629
988
|
const childPath = path === "" ? key : `${path}.${key}`;
|
|
630
989
|
const existing = target[key];
|
|
631
|
-
if (isPlainObject(value) && isPlainObject(existing)) {
|
|
632
|
-
const child = { ...existing };
|
|
990
|
+
if (isPlainObject(value) && (isPlainObject(existing) || existing === void 0)) {
|
|
991
|
+
const child = { ...existing ?? {} };
|
|
633
992
|
mergeLeaf(child, value, source, provenance, childPath);
|
|
634
993
|
target[key] = child;
|
|
635
994
|
continue;
|
|
@@ -701,10 +1060,27 @@ var resolveConfig = (layers = []) => {
|
|
|
701
1060
|
if (parsed.data.privacy.contentMode === "raw" && !parsed.data.privacy.allowRawContent) {
|
|
702
1061
|
notes.push("privacy.contentMode=raw will be downgraded to omit: allowRawContent is false");
|
|
703
1062
|
}
|
|
704
|
-
|
|
1063
|
+
const withDestinations = hasConfiguredDestinations(parsed.data.exporter);
|
|
1064
|
+
if (parsed.data.exporter.enabled && parsed.data.exporter.protocol !== "none" && parsed.data.exporter.endpoint === void 0 && !withDestinations) {
|
|
705
1065
|
notes.push("exporter.enabled is true but no endpoint is configured");
|
|
706
1066
|
}
|
|
707
|
-
if (
|
|
1067
|
+
if (withDestinations) {
|
|
1068
|
+
const enabled = (parsed.data.exporter.destinations ?? []).filter(
|
|
1069
|
+
(destination) => destination.enabled !== false
|
|
1070
|
+
);
|
|
1071
|
+
if (enabled.length === 0 && parsed.data.exporter.endpoint === void 0) {
|
|
1072
|
+
notes.push("exporter.destinations is set but every destination is disabled");
|
|
1073
|
+
}
|
|
1074
|
+
if (!parsed.data.exporter.logs.enabled) {
|
|
1075
|
+
const askingForLogs = enabled.filter((destination) => destination.signals?.includes("logs") === true).map((destination) => destination.name);
|
|
1076
|
+
if (askingForLogs.length > 0) {
|
|
1077
|
+
notes.push(
|
|
1078
|
+
`destination(s) ${askingForLogs.join(", ")} list the logs signal but exporter.logs.enabled is false, so only traces are sent`
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
if (!withDestinations && parsed.data.exporter.logs.enabled && parsed.data.exporter.logs.endpoint === void 0 && parsed.data.exporter.endpoint === void 0) {
|
|
708
1084
|
notes.push(
|
|
709
1085
|
"exporter.logs.enabled is true but neither a logs endpoint nor a trace endpoint to derive one from is configured"
|
|
710
1086
|
);
|
|
@@ -716,6 +1092,35 @@ var resolveConfig = (layers = []) => {
|
|
|
716
1092
|
}
|
|
717
1093
|
return { status: "ok", config: parsed.data, provenance, notes };
|
|
718
1094
|
};
|
|
1095
|
+
var describeDestinationAttributes = (config) => {
|
|
1096
|
+
const attributes = {};
|
|
1097
|
+
if (config.exporter.spool !== void 0 || hasConfiguredDestinations(config.exporter)) {
|
|
1098
|
+
const spool = effectiveSpoolPolicy(config.exporter);
|
|
1099
|
+
attributes["exporter.spool_max_bytes"] = spool.maxBytes;
|
|
1100
|
+
attributes["exporter.spool_max_age_millis"] = spool.maxAgeMillis;
|
|
1101
|
+
attributes["exporter.spool_max_batches"] = spool.maxBatches;
|
|
1102
|
+
}
|
|
1103
|
+
if (!hasConfiguredDestinations(config.exporter)) {
|
|
1104
|
+
return attributes;
|
|
1105
|
+
}
|
|
1106
|
+
const destinations = describeExportDestinations(config.exporter);
|
|
1107
|
+
attributes["exporter.destination_names"] = destinations.map((destination) => destination.name);
|
|
1108
|
+
for (const destination of destinations) {
|
|
1109
|
+
const prefix = `exporter.destination.${destination.name}`;
|
|
1110
|
+
attributes[`${prefix}.enabled`] = destination.enabled;
|
|
1111
|
+
attributes[`${prefix}.protocol`] = destination.protocol;
|
|
1112
|
+
attributes[`${prefix}.signals`] = [...destination.signals];
|
|
1113
|
+
if (destination.tracesEndpointOrigin !== void 0) {
|
|
1114
|
+
attributes[`${prefix}.traces_endpoint_origin`] = destination.tracesEndpointOrigin;
|
|
1115
|
+
}
|
|
1116
|
+
if (destination.logsEndpointOrigin !== void 0) {
|
|
1117
|
+
attributes[`${prefix}.logs_endpoint_origin`] = destination.logsEndpointOrigin;
|
|
1118
|
+
}
|
|
1119
|
+
attributes[`${prefix}.header_names`] = [...destination.headerNames];
|
|
1120
|
+
attributes[`${prefix}.header_variables`] = [...destination.headerVariables];
|
|
1121
|
+
}
|
|
1122
|
+
return attributes;
|
|
1123
|
+
};
|
|
719
1124
|
var describeResolvedConfig = (config) => {
|
|
720
1125
|
const originOf = (endpoint) => {
|
|
721
1126
|
if (endpoint === void 0) {
|
|
@@ -727,12 +1132,12 @@ var describeResolvedConfig = (config) => {
|
|
|
727
1132
|
return "<unparsable>";
|
|
728
1133
|
}
|
|
729
1134
|
};
|
|
730
|
-
const
|
|
1135
|
+
const endpointOrigin2 = originOf(config.exporter.endpoint);
|
|
731
1136
|
const logsEndpointOrigin = originOf(config.exporter.logs.endpoint);
|
|
732
1137
|
return {
|
|
733
1138
|
"exporter.enabled": config.exporter.enabled,
|
|
734
1139
|
"exporter.protocol": config.exporter.protocol,
|
|
735
|
-
...
|
|
1140
|
+
...endpointOrigin2 === void 0 ? {} : { "exporter.endpoint_origin": endpointOrigin2 },
|
|
736
1141
|
"exporter.logs_enabled": config.exporter.logs.enabled,
|
|
737
1142
|
"exporter.logs_include_content": config.exporter.logs.includeContent,
|
|
738
1143
|
"exporter.logs_max_batch_size": config.exporter.logs.maxBatchSize,
|
|
@@ -744,6 +1149,7 @@ var describeResolvedConfig = (config) => {
|
|
|
744
1149
|
"exporter.resource_attribute_names": [
|
|
745
1150
|
...describeResourceAttributeNames(config.exporter.resourceAttributes)
|
|
746
1151
|
],
|
|
1152
|
+
...describeDestinationAttributes(config),
|
|
747
1153
|
"exporter.timeout_millis": config.exporter.timeoutMillis,
|
|
748
1154
|
"exporter.max_batch_size": config.exporter.maxBatchSize,
|
|
749
1155
|
"exporter.service_name": config.exporter.serviceName,
|
|
@@ -784,127 +1190,6 @@ var otlpSignalEndpointFromBase = (base, signal) => {
|
|
|
784
1190
|
return `${trimmed}${signal === "traces" ? OTLP_TRACES_PATH : OTLP_LOGS_PATH}`;
|
|
785
1191
|
};
|
|
786
1192
|
|
|
787
|
-
// src/config/otlp-headers.ts
|
|
788
|
-
var MAX_OTLP_HEADERS = 32;
|
|
789
|
-
var OTLP_HEADER_VARIABLES = Object.freeze({
|
|
790
|
-
generic: "OTEL_EXPORTER_OTLP_HEADERS",
|
|
791
|
-
traces: "OTEL_EXPORTER_OTLP_TRACES_HEADERS",
|
|
792
|
-
logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
|
|
793
|
-
});
|
|
794
|
-
var HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
795
|
-
var isUnsafeHeaderValue = (value) => [...value].some((char) => {
|
|
796
|
-
const code = char.codePointAt(0) ?? 0;
|
|
797
|
-
return code < 32 && code !== 9 || code === 127 || code > 255;
|
|
798
|
-
});
|
|
799
|
-
var decode = (raw) => {
|
|
800
|
-
try {
|
|
801
|
-
return decodeURIComponent(raw);
|
|
802
|
-
} catch {
|
|
803
|
-
return void 0;
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
var parseOtlpHeadersValue = (raw) => {
|
|
807
|
-
const headers = {};
|
|
808
|
-
const warnings = [];
|
|
809
|
-
let overflowed = false;
|
|
810
|
-
for (const [index, rawEntry] of raw.split(",").entries()) {
|
|
811
|
-
const position = String(index + 1);
|
|
812
|
-
const entry = rawEntry.trim();
|
|
813
|
-
if (entry === "") {
|
|
814
|
-
continue;
|
|
815
|
-
}
|
|
816
|
-
const equals = entry.indexOf("=");
|
|
817
|
-
if (equals <= 0) {
|
|
818
|
-
warnings.push(`entry ${position} is not a key=value pair; ignored`);
|
|
819
|
-
continue;
|
|
820
|
-
}
|
|
821
|
-
const key = decode(entry.slice(0, equals).trim());
|
|
822
|
-
const value = decode(entry.slice(equals + 1).trim());
|
|
823
|
-
if (key === void 0 || value === void 0) {
|
|
824
|
-
warnings.push(`entry ${position} has malformed percent-encoding; ignored`);
|
|
825
|
-
continue;
|
|
826
|
-
}
|
|
827
|
-
const name = key.trim();
|
|
828
|
-
const trimmedValue = value.trim();
|
|
829
|
-
if (!HEADER_NAME_PATTERN.test(name)) {
|
|
830
|
-
warnings.push(`entry ${position} does not name a valid HTTP header; ignored`);
|
|
831
|
-
continue;
|
|
832
|
-
}
|
|
833
|
-
if (trimmedValue === "") {
|
|
834
|
-
warnings.push(`entry ${position} has an empty value; ignored`);
|
|
835
|
-
continue;
|
|
836
|
-
}
|
|
837
|
-
if (isUnsafeHeaderValue(trimmedValue)) {
|
|
838
|
-
warnings.push(`entry ${position} has a character not allowed in an HTTP header value; ignored`);
|
|
839
|
-
continue;
|
|
840
|
-
}
|
|
841
|
-
const existing = findHeaderName(headers, name);
|
|
842
|
-
if (existing === void 0 && Object.keys(headers).length >= MAX_OTLP_HEADERS) {
|
|
843
|
-
overflowed = true;
|
|
844
|
-
continue;
|
|
845
|
-
}
|
|
846
|
-
if (existing !== void 0) {
|
|
847
|
-
delete headers[existing];
|
|
848
|
-
}
|
|
849
|
-
headers[name] = trimmedValue;
|
|
850
|
-
}
|
|
851
|
-
if (overflowed) {
|
|
852
|
-
warnings.push(`more than ${String(MAX_OTLP_HEADERS)} headers were supplied; the excess was ignored`);
|
|
853
|
-
}
|
|
854
|
-
return { headers, warnings };
|
|
855
|
-
};
|
|
856
|
-
var findHeaderName = (headers, name) => {
|
|
857
|
-
const lower = name.toLowerCase();
|
|
858
|
-
return Object.keys(headers).find((candidate) => candidate.toLowerCase() === lower);
|
|
859
|
-
};
|
|
860
|
-
var mergeOtlpHeaders = (...sources) => {
|
|
861
|
-
const merged = {};
|
|
862
|
-
for (const source of sources) {
|
|
863
|
-
for (const [name, value] of Object.entries(source)) {
|
|
864
|
-
const existing = findHeaderName(merged, name);
|
|
865
|
-
if (existing !== void 0) {
|
|
866
|
-
delete merged[existing];
|
|
867
|
-
}
|
|
868
|
-
merged[name] = value;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
return merged;
|
|
872
|
-
};
|
|
873
|
-
var resolveOtlpHeaders = (env, explicit = {}) => {
|
|
874
|
-
const warnings = [];
|
|
875
|
-
const read = (variable) => {
|
|
876
|
-
const raw = env[variable];
|
|
877
|
-
if (raw === void 0 || raw.trim() === "") {
|
|
878
|
-
return {};
|
|
879
|
-
}
|
|
880
|
-
const parsed = parseOtlpHeadersValue(raw);
|
|
881
|
-
for (const detail of parsed.warnings) {
|
|
882
|
-
warnings.push({ variable, detail });
|
|
883
|
-
}
|
|
884
|
-
return parsed.headers;
|
|
885
|
-
};
|
|
886
|
-
const generic = read(OTLP_HEADER_VARIABLES.generic);
|
|
887
|
-
const traces = read(OTLP_HEADER_VARIABLES.traces);
|
|
888
|
-
const logs = read(OTLP_HEADER_VARIABLES.logs);
|
|
889
|
-
return {
|
|
890
|
-
traces: mergeOtlpHeaders(generic, traces, explicit),
|
|
891
|
-
logs: mergeOtlpHeaders(generic, logs, explicit),
|
|
892
|
-
warnings
|
|
893
|
-
};
|
|
894
|
-
};
|
|
895
|
-
var unionOtlpHeaderNames = (...lists) => {
|
|
896
|
-
const names = [];
|
|
897
|
-
const seen = /* @__PURE__ */ new Set();
|
|
898
|
-
for (const name of lists.flat()) {
|
|
899
|
-
if (!seen.has(name.toLowerCase())) {
|
|
900
|
-
seen.add(name.toLowerCase());
|
|
901
|
-
names.push(name);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
return names.sort().slice(0, MAX_OTLP_HEADERS);
|
|
905
|
-
};
|
|
906
|
-
var describeOtlpHeaderNames = (...sources) => unionOtlpHeaderNames(...sources.map((source) => Object.keys(source)));
|
|
907
|
-
|
|
908
1193
|
// src/config/environment.ts
|
|
909
1194
|
var ENVIRONMENT_VARIABLES = Object.freeze({
|
|
910
1195
|
exporterEnabled: "OTEL_HOOK_ENABLED",
|
|
@@ -936,7 +1221,9 @@ var ENVIRONMENT_VARIABLES = Object.freeze({
|
|
|
936
1221
|
maxArrayLength: "OTEL_HOOK_MAX_ARRAY_LENGTH",
|
|
937
1222
|
maxEventsPerInvocation: "OTEL_HOOK_MAX_EVENTS_PER_INVOCATION",
|
|
938
1223
|
minimumConfidence: "OTEL_HOOK_MIN_DETECTION_CONFIDENCE",
|
|
939
|
-
logLevel: "OTEL_HOOK_LOG_LEVEL"
|
|
1224
|
+
logLevel: "OTEL_HOOK_LOG_LEVEL",
|
|
1225
|
+
/** `providers.claudeCode.readTranscriptUsage`; see `providersPolicySchema`. */
|
|
1226
|
+
claudeTranscriptUsage: "OTEL_HOOK_CLAUDE_TRANSCRIPT_USAGE"
|
|
940
1227
|
});
|
|
941
1228
|
var BOOLEAN_TRUE = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
942
1229
|
var BOOLEAN_FALSE = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
|
|
@@ -1113,23 +1400,33 @@ var parseEnvironmentConfig = (env) => {
|
|
|
1113
1400
|
};
|
|
1114
1401
|
const detection = confidenceParsed?.success === true ? { minimumConfidence: confidenceParsed.data } : {};
|
|
1115
1402
|
const diagnostics = logLevel === void 0 ? {} : { logLevel };
|
|
1403
|
+
const claudeTranscriptUsage = readBoolean(ENVIRONMENT_VARIABLES.claudeTranscriptUsage);
|
|
1404
|
+
const providers = claudeTranscriptUsage === void 0 ? {} : { claudeCode: { readTranscriptUsage: claudeTranscriptUsage } };
|
|
1116
1405
|
const patch = {
|
|
1117
1406
|
...Object.keys(exporter).length === 0 ? {} : { exporter },
|
|
1118
1407
|
...Object.keys(privacy).length === 0 ? {} : { privacy },
|
|
1119
1408
|
...Object.keys(detection).length === 0 ? {} : { detection },
|
|
1120
|
-
...Object.keys(diagnostics).length === 0 ? {} : { diagnostics }
|
|
1409
|
+
...Object.keys(diagnostics).length === 0 ? {} : { diagnostics },
|
|
1410
|
+
...Object.keys(providers).length === 0 ? {} : { providers }
|
|
1121
1411
|
};
|
|
1122
1412
|
return { patch, warnings };
|
|
1123
1413
|
};
|
|
1124
1414
|
export {
|
|
1125
1415
|
CONFIG_SOURCE_PRECEDENCE,
|
|
1126
1416
|
DEFAULT_CONFIG,
|
|
1417
|
+
DEFAULT_DESTINATION_NAME,
|
|
1127
1418
|
DEFAULT_DETECTION_POLICY,
|
|
1128
1419
|
DEFAULT_DIAGNOSTICS_POLICY,
|
|
1129
1420
|
DEFAULT_EXPORTER_POLICY,
|
|
1130
1421
|
DEFAULT_LOGS_POLICY,
|
|
1422
|
+
DEFAULT_PROVIDERS_POLICY,
|
|
1423
|
+
DEFAULT_SPOOL_POLICY,
|
|
1424
|
+
DESTINATION_NAME_PATTERN,
|
|
1131
1425
|
EMPTY_RESOURCE_ATTRIBUTES,
|
|
1132
1426
|
ENVIRONMENT_VARIABLES,
|
|
1427
|
+
HEADER_ENV_REFERENCE_PREFIX,
|
|
1428
|
+
MAX_DESTINATION_HEADERS,
|
|
1429
|
+
MAX_EXPORT_DESTINATIONS,
|
|
1133
1430
|
MAX_OTLP_HEADERS,
|
|
1134
1431
|
MAX_RESOURCE_ATTRIBUTES,
|
|
1135
1432
|
MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH,
|
|
@@ -1142,12 +1439,19 @@ export {
|
|
|
1142
1439
|
checkResourceAttributeKey,
|
|
1143
1440
|
configSourceSchema,
|
|
1144
1441
|
contentModeSchema,
|
|
1442
|
+
describeExportDestinations,
|
|
1145
1443
|
describeOtlpHeaderNames,
|
|
1146
1444
|
describeResolvedConfig,
|
|
1147
1445
|
describeResourceAttributeNames,
|
|
1148
1446
|
detectionPolicySchema,
|
|
1149
1447
|
diagnosticsPolicySchema,
|
|
1448
|
+
effectiveSpoolPolicy,
|
|
1449
|
+
endpointOrigin,
|
|
1450
|
+
exportDestinationSchema,
|
|
1451
|
+
exportDestinationsSchema,
|
|
1452
|
+
exportSignalSchema,
|
|
1150
1453
|
exporterPolicySchema,
|
|
1454
|
+
hasConfiguredDestinations,
|
|
1151
1455
|
isReservedResourceAttributeKey,
|
|
1152
1456
|
isSecretResourceAttributeKey,
|
|
1153
1457
|
logsPolicySchema,
|
|
@@ -1156,13 +1460,19 @@ export {
|
|
|
1156
1460
|
otelHookConfigSchema,
|
|
1157
1461
|
otlpSignalEndpointFromBase,
|
|
1158
1462
|
parseEnvironmentConfig,
|
|
1463
|
+
parseHeaderValueReference,
|
|
1159
1464
|
parseOtlpHeadersValue,
|
|
1160
1465
|
parseResourceAttributesValue,
|
|
1466
|
+
providersPolicySchema,
|
|
1467
|
+
readsClaudeTranscriptUsage,
|
|
1161
1468
|
resolveConfig,
|
|
1469
|
+
resolveDestinationHeaders,
|
|
1470
|
+
resolveExportDestinations,
|
|
1162
1471
|
resolveOtlpHeaders,
|
|
1163
1472
|
resourceAttributeValueSchema,
|
|
1164
1473
|
resourceAttributesSchema,
|
|
1165
1474
|
sanitizeResourceAttributes,
|
|
1475
|
+
spoolPolicySchema,
|
|
1166
1476
|
unionOtlpHeaderNames
|
|
1167
1477
|
};
|
|
1168
1478
|
//# sourceMappingURL=config.js.map
|