managed-deepagents 0.9.5-dev.4 → 0.9.5-dev.5

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 (78) hide show
  1. package/dist/channels/http/http.d.ts.map +1 -1
  2. package/dist/channels/http/http.js +4 -4
  3. package/dist/channels/http/http.js.map +1 -1
  4. package/dist/channels/schedule-delivery.d.ts.map +1 -1
  5. package/dist/channels/schedule-delivery.js +3 -3
  6. package/dist/channels/schedule-delivery.js.map +1 -1
  7. package/dist/channels/trigger/http.d.ts.map +1 -1
  8. package/dist/channels/trigger/http.js +10 -3
  9. package/dist/channels/trigger/http.js.map +1 -1
  10. package/dist/concurrency/batch-processor.d.ts +51 -0
  11. package/dist/concurrency/batch-processor.d.ts.map +1 -0
  12. package/dist/concurrency/batch-processor.js +99 -0
  13. package/dist/concurrency/batch-processor.js.map +1 -0
  14. package/dist/identity/loopback.d.ts +5 -0
  15. package/dist/identity/loopback.d.ts.map +1 -1
  16. package/dist/identity/loopback.js +9 -0
  17. package/dist/identity/loopback.js.map +1 -1
  18. package/dist/ingress/index.d.ts +8 -0
  19. package/dist/ingress/index.d.ts.map +1 -1
  20. package/dist/ingress/index.js +32 -2
  21. package/dist/ingress/index.js.map +1 -1
  22. package/dist/ingress/runs.d.ts.map +1 -1
  23. package/dist/ingress/runs.js +13 -0
  24. package/dist/ingress/runs.js.map +1 -1
  25. package/dist/resilience/retry.d.ts +21 -0
  26. package/dist/resilience/retry.d.ts.map +1 -0
  27. package/dist/resilience/retry.js +40 -0
  28. package/dist/resilience/retry.js.map +1 -0
  29. package/dist/runtime/http.d.ts +15 -0
  30. package/dist/runtime/http.d.ts.map +1 -1
  31. package/dist/runtime/http.js +37 -0
  32. package/dist/runtime/http.js.map +1 -1
  33. package/dist/runtime/identity-http.d.ts.map +1 -1
  34. package/dist/runtime/identity-http.js +5 -4
  35. package/dist/runtime/identity-http.js.map +1 -1
  36. package/dist/runtime/log.d.ts +8 -14
  37. package/dist/runtime/log.d.ts.map +1 -1
  38. package/dist/runtime/log.js +16 -7
  39. package/dist/runtime/log.js.map +1 -1
  40. package/dist/runtime/run-input.d.ts.map +1 -1
  41. package/dist/runtime/run-input.js +20 -2
  42. package/dist/runtime/run-input.js.map +1 -1
  43. package/dist/runtime/sandbox-manager.d.ts.map +1 -1
  44. package/dist/runtime/sandbox-manager.js +3 -5
  45. package/dist/runtime/sandbox-manager.js.map +1 -1
  46. package/dist/telemetry/lifecycle.d.ts +26 -0
  47. package/dist/telemetry/lifecycle.d.ts.map +1 -0
  48. package/dist/telemetry/lifecycle.js +49 -0
  49. package/dist/telemetry/lifecycle.js.map +1 -0
  50. package/dist/telemetry/otel/context.d.ts +57 -0
  51. package/dist/telemetry/otel/context.d.ts.map +1 -0
  52. package/dist/telemetry/otel/context.js +122 -0
  53. package/dist/telemetry/otel/context.js.map +1 -0
  54. package/dist/telemetry/otel/exporter.d.ts +53 -0
  55. package/dist/telemetry/otel/exporter.d.ts.map +1 -0
  56. package/dist/telemetry/otel/exporter.js +190 -0
  57. package/dist/telemetry/otel/exporter.js.map +1 -0
  58. package/dist/telemetry/otel/index.d.ts +6 -0
  59. package/dist/telemetry/otel/index.d.ts.map +1 -0
  60. package/dist/telemetry/otel/index.js +3 -0
  61. package/dist/telemetry/otel/index.js.map +1 -0
  62. package/dist/telemetry/otel/otlp.d.ts +44 -0
  63. package/dist/telemetry/otel/otlp.d.ts.map +1 -0
  64. package/dist/telemetry/otel/otlp.js +7 -0
  65. package/dist/telemetry/otel/otlp.js.map +1 -0
  66. package/dist/telemetry/otel/truncate.d.ts +10 -0
  67. package/dist/telemetry/otel/truncate.d.ts.map +1 -0
  68. package/dist/telemetry/otel/truncate.js +39 -0
  69. package/dist/telemetry/otel/truncate.js.map +1 -0
  70. package/dist/telemetry/run-listener.d.ts +1 -1
  71. package/dist/telemetry/run-listener.d.ts.map +1 -1
  72. package/dist/telemetry/run-listener.js +32 -2
  73. package/dist/telemetry/run-listener.js.map +1 -1
  74. package/dist/telemetry/transport/posthog.d.ts +13 -1
  75. package/dist/telemetry/transport/posthog.d.ts.map +1 -1
  76. package/dist/telemetry/transport/posthog.js +68 -30
  77. package/dist/telemetry/transport/posthog.js.map +1 -1
  78. package/package.json +7 -7
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Process shutdown for the telemetry sinks. Each sink registers a drain; on
3
+ * exit or SIGTERM/SIGINT they run in parallel under one shared deadline.
4
+ */
5
+ /**
6
+ * How long the drains get. Kubernetes allows 30s between SIGTERM and SIGKILL
7
+ * by default (`terminationGracePeriodSeconds`), and the server's own drain uses
8
+ * part of it; 5s fits alongside and matches Fluent Bit's default `Grace`.
9
+ */
10
+ export declare const SHUTDOWN_DEADLINE_MS = 5000;
11
+ /** Sends what a sink holds, giving up after `deadlineMs`. */
12
+ export type Drain = (deadlineMs: number) => Promise<void>;
13
+ /** The parts of `process` the hooks use, so tests can pass their own. */
14
+ export interface ShutdownProcess {
15
+ readonly pid: number;
16
+ once(event: "beforeExit" | NodeJS.Signals, listener: () => void): unknown;
17
+ listenerCount(event: NodeJS.Signals): number;
18
+ kill(pid: number, signal: NodeJS.Signals): unknown;
19
+ }
20
+ /** Run `drain` at shutdown. The first registration installs the hooks. */
21
+ export declare function onShutdown(drain: Drain, target?: ShutdownProcess): void;
22
+ /** Drain every registered sink in parallel. Runs once; later calls share it. */
23
+ export declare function shutdownTelemetry(deadlineMs?: number): Promise<void>;
24
+ /** @internal Forget registrations and hooks between tests. */
25
+ export declare function resetShutdownForTests(): void;
26
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/telemetry/lifecycle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAE1C,6DAA6D;AAC7D,MAAM,MAAM,KAAK,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1D,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC;IAC1E,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IAC7C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;CACpD;AAQD,0EAA0E;AAC1E,wBAAgB,UAAU,CACxB,KAAK,EAAE,KAAK,EACZ,MAAM,GAAE,eAAyB,GAChC,IAAI,CAoBN;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAC/B,UAAU,GAAE,MAA6B,GACxC,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,8DAA8D;AAC9D,wBAAgB,qBAAqB,IAAI,IAAI,CAI5C"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Process shutdown for the telemetry sinks. Each sink registers a drain; on
3
+ * exit or SIGTERM/SIGINT they run in parallel under one shared deadline.
4
+ */
5
+ /**
6
+ * How long the drains get. Kubernetes allows 30s between SIGTERM and SIGKILL
7
+ * by default (`terminationGracePeriodSeconds`), and the server's own drain uses
8
+ * part of it; 5s fits alongside and matches Fluent Bit's default `Grace`.
9
+ */
10
+ export const SHUTDOWN_DEADLINE_MS = 5_000;
11
+ const SIGNALS = ["SIGTERM", "SIGINT"];
12
+ const drains = [];
13
+ let hooked = false;
14
+ let shuttingDown;
15
+ /** Run `drain` at shutdown. The first registration installs the hooks. */
16
+ export function onShutdown(drain, target = process) {
17
+ drains.push(drain);
18
+ if (hooked)
19
+ return;
20
+ hooked = true;
21
+ target.once("beforeExit", () => {
22
+ shutdownTelemetry().catch(() => undefined);
23
+ });
24
+ for (const signal of SIGNALS) {
25
+ target.once(signal, () => {
26
+ shutdownTelemetry()
27
+ .then(() => {
28
+ // Listening suppressed the default exit; restore it unless someone
29
+ // else now owns the signal.
30
+ if (target.listenerCount(signal) === 0) {
31
+ target.kill(target.pid, signal);
32
+ }
33
+ })
34
+ .catch(() => undefined);
35
+ });
36
+ }
37
+ }
38
+ /** Drain every registered sink in parallel. Runs once; later calls share it. */
39
+ export function shutdownTelemetry(deadlineMs = SHUTDOWN_DEADLINE_MS) {
40
+ shuttingDown ??= Promise.allSettled(drains.map(async (drain) => drain(deadlineMs))).then(() => undefined);
41
+ return shuttingDown;
42
+ }
43
+ /** @internal Forget registrations and hooks between tests. */
44
+ export function resetShutdownForTests() {
45
+ drains.length = 0;
46
+ hooked = false;
47
+ shuttingDown = undefined;
48
+ }
49
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/telemetry/lifecycle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAa1C,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAU,CAAC;AAE/C,MAAM,MAAM,GAAY,EAAE,CAAC;AAC3B,IAAI,MAAM,GAAG,KAAK,CAAC;AACnB,IAAI,YAAuC,CAAC;AAE5C,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CACxB,KAAY,EACZ,MAAM,GAAoB,OAAO;IAEjC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,IAAI,MAAM;QAAE,OAAO;IACnB,MAAM,GAAG,IAAI,CAAC;IACd,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE;QAC7B,iBAAiB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IACH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;YACvB,iBAAiB,EAAE;iBAChB,IAAI,CAAC,GAAG,EAAE;gBACT,mEAAmE;gBACnE,4BAA4B;gBAC5B,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;oBACvC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,iBAAiB,CAC/B,UAAU,GAAW,oBAAoB;IAEzC,YAAY,KAAK,OAAO,CAAC,UAAU,CACjC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAC/C,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACxB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,qBAAqB;IACnC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,MAAM,GAAG,KAAK,CAAC;IACf,YAAY,GAAG,SAAS,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,57 @@
1
+ /** Run metadata key that carries the trace id from ingress into the run. */
2
+ export declare const TRACE_ID_METADATA_KEY = "mda_trace_id";
3
+ export type LogSeverity = "INFO" | "WARN" | "ERROR";
4
+ export type LogAttributeValue = string | number | boolean;
5
+ export type LogAttributes = Record<string, LogAttributeValue>;
6
+ export interface LogRecord {
7
+ /**
8
+ * Unique to this record and kept across retries, so copies of a batch sent
9
+ * twice can be told apart from distinct records.
10
+ */
11
+ uid: string;
12
+ timeUnixNano: string;
13
+ severity: LogSeverity;
14
+ body: string;
15
+ attributes: LogAttributes;
16
+ traceId: string;
17
+ spanId: string;
18
+ }
19
+ export interface LogContext {
20
+ traceId: string;
21
+ spanId: string;
22
+ /** Attached to every later record, so a fact learned mid-request sticks. */
23
+ attributes: LogAttributes;
24
+ /** Work that outlives the request; ingress completes after it settles. */
25
+ pending: Promise<unknown>[];
26
+ }
27
+ /** A fresh 16-byte trace id as 32 lowercase hex characters. */
28
+ export declare function newTraceId(): string;
29
+ /** A fresh 8-byte span id as 16 lowercase hex characters. */
30
+ export declare function newSpanId(): string;
31
+ /** The trace id of a W3C `traceparent` header, or a new one. */
32
+ export declare function traceIdFromTraceparent(header: string | null | undefined): string;
33
+ /** A trace id handed over through run metadata, or a new one. */
34
+ export declare function traceIdFromMetadata(metadata: Record<string, unknown> | undefined): string;
35
+ /** A new, empty log context for `traceId` with its own span id. */
36
+ export declare function createLogContext(traceId: string): LogContext;
37
+ /** Run `fn` inside `context`. */
38
+ export declare function runInLogContext<T>(context: LogContext, fn: () => T): T;
39
+ /** Run `fn` with a new log context for `traceId`. */
40
+ export declare function withLogContext<T>(traceId: string, fn: (context: LogContext) => T): T;
41
+ export declare function currentLogContext(): LogContext | undefined;
42
+ /** Keep the current context open until `work` settles. */
43
+ export declare function holdLogContext(work: Promise<unknown>): void;
44
+ /** Add attributes to the current context's later records. */
45
+ export declare function setLogAttributes(attributes: Record<string, LogAttributeValue | null | undefined>): void;
46
+ /** OTel `exception.*` attributes for an error. */
47
+ export declare function exceptionAttributes(error: unknown): LogAttributes;
48
+ /**
49
+ * Queue a record under the current context's ids on the process-wide log
50
+ * sink, with the middle cut out of any string over the per-value limit. Does
51
+ * nothing outside a context or when the sink is disabled.
52
+ */
53
+ export declare function recordLog(severity: LogSeverity, body: string, options?: {
54
+ error?: unknown;
55
+ attributes?: LogAttributes;
56
+ }): void;
57
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/telemetry/otel/context.ts"],"names":[],"mappings":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,MAAM,CAAC,GAAG,CAAC,CAEtE;AAED,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,CAAC,GAC7B,CAAC,CAGH;AAED,wBAAgB,iBAAiB,IAAI,UAAU,GAAG,SAAS,CAE1D;AAED,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAE3D;AAED,6DAA6D;AAC7D,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAAC,GAC/D,IAAI,CAQN;AAED,kDAAkD;AAClD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAYjE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,aAAa,CAAA;CAAO,GAC5D,IAAI,CAqBN"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Per-request log context for the OTel log forwarder.
3
+ *
4
+ * Ingress and the run execute in different processes, so each holds its own
5
+ * context, and records go straight to the process-wide log sink stamped with
6
+ * that context's ids. Both share one trace id: ingress takes
7
+ * it from the incoming `traceparent` (or mints one) and hands it to the run as
8
+ * `config.metadata.mda_trace_id`. Each side gets its own span id so Datadog can
9
+ * tell which process wrote a record.
10
+ */
11
+ import { AsyncLocalStorage } from "node:async_hooks";
12
+ import { randomBytes, randomUUID } from "node:crypto";
13
+ import { logSink } from "./exporter.js";
14
+ import { truncateMiddle } from "./truncate.js";
15
+ /** Run metadata key that carries the trace id from ingress into the run. */
16
+ export const TRACE_ID_METADATA_KEY = "mda_trace_id";
17
+ const storage = new AsyncLocalStorage();
18
+ const TRACE_ID = /^[0-9a-f]{32}$/;
19
+ const TRACEPARENT = /^[0-9a-f]{2}-([0-9a-f]{32})-[0-9a-f]{16}-[0-9a-f]{2}$/;
20
+ function isValidTraceId(value) {
21
+ return TRACE_ID.test(value) && !/^0+$/.test(value);
22
+ }
23
+ /** A fresh 16-byte trace id as 32 lowercase hex characters. */
24
+ export function newTraceId() {
25
+ return randomBytes(16).toString("hex");
26
+ }
27
+ /** A fresh 8-byte span id as 16 lowercase hex characters. */
28
+ export function newSpanId() {
29
+ return randomBytes(8).toString("hex");
30
+ }
31
+ /** The trace id of a W3C `traceparent` header, or a new one. */
32
+ export function traceIdFromTraceparent(header) {
33
+ const traceId = TRACEPARENT.exec(header?.trim().toLowerCase() ?? "")?.[1];
34
+ return traceId && isValidTraceId(traceId) ? traceId : newTraceId();
35
+ }
36
+ /** A trace id handed over through run metadata, or a new one. */
37
+ export function traceIdFromMetadata(metadata) {
38
+ const value = metadata?.[TRACE_ID_METADATA_KEY];
39
+ return typeof value === "string" && isValidTraceId(value)
40
+ ? value
41
+ : newTraceId();
42
+ }
43
+ /** A new, empty log context for `traceId` with its own span id. */
44
+ export function createLogContext(traceId) {
45
+ return {
46
+ traceId,
47
+ spanId: newSpanId(),
48
+ attributes: {},
49
+ pending: [],
50
+ };
51
+ }
52
+ /** Run `fn` inside `context`. */
53
+ export function runInLogContext(context, fn) {
54
+ return storage.run(context, fn);
55
+ }
56
+ /** Run `fn` with a new log context for `traceId`. */
57
+ export function withLogContext(traceId, fn) {
58
+ const context = createLogContext(traceId);
59
+ return storage.run(context, () => fn(context));
60
+ }
61
+ export function currentLogContext() {
62
+ return storage.getStore();
63
+ }
64
+ /** Keep the current context open until `work` settles. */
65
+ export function holdLogContext(work) {
66
+ currentLogContext()?.pending.push(work);
67
+ }
68
+ /** Add attributes to the current context's later records. */
69
+ export function setLogAttributes(attributes) {
70
+ const context = currentLogContext();
71
+ if (!context)
72
+ return;
73
+ for (const [key, value] of Object.entries(attributes)) {
74
+ if (value !== null && value !== undefined) {
75
+ context.attributes[key] = value;
76
+ }
77
+ }
78
+ }
79
+ /** OTel `exception.*` attributes for an error. */
80
+ export function exceptionAttributes(error) {
81
+ if (!(error instanceof Error)) {
82
+ return { "exception.type": typeof error };
83
+ }
84
+ const attributes = {
85
+ "exception.type": error.name,
86
+ "exception.message": error.message,
87
+ };
88
+ if (error.stack) {
89
+ attributes["exception.stacktrace"] = error.stack;
90
+ }
91
+ return attributes;
92
+ }
93
+ /**
94
+ * Queue a record under the current context's ids on the process-wide log
95
+ * sink, with the middle cut out of any string over the per-value limit. Does
96
+ * nothing outside a context or when the sink is disabled.
97
+ */
98
+ export function recordLog(severity, body, options = {}) {
99
+ const context = currentLogContext();
100
+ const sink = logSink();
101
+ if (!context || !sink.enabled)
102
+ return;
103
+ const attributes = {
104
+ ...context.attributes,
105
+ ...options.attributes,
106
+ ...(options.error === undefined ? {} : exceptionAttributes(options.error)),
107
+ };
108
+ for (const [key, value] of Object.entries(attributes)) {
109
+ if (typeof value === "string")
110
+ attributes[key] = truncateMiddle(value);
111
+ }
112
+ sink.push({
113
+ uid: randomUUID(),
114
+ timeUnixNano: `${BigInt(Date.now()) * 1000000n}`,
115
+ severity,
116
+ body: truncateMiddle(body),
117
+ attributes,
118
+ traceId: context.traceId,
119
+ spanId: context.spanId,
120
+ });
121
+ }
122
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/telemetry/otel/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,qBAAqB,GA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MAAM;KACvB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { RetryPolicy } from "../../resilience/retry.js";
2
+ import type { LogRecord } from "./context.js";
3
+ import type { ExportLogsServiceRequest, OtlpLogRecord } from "./otlp.js";
4
+ /** The collection endpoint accepts at most this many records per request. */
5
+ export declare const MAX_RECORDS_PER_REQUEST = 200;
6
+ /** Encoded records per request, under the endpoint's 5MB body limit. */
7
+ export declare const MAX_REQUEST_BYTES: number;
8
+ export interface OtelLogConfig {
9
+ url: string;
10
+ headers: Record<string, string>;
11
+ }
12
+ /**
13
+ * Where and how to send logs, or `undefined` when logs must not be sent:
14
+ * telemetry is off, the process is not a LangSmith deployment, there is no
15
+ * key, or the key would cross the network in cleartext.
16
+ */
17
+ export declare function resolveOtelLogConfig(env?: Record<string, string | undefined>): OtelLogConfig | undefined;
18
+ export declare function toOtlpLogRecord(record: LogRecord): OtlpLogRecord;
19
+ /**
20
+ * One OTLP `ExportLogsServiceRequest`. Records from many contexts can share a
21
+ * request; each keeps its own trace and span ids.
22
+ */
23
+ export declare function encodeLogs(records: OtlpLogRecord[], serviceVersion?: string): ExportLogsServiceRequest;
24
+ /** Where records go once built. Never blocks or throws. */
25
+ export interface LogSink {
26
+ /** Whether pushed records go anywhere; when not, callers skip building them. */
27
+ readonly enabled: boolean;
28
+ push(record: LogRecord): void;
29
+ /** Resolves once every pushed record has been handled. */
30
+ idle(): Promise<void>;
31
+ /** Refuse new records and drain what is queued until `deadlineMs`. */
32
+ shutdown(deadlineMs: number): Promise<void>;
33
+ }
34
+ export interface LogSinkOptions {
35
+ env?: Record<string, string | undefined>;
36
+ fetch?: typeof fetch;
37
+ maxWaitMs?: number;
38
+ retry?: RetryPolicy;
39
+ }
40
+ /**
41
+ * A sink that batches records in the background and sends them to the
42
+ * collection endpoint. Drops everything when {@link resolveOtelLogConfig}
43
+ * returns nothing.
44
+ */
45
+ export declare function createLogSink(options?: LogSinkOptions): LogSink;
46
+ /**
47
+ * The process-wide sink, created on first use. When it exports, it drains at
48
+ * process shutdown.
49
+ */
50
+ export declare function logSink(): LogSink;
51
+ /** @internal Test-only sink override; `undefined` restores the default. */
52
+ export declare function setLogSinkForTests(override: LogSink | undefined): void;
53
+ //# sourceMappingURL=exporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../../../src/telemetry/otel/exporter.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAU7D,OAAO,KAAK,EAAoC,SAAS,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,KAAK,EACV,wBAAwB,EAGxB,aAAa,EACd,MAAM,WAAW,CAAC;AAUnB,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,QAAU,CAAC;AAOzC,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAMD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,aAAa,GAAG,SAAS,CAwB3B;AAmBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa,CAahE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,aAAa,EAAE,EACxB,cAAc,GAAE,MAAyB,GACxC,wBAAwB,CAgB1B;AAWD,2DAA2D;AAC3D,MAAM,WAAW,OAAO;IACtB,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,0DAA0D;IAC1D,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,sEAAsE;IACtE,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AASD,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAsBnE;AA0BD;;;GAGG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAOjC;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAEtE"}
@@ -0,0 +1,190 @@
1
+ /**
2
+ * The process-wide log sink: sends records from every log context to the
3
+ * LangSmith MDA log collection endpoint as OTLP/HTTP JSON, which forwards them
4
+ * to Datadog.
5
+ *
6
+ * Built on our own `BatchProcessor` and `withRetry` rather than the OTel SDK.
7
+ * PostHog events need the same batching and retry, so both sinks share one
8
+ * mechanism, and the Python runtime mirrors it.
9
+ */
10
+ import { agentAuthHeaders } from "../../agent-auth.js";
11
+ import { resolveAgentAuthBaseUrl } from "../../connections.js";
12
+ import { sendsKeySecurely } from "../../identity/loopback.js";
13
+ import { BatchProcessor } from "../../concurrency/batch-processor.js";
14
+ import { withRetry } from "../../resilience/retry.js";
15
+ import { fetchWithTimeout, HttpStatusError, isRetryable, requestedDelayMs, } from "../../runtime/http.js";
16
+ import { isTelemetryDisabled } from "../gates.js";
17
+ import { onShutdown } from "../lifecycle.js";
18
+ import { packageVersion } from "../metadata.js";
19
+ const LOGS_PATH = "/v1/platform/mda/otel/v1/logs";
20
+ const SERVICE_NAME = "mda-node";
21
+ /** Bounds one export request; the OTel exporters' default. */
22
+ const EXPORT_TIMEOUT_MS = 10_000;
23
+ /** How long a partial batch waits for more records. */
24
+ const BATCH_WAIT_MS = 1_000;
25
+ /** Records waiting to send; later ones are dropped. */
26
+ const MAX_QUEUED_RECORDS = 10_000;
27
+ /** The collection endpoint accepts at most this many records per request. */
28
+ export const MAX_RECORDS_PER_REQUEST = 200;
29
+ /** Encoded records per request, under the endpoint's 5MB body limit. */
30
+ export const MAX_REQUEST_BYTES = 4 << 20;
31
+ /** OTel semantic-convention attribute for a log record's unique id. */
32
+ const RECORD_UID_KEY = "log.record.uid";
33
+ const SEVERITY_NUMBER = { INFO: 9, WARN: 13, ERROR: 17 };
34
+ function nonempty(value) {
35
+ return value?.trim() || undefined;
36
+ }
37
+ /**
38
+ * Where and how to send logs, or `undefined` when logs must not be sent:
39
+ * telemetry is off, the process is not a LangSmith deployment, there is no
40
+ * key, or the key would cross the network in cleartext.
41
+ */
42
+ export function resolveOtelLogConfig(env = process.env) {
43
+ if (isTelemetryDisabled(env))
44
+ return undefined;
45
+ if (env.MDA_LOCAL_DEV === "1" || !nonempty(env.LANGSMITH_HOST_PROJECT_ID)) {
46
+ return undefined;
47
+ }
48
+ const apiKey = nonempty(env.LANGSMITH_API_KEY) ?? nonempty(env.LANGCHAIN_API_KEY);
49
+ if (!apiKey)
50
+ return undefined;
51
+ let url;
52
+ try {
53
+ url = new URL(LOGS_PATH, resolveAgentAuthBaseUrl(env));
54
+ }
55
+ catch {
56
+ return undefined;
57
+ }
58
+ if (!sendsKeySecurely(url))
59
+ return undefined;
60
+ return {
61
+ url: url.toString(),
62
+ headers: agentAuthHeaders({
63
+ apiKey,
64
+ workspaceId: nonempty(env.LANGSMITH_TENANT_ID) ??
65
+ nonempty(env.LANGSMITH_WORKSPACE_ID),
66
+ }),
67
+ };
68
+ }
69
+ function anyValue(value) {
70
+ if (typeof value === "boolean")
71
+ return { boolValue: value };
72
+ if (typeof value === "number") {
73
+ return Number.isInteger(value)
74
+ ? { intValue: String(value) }
75
+ : { doubleValue: value };
76
+ }
77
+ return { stringValue: value };
78
+ }
79
+ function keyValues(attributes) {
80
+ return Object.entries(attributes).map(([key, value]) => ({
81
+ key,
82
+ value: anyValue(value),
83
+ }));
84
+ }
85
+ export function toOtlpLogRecord(record) {
86
+ return {
87
+ timeUnixNano: record.timeUnixNano,
88
+ severityNumber: SEVERITY_NUMBER[record.severity],
89
+ severityText: record.severity,
90
+ body: { stringValue: record.body },
91
+ attributes: [
92
+ ...keyValues(record.attributes),
93
+ { key: RECORD_UID_KEY, value: { stringValue: record.uid } },
94
+ ],
95
+ traceId: record.traceId,
96
+ spanId: record.spanId,
97
+ };
98
+ }
99
+ /**
100
+ * One OTLP `ExportLogsServiceRequest`. Records from many contexts can share a
101
+ * request; each keeps its own trace and span ids.
102
+ */
103
+ export function encodeLogs(records, serviceVersion = packageVersion()) {
104
+ return {
105
+ resourceLogs: [
106
+ {
107
+ resource: {
108
+ attributes: keyValues({
109
+ "service.name": SERVICE_NAME,
110
+ "service.version": serviceVersion,
111
+ }),
112
+ },
113
+ scopeLogs: [
114
+ { scope: { name: "managed-deepagents" }, logRecords: records },
115
+ ],
116
+ },
117
+ ],
118
+ };
119
+ }
120
+ /** 429 and 5xx (including timeouts and network failures) are tried again. */
121
+ const EXPORT_RETRY = {
122
+ maxAttempts: 5,
123
+ baseDelayMs: 1_000,
124
+ maxDelayMs: 30_000,
125
+ retryOn: isRetryable,
126
+ delayFor: requestedDelayMs,
127
+ };
128
+ const NOOP_SINK = {
129
+ enabled: false,
130
+ push: () => undefined,
131
+ idle: async () => undefined,
132
+ shutdown: async () => undefined,
133
+ };
134
+ /**
135
+ * A sink that batches records in the background and sends them to the
136
+ * collection endpoint. Drops everything when {@link resolveOtelLogConfig}
137
+ * returns nothing.
138
+ */
139
+ export function createLogSink(options = {}) {
140
+ const config = resolveOtelLogConfig(options.env);
141
+ if (!config)
142
+ return NOOP_SINK;
143
+ const processor = new BatchProcessor({
144
+ handle: withRetry((batch, signal) => postLogs(config, batch, signal, options.fetch), options.retry ?? EXPORT_RETRY),
145
+ maxBatchSize: MAX_RECORDS_PER_REQUEST,
146
+ maxBatchBytes: MAX_REQUEST_BYTES,
147
+ sizeOf: (record) => Buffer.byteLength(JSON.stringify(record)),
148
+ maxWaitMs: options.maxWaitMs ?? BATCH_WAIT_MS,
149
+ maxQueued: MAX_QUEUED_RECORDS,
150
+ });
151
+ return {
152
+ enabled: true,
153
+ push: (record) => {
154
+ processor.push(toOtlpLogRecord(record));
155
+ },
156
+ idle: () => processor.idle(),
157
+ shutdown: (deadlineMs) => processor.shutdown(deadlineMs),
158
+ };
159
+ }
160
+ async function postLogs(config, batch, signal, fetchImpl) {
161
+ const response = await fetchWithTimeout(config.url, {
162
+ method: "POST",
163
+ headers: config.headers,
164
+ body: JSON.stringify(encodeLogs(batch)),
165
+ redirect: "error",
166
+ signal,
167
+ }, EXPORT_TIMEOUT_MS, fetchImpl);
168
+ await response.body?.cancel();
169
+ if (!response.ok)
170
+ throw HttpStatusError.from(response);
171
+ }
172
+ let sink;
173
+ /**
174
+ * The process-wide sink, created on first use. When it exports, it drains at
175
+ * process shutdown.
176
+ */
177
+ export function logSink() {
178
+ if (!sink) {
179
+ const created = createLogSink();
180
+ if (created !== NOOP_SINK)
181
+ onShutdown((ms) => created.shutdown(ms));
182
+ sink = created;
183
+ }
184
+ return sink;
185
+ }
186
+ /** @internal Test-only sink override; `undefined` restores the default. */
187
+ export function setLogSinkForTests(override) {
188
+ sink = override;
189
+ }
190
+ //# sourceMappingURL=exporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter.js","sourceRoot":"","sources":["../../../src/telemetry/otel/exporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,s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C,MAAM,CAAC,GAAG,EACV;QACE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACvC,QAAQ,EAAE,OAAO;QACjB,MAAM;KACP,EACD,iBAAiB,EACjB,SAAS,CACV,CAAC;IACF,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAC9B,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACzD,CAAC;AAED,IAAI,IAAyB,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,OAAO;IACrB,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;QAChC,IAAI,OAAO,KAAK,SAAS;YAAE,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QACpE,IAAI,GAAG,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,QAA6B;IAC9D,IAAI,GAAG,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { createLogContext, currentLogContext, exceptionAttributes, holdLogContext, newSpanId, newTraceId, recordLog, runInLogContext, setLogAttributes, TRACE_ID_METADATA_KEY, traceIdFromMetadata, traceIdFromTraceparent, withLogContext, } from "./context.js";
2
+ export type { LogAttributes, LogAttributeValue, LogContext, LogRecord, LogSeverity, } from "./context.js";
3
+ export { createLogSink, encodeLogs, logSink, MAX_RECORDS_PER_REQUEST, MAX_REQUEST_BYTES, resolveOtelLogConfig, setLogSinkForTests, toOtlpLogRecord, } from "./exporter.js";
4
+ export type { LogSink, LogSinkOptions, OtelLogConfig } from "./exporter.js";
5
+ export type { ExportLogsServiceRequest, OtlpAnyValue, OtlpKeyValue, OtlpLogRecord, OtlpResourceLogs, OtlpScopeLogs, } from "./otlp.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telemetry/otel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,SAAS,EACT,UAAU,EACV,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,UAAU,EACV,OAAO,EACP,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC5E,YAAY,EACV,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,aAAa,GACd,MAAM,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createLogContext, currentLogContext, exceptionAttributes, holdLogContext, newSpanId, newTraceId, recordLog, runInLogContext, setLogAttributes, TRACE_ID_METADATA_KEY, traceIdFromMetadata, traceIdFromTraceparent, withLogContext, } from "./context.js";
2
+ export { createLogSink, encodeLogs, logSink, MAX_RECORDS_PER_REQUEST, MAX_REQUEST_BYTES, resolveOtelLogConfig, setLogSinkForTests, toOtlpLogRecord, } from "./exporter.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/telemetry/otel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,SAAS,EACT,UAAU,EACV,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,GACf,MAAM,cAAc,CAAC;AAQtB,OAAO,EACL,aAAa,EACb,UAAU,EACV,OAAO,EACP,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,GAChB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The OTLP/HTTP JSON shapes the log collection endpoint accepts: the subset of
3
+ * `ExportLogsServiceRequest` this runtime sends. Field names follow the OTLP
4
+ * JSON encoding (lowerCamelCase; 64-bit integers as decimal strings).
5
+ */
6
+ export type OtlpAnyValue = {
7
+ stringValue: string;
8
+ } | {
9
+ boolValue: boolean;
10
+ } | {
11
+ intValue: string;
12
+ } | {
13
+ doubleValue: number;
14
+ };
15
+ export interface OtlpKeyValue {
16
+ key: string;
17
+ value: OtlpAnyValue;
18
+ }
19
+ /** One record, carrying its own context's trace and span ids. */
20
+ export interface OtlpLogRecord {
21
+ timeUnixNano: string;
22
+ severityNumber: number;
23
+ severityText: string;
24
+ body: OtlpAnyValue;
25
+ attributes: OtlpKeyValue[];
26
+ traceId: string;
27
+ spanId: string;
28
+ }
29
+ export interface OtlpScopeLogs {
30
+ scope: {
31
+ name: string;
32
+ };
33
+ logRecords: OtlpLogRecord[];
34
+ }
35
+ export interface OtlpResourceLogs {
36
+ resource: {
37
+ attributes: OtlpKeyValue[];
38
+ };
39
+ scopeLogs: OtlpScopeLogs[];
40
+ }
41
+ export interface ExportLogsServiceRequest {
42
+ resourceLogs: OtlpResourceLogs[];
43
+ }
44
+ //# sourceMappingURL=otlp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otlp.d.ts","sourceRoot":"","sources":["../../../src/telemetry/otel/otlp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,YAAY,GACpB;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GACvB;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,GACtB;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GACpB;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5B,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,UAAU,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE;QAAE,UAAU,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IACzC,SAAS,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The OTLP/HTTP JSON shapes the log collection endpoint accepts: the subset of
3
+ * `ExportLogsServiceRequest` this runtime sends. Field names follow the OTLP
4
+ * JSON encoding (lowerCamelCase; 64-bit integers as decimal strings).
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=otlp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otlp.js","sourceRoot":"","sources":["../../../src/telemetry/otel/otlp.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Keeps a log value within the collection endpoint's per-value limit by
3
+ * cutting its middle, as the CLI does: the start says what failed, and the end
4
+ * of a stacktrace or a child's output usually says why.
5
+ */
6
+ /** The collection endpoint keeps up to this many bytes of a value. */
7
+ export declare const MAX_VALUE_BYTES: number;
8
+ /** `value` within `maxBytes` of UTF-8: its start and end, with the cut size. */
9
+ export declare function truncateMiddle(value: string, maxBytes?: number): string;
10
+ //# sourceMappingURL=truncate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.d.ts","sourceRoot":"","sources":["../../../src/telemetry/otel/truncate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,sEAAsE;AACtE,eAAO,MAAM,eAAe,QAAW,CAAC;AAMxC,gFAAgF;AAChF,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAwB,GACjC,MAAM,CAaR"}