managed-deepagents 0.9.6-dev.15 → 0.9.6-dev.17

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 (343) hide show
  1. package/README.md +57 -953
  2. package/dist/agent-auth.d.ts +1 -1
  3. package/dist/agent-auth.d.ts.map +1 -1
  4. package/dist/agent-auth.js +12 -36
  5. package/dist/agent-auth.js.map +1 -1
  6. package/dist/channels/assistant-text.d.ts +0 -24
  7. package/dist/channels/assistant-text.d.ts.map +1 -1
  8. package/dist/channels/assistant-text.js +1 -65
  9. package/dist/channels/assistant-text.js.map +1 -1
  10. package/dist/channels/binding.d.ts +1 -20
  11. package/dist/channels/binding.d.ts.map +1 -1
  12. package/dist/channels/binding.js +10 -39
  13. package/dist/channels/binding.js.map +1 -1
  14. package/dist/channels/http/http.d.ts.map +1 -1
  15. package/dist/channels/http/http.js +65 -386
  16. package/dist/channels/http/http.js.map +1 -1
  17. package/dist/channels/http/index.d.ts +1 -2
  18. package/dist/channels/http/index.d.ts.map +1 -1
  19. package/dist/channels/http/index.js +10 -14
  20. package/dist/channels/http/index.js.map +1 -1
  21. package/dist/channels/http/ingress.d.ts +5 -65
  22. package/dist/channels/http/ingress.d.ts.map +1 -1
  23. package/dist/channels/http/ingress.js +33 -149
  24. package/dist/channels/http/ingress.js.map +1 -1
  25. package/dist/channels/http/types.d.ts +2 -143
  26. package/dist/channels/http/types.d.ts.map +1 -1
  27. package/dist/channels/message-schema.d.ts +0 -2
  28. package/dist/channels/message-schema.d.ts.map +1 -1
  29. package/dist/channels/message-schema.js +0 -4
  30. package/dist/channels/message-schema.js.map +1 -1
  31. package/dist/channels/messaging-registry.d.ts +0 -16
  32. package/dist/channels/messaging-registry.d.ts.map +1 -1
  33. package/dist/channels/messaging-registry.js +0 -29
  34. package/dist/channels/messaging-registry.js.map +1 -1
  35. package/dist/channels/runtime.d.ts +1 -1
  36. package/dist/channels/runtime.d.ts.map +1 -1
  37. package/dist/channels/runtime.js +1 -1
  38. package/dist/channels/runtime.js.map +1 -1
  39. package/dist/channels/schedule-delivery.d.ts +1 -1
  40. package/dist/channels/schedule-delivery.d.ts.map +1 -1
  41. package/dist/channels/schedule-delivery.js +23 -12
  42. package/dist/channels/schedule-delivery.js.map +1 -1
  43. package/dist/channels/slack/api.d.ts +0 -2
  44. package/dist/channels/slack/api.d.ts.map +1 -1
  45. package/dist/channels/slack/api.js +0 -6
  46. package/dist/channels/slack/api.js.map +1 -1
  47. package/dist/channels/slack/files.d.ts.map +1 -1
  48. package/dist/channels/slack/files.js +3 -2
  49. package/dist/channels/slack/files.js.map +1 -1
  50. package/dist/channels/slack/index.d.ts +2 -76
  51. package/dist/channels/slack/index.d.ts.map +1 -1
  52. package/dist/channels/slack/index.js +6 -177
  53. package/dist/channels/slack/index.js.map +1 -1
  54. package/dist/channels/slack/message-content.d.ts.map +1 -1
  55. package/dist/channels/slack/message-content.js +28 -23
  56. package/dist/channels/slack/message-content.js.map +1 -1
  57. package/dist/channels/source-providers.js +1 -1
  58. package/dist/channels/source-providers.js.map +1 -1
  59. package/dist/channels/trigger/client.d.ts.map +1 -1
  60. package/dist/channels/trigger/client.js +12 -6
  61. package/dist/channels/trigger/client.js.map +1 -1
  62. package/dist/channels/trigger/http.d.ts +3 -114
  63. package/dist/channels/trigger/http.d.ts.map +1 -1
  64. package/dist/channels/trigger/http.js +82 -314
  65. package/dist/channels/trigger/http.js.map +1 -1
  66. package/dist/channels/trigger/identity-context.d.ts +1 -1
  67. package/dist/channels/trigger/identity-context.d.ts.map +1 -1
  68. package/dist/channels/trigger/identity-context.js +3 -5
  69. package/dist/channels/trigger/identity-context.js.map +1 -1
  70. package/dist/channels/trigger/ingress.d.ts +1 -38
  71. package/dist/channels/trigger/ingress.d.ts.map +1 -1
  72. package/dist/channels/trigger/ingress.js +24 -49
  73. package/dist/channels/trigger/ingress.js.map +1 -1
  74. package/dist/channels/trigger/types.d.ts +3 -82
  75. package/dist/channels/trigger/types.d.ts.map +1 -1
  76. package/dist/channels/trigger/types.js +0 -36
  77. package/dist/channels/trigger/types.js.map +1 -1
  78. package/dist/channels/types.d.ts +3 -19
  79. package/dist/channels/types.d.ts.map +1 -1
  80. package/dist/channels/types.js +0 -2
  81. package/dist/channels/types.js.map +1 -1
  82. package/dist/concurrency/batch-processor.d.ts +51 -0
  83. package/dist/concurrency/batch-processor.d.ts.map +1 -0
  84. package/dist/concurrency/batch-processor.js +99 -0
  85. package/dist/concurrency/batch-processor.js.map +1 -0
  86. package/dist/connections.d.ts +1 -42
  87. package/dist/connections.d.ts.map +1 -1
  88. package/dist/connections.js +14 -127
  89. package/dist/connections.js.map +1 -1
  90. package/dist/credential-gate.d.ts +0 -2
  91. package/dist/credential-gate.d.ts.map +1 -1
  92. package/dist/credential-gate.js +3 -37
  93. package/dist/credential-gate.js.map +1 -1
  94. package/dist/define-deep-agent.d.ts.map +1 -1
  95. package/dist/define-deep-agent.js +0 -6
  96. package/dist/define-deep-agent.js.map +1 -1
  97. package/dist/identity/loopback.d.ts +7 -2
  98. package/dist/identity/loopback.d.ts.map +1 -1
  99. package/dist/identity/loopback.js +15 -4
  100. package/dist/identity/loopback.js.map +1 -1
  101. package/dist/identity/slack/links.js +3 -2
  102. package/dist/identity/slack/links.js.map +1 -1
  103. package/dist/index.d.ts +4 -15
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +1 -2
  106. package/dist/index.js.map +1 -1
  107. package/dist/ingress/index.d.ts +8 -0
  108. package/dist/ingress/index.d.ts.map +1 -1
  109. package/dist/ingress/index.js +32 -2
  110. package/dist/ingress/index.js.map +1 -1
  111. package/dist/ingress/loopback.js +4 -3
  112. package/dist/ingress/loopback.js.map +1 -1
  113. package/dist/ingress/runs.d.ts +1 -74
  114. package/dist/ingress/runs.d.ts.map +1 -1
  115. package/dist/ingress/runs.js +16 -176
  116. package/dist/ingress/runs.js.map +1 -1
  117. package/dist/managed-composition.d.ts.map +1 -1
  118. package/dist/managed-composition.js +13 -8
  119. package/dist/managed-composition.js.map +1 -1
  120. package/dist/memory/instructions-middleware.d.ts.map +1 -1
  121. package/dist/memory/instructions-middleware.js +6 -5
  122. package/dist/memory/instructions-middleware.js.map +1 -1
  123. package/dist/namespaces.d.ts +21 -21
  124. package/dist/namespaces.d.ts.map +1 -1
  125. package/dist/namespaces.js +29 -4
  126. package/dist/namespaces.js.map +1 -1
  127. package/dist/resilience/retry.d.ts +21 -0
  128. package/dist/resilience/retry.d.ts.map +1 -0
  129. package/dist/resilience/retry.js +40 -0
  130. package/dist/resilience/retry.js.map +1 -0
  131. package/dist/runtime/auth.d.ts.map +1 -1
  132. package/dist/runtime/auth.js +21 -151
  133. package/dist/runtime/auth.js.map +1 -1
  134. package/dist/runtime/channel.d.ts +0 -6
  135. package/dist/runtime/channel.d.ts.map +1 -1
  136. package/dist/runtime/channel.js.map +1 -1
  137. package/dist/runtime/graph-build-timing.d.ts +30 -0
  138. package/dist/runtime/graph-build-timing.d.ts.map +1 -0
  139. package/dist/runtime/graph-build-timing.js +50 -0
  140. package/dist/runtime/graph-build-timing.js.map +1 -0
  141. package/dist/runtime/http.d.ts +15 -0
  142. package/dist/runtime/http.d.ts.map +1 -1
  143. package/dist/runtime/http.js +37 -0
  144. package/dist/runtime/http.js.map +1 -1
  145. package/dist/runtime/identity-http.d.ts +0 -2
  146. package/dist/runtime/identity-http.d.ts.map +1 -1
  147. package/dist/runtime/identity-http.js +16 -40
  148. package/dist/runtime/identity-http.js.map +1 -1
  149. package/dist/runtime/identity-runtime.d.ts +0 -10
  150. package/dist/runtime/identity-runtime.d.ts.map +1 -1
  151. package/dist/runtime/identity-runtime.js +0 -22
  152. package/dist/runtime/identity-runtime.js.map +1 -1
  153. package/dist/runtime/index.d.ts.map +1 -1
  154. package/dist/runtime/index.js +47 -46
  155. package/dist/runtime/index.js.map +1 -1
  156. package/dist/runtime/langsmith-env.d.ts +19 -0
  157. package/dist/runtime/langsmith-env.d.ts.map +1 -0
  158. package/dist/runtime/langsmith-env.js +38 -0
  159. package/dist/runtime/langsmith-env.js.map +1 -0
  160. package/dist/runtime/log.d.ts +8 -14
  161. package/dist/runtime/log.d.ts.map +1 -1
  162. package/dist/runtime/log.js +16 -7
  163. package/dist/runtime/log.js.map +1 -1
  164. package/dist/runtime/managed-middleware.d.ts.map +1 -1
  165. package/dist/runtime/managed-middleware.js +1 -14
  166. package/dist/runtime/managed-middleware.js.map +1 -1
  167. package/dist/runtime/managed-tools.d.ts +10 -10
  168. package/dist/runtime/managed-tools.d.ts.map +1 -1
  169. package/dist/runtime/managed-tools.js +24 -24
  170. package/dist/runtime/managed-tools.js.map +1 -1
  171. package/dist/runtime/memory/mounts.d.ts +82 -11
  172. package/dist/runtime/memory/mounts.d.ts.map +1 -1
  173. package/dist/runtime/memory/mounts.js +173 -34
  174. package/dist/runtime/memory/mounts.js.map +1 -1
  175. package/dist/runtime/memory/policy.d.ts.map +1 -1
  176. package/dist/runtime/memory/policy.js +3 -1
  177. package/dist/runtime/memory/policy.js.map +1 -1
  178. package/dist/runtime/run-input.d.ts +0 -10
  179. package/dist/runtime/run-input.d.ts.map +1 -1
  180. package/dist/runtime/run-input.js +19 -47
  181. package/dist/runtime/run-input.js.map +1 -1
  182. package/dist/runtime/sandbox-manager.d.ts +1 -1
  183. package/dist/runtime/sandbox-manager.d.ts.map +1 -1
  184. package/dist/runtime/sandbox-manager.js +10 -15
  185. package/dist/runtime/sandbox-manager.js.map +1 -1
  186. package/dist/runtime/schedule-auth.d.ts +0 -17
  187. package/dist/runtime/schedule-auth.d.ts.map +1 -1
  188. package/dist/runtime/schedule-auth.js +3 -40
  189. package/dist/runtime/schedule-auth.js.map +1 -1
  190. package/dist/runtime/selected-skills-backend.d.ts +3 -3
  191. package/dist/runtime/selected-skills-backend.d.ts.map +1 -1
  192. package/dist/runtime/selected-skills-backend.js +5 -5
  193. package/dist/runtime/selected-skills-backend.js.map +1 -1
  194. package/dist/runtime/types.d.ts +1 -5
  195. package/dist/runtime/types.d.ts.map +1 -1
  196. package/dist/runtime-schedules.d.ts +0 -13
  197. package/dist/runtime-schedules.d.ts.map +1 -1
  198. package/dist/runtime-schedules.js +22 -86
  199. package/dist/runtime-schedules.js.map +1 -1
  200. package/dist/sandbox.d.ts +6 -0
  201. package/dist/sandbox.d.ts.map +1 -1
  202. package/dist/sandbox.js +7 -3
  203. package/dist/sandbox.js.map +1 -1
  204. package/dist/schedule-channel.d.ts +2 -5
  205. package/dist/schedule-channel.d.ts.map +1 -1
  206. package/dist/schedule-channel.js +12 -13
  207. package/dist/schedule-channel.js.map +1 -1
  208. package/dist/telemetry/lifecycle.d.ts +26 -0
  209. package/dist/telemetry/lifecycle.d.ts.map +1 -0
  210. package/dist/telemetry/lifecycle.js +49 -0
  211. package/dist/telemetry/lifecycle.js.map +1 -0
  212. package/dist/telemetry/metadata.d.ts.map +1 -1
  213. package/dist/telemetry/metadata.js +4 -4
  214. package/dist/telemetry/metadata.js.map +1 -1
  215. package/dist/telemetry/otel/context.d.ts +57 -0
  216. package/dist/telemetry/otel/context.d.ts.map +1 -0
  217. package/dist/telemetry/otel/context.js +122 -0
  218. package/dist/telemetry/otel/context.js.map +1 -0
  219. package/dist/telemetry/otel/exporter.d.ts +53 -0
  220. package/dist/telemetry/otel/exporter.d.ts.map +1 -0
  221. package/dist/telemetry/otel/exporter.js +190 -0
  222. package/dist/telemetry/otel/exporter.js.map +1 -0
  223. package/dist/telemetry/otel/index.d.ts +6 -0
  224. package/dist/telemetry/otel/index.d.ts.map +1 -0
  225. package/dist/telemetry/otel/index.js +3 -0
  226. package/dist/telemetry/otel/index.js.map +1 -0
  227. package/dist/telemetry/otel/otlp.d.ts +44 -0
  228. package/dist/telemetry/otel/otlp.d.ts.map +1 -0
  229. package/dist/telemetry/otel/otlp.js +7 -0
  230. package/dist/telemetry/otel/otlp.js.map +1 -0
  231. package/dist/telemetry/otel/truncate.d.ts +10 -0
  232. package/dist/telemetry/otel/truncate.d.ts.map +1 -0
  233. package/dist/telemetry/otel/truncate.js +39 -0
  234. package/dist/telemetry/otel/truncate.js.map +1 -0
  235. package/dist/telemetry/run-listener.d.ts +1 -1
  236. package/dist/telemetry/run-listener.d.ts.map +1 -1
  237. package/dist/telemetry/run-listener.js +32 -2
  238. package/dist/telemetry/run-listener.js.map +1 -1
  239. package/dist/telemetry/transport/posthog.d.ts +13 -1
  240. package/dist/telemetry/transport/posthog.d.ts.map +1 -1
  241. package/dist/telemetry/transport/posthog.js +68 -30
  242. package/dist/telemetry/transport/posthog.js.map +1 -1
  243. package/package.json +11 -11
  244. package/dist/channels/actor.d.ts +0 -43
  245. package/dist/channels/actor.d.ts.map +0 -1
  246. package/dist/channels/actor.js +0 -2
  247. package/dist/channels/actor.js.map +0 -1
  248. package/dist/channels/delivery.d.ts +0 -21
  249. package/dist/channels/delivery.d.ts.map +0 -1
  250. package/dist/channels/delivery.js +0 -196
  251. package/dist/channels/delivery.js.map +0 -1
  252. package/dist/channels/github/connections.d.ts +0 -11
  253. package/dist/channels/github/connections.d.ts.map +0 -1
  254. package/dist/channels/github/connections.js +0 -14
  255. package/dist/channels/github/connections.js.map +0 -1
  256. package/dist/channels/github/index.d.ts +0 -8
  257. package/dist/channels/github/index.d.ts.map +0 -1
  258. package/dist/channels/github/index.js +0 -274
  259. package/dist/channels/github/index.js.map +0 -1
  260. package/dist/channels/github/mentions.d.ts +0 -12
  261. package/dist/channels/github/mentions.d.ts.map +0 -1
  262. package/dist/channels/github/mentions.js +0 -185
  263. package/dist/channels/github/mentions.js.map +0 -1
  264. package/dist/channels/github/schema.d.ts +0 -4165
  265. package/dist/channels/github/schema.d.ts.map +0 -1
  266. package/dist/channels/github/schema.js +0 -221
  267. package/dist/channels/github/schema.js.map +0 -1
  268. package/dist/channels/github/types.d.ts +0 -163
  269. package/dist/channels/github/types.d.ts.map +0 -1
  270. package/dist/channels/github/types.js +0 -2
  271. package/dist/channels/github/types.js.map +0 -1
  272. package/dist/channels/http/endpoint.d.ts +0 -95
  273. package/dist/channels/http/endpoint.d.ts.map +0 -1
  274. package/dist/channels/http/endpoint.js +0 -276
  275. package/dist/channels/http/endpoint.js.map +0 -1
  276. package/dist/channels/http/provider.d.ts +0 -119
  277. package/dist/channels/http/provider.d.ts.map +0 -1
  278. package/dist/channels/http/provider.js +0 -227
  279. package/dist/channels/http/provider.js.map +0 -1
  280. package/dist/channels/http/studio.d.ts +0 -24
  281. package/dist/channels/http/studio.d.ts.map +0 -1
  282. package/dist/channels/http/studio.js +0 -95
  283. package/dist/channels/http/studio.js.map +0 -1
  284. package/dist/channels/http/threads.d.ts +0 -7
  285. package/dist/channels/http/threads.d.ts.map +0 -1
  286. package/dist/channels/http/threads.js +0 -10
  287. package/dist/channels/http/threads.js.map +0 -1
  288. package/dist/channels/linear/connections.d.ts +0 -11
  289. package/dist/channels/linear/connections.d.ts.map +0 -1
  290. package/dist/channels/linear/connections.js +0 -14
  291. package/dist/channels/linear/connections.js.map +0 -1
  292. package/dist/channels/linear/graphql.d.ts +0 -57
  293. package/dist/channels/linear/graphql.d.ts.map +0 -1
  294. package/dist/channels/linear/graphql.js +0 -167
  295. package/dist/channels/linear/graphql.js.map +0 -1
  296. package/dist/channels/linear/index.d.ts +0 -9
  297. package/dist/channels/linear/index.d.ts.map +0 -1
  298. package/dist/channels/linear/index.js +0 -489
  299. package/dist/channels/linear/index.js.map +0 -1
  300. package/dist/channels/linear/schema.d.ts +0 -1050
  301. package/dist/channels/linear/schema.d.ts.map +0 -1
  302. package/dist/channels/linear/schema.js +0 -255
  303. package/dist/channels/linear/schema.js.map +0 -1
  304. package/dist/channels/linear/types.d.ts +0 -162
  305. package/dist/channels/linear/types.d.ts.map +0 -1
  306. package/dist/channels/linear/types.js +0 -2
  307. package/dist/channels/linear/types.js.map +0 -1
  308. package/dist/channels/reserved-connections.d.ts +0 -12
  309. package/dist/channels/reserved-connections.d.ts.map +0 -1
  310. package/dist/channels/reserved-connections.js +0 -55
  311. package/dist/channels/reserved-connections.js.map +0 -1
  312. package/dist/channels/run-input.d.ts +0 -71
  313. package/dist/channels/run-input.d.ts.map +0 -1
  314. package/dist/channels/run-input.js +0 -155
  315. package/dist/channels/run-input.js.map +0 -1
  316. package/dist/channels/slack/connections.d.ts +0 -6
  317. package/dist/channels/slack/connections.d.ts.map +0 -1
  318. package/dist/channels/slack/connections.js +0 -6
  319. package/dist/channels/slack/connections.js.map +0 -1
  320. package/dist/channels/slack/events.d.ts +0 -272
  321. package/dist/channels/slack/events.d.ts.map +0 -1
  322. package/dist/channels/slack/events.js +0 -235
  323. package/dist/channels/slack/events.js.map +0 -1
  324. package/dist/channels/slack/status.d.ts +0 -76
  325. package/dist/channels/slack/status.d.ts.map +0 -1
  326. package/dist/channels/slack/status.js +0 -427
  327. package/dist/channels/slack/status.js.map +0 -1
  328. package/dist/runtime/channel-icon.d.ts +0 -22
  329. package/dist/runtime/channel-icon.d.ts.map +0 -1
  330. package/dist/runtime/channel-icon.js +0 -70
  331. package/dist/runtime/channel-icon.js.map +0 -1
  332. package/dist/runtime/managed-thread.d.ts +0 -60
  333. package/dist/runtime/managed-thread.d.ts.map +0 -1
  334. package/dist/runtime/managed-thread.js +0 -76
  335. package/dist/runtime/managed-thread.js.map +0 -1
  336. package/dist/runtime/thread-record.d.ts +0 -81
  337. package/dist/runtime/thread-record.d.ts.map +0 -1
  338. package/dist/runtime/thread-record.js +0 -205
  339. package/dist/runtime/thread-record.js.map +0 -1
  340. package/dist/values.d.ts +0 -15
  341. package/dist/values.d.ts.map +0 -1
  342. package/dist/values.js +0 -31
  343. package/dist/values.js.map +0 -1
@@ -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
@@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D;AAED,iCAAiC;AACjC,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,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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AAI,CAAC;QAC1B,UAAU;QACV,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,OAAO,CAAC,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;AAc7D,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,CAqB3B;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 { resolveServerApiKey, resolveTenantWorkspaceId, } from "../../runtime/langsmith-env.js";
17
+ import { isTelemetryDisabled } from "../gates.js";
18
+ import { onShutdown } from "../lifecycle.js";
19
+ import { packageVersion } from "../metadata.js";
20
+ const LOGS_PATH = "/v1/platform/mda/otel/v1/logs";
21
+ const SERVICE_NAME = "mda-node";
22
+ /** Bounds one export request; the OTel exporters' default. */
23
+ const EXPORT_TIMEOUT_MS = 10_000;
24
+ /** How long a partial batch waits for more records. */
25
+ const BATCH_WAIT_MS = 1_000;
26
+ /** Records waiting to send; later ones are dropped. */
27
+ const MAX_QUEUED_RECORDS = 10_000;
28
+ /** The collection endpoint accepts at most this many records per request. */
29
+ export const MAX_RECORDS_PER_REQUEST = 200;
30
+ /** Encoded records per request, under the endpoint's 5MB body limit. */
31
+ export const MAX_REQUEST_BYTES = 4 << 20;
32
+ /** OTel semantic-convention attribute for a log record's unique id. */
33
+ const RECORD_UID_KEY = "log.record.uid";
34
+ const SEVERITY_NUMBER = { INFO: 9, WARN: 13, ERROR: 17 };
35
+ function nonempty(value) {
36
+ return value?.trim() || undefined;
37
+ }
38
+ /**
39
+ * Where and how to send logs, or `undefined` when logs must not be sent:
40
+ * telemetry is off, the process is not a LangSmith deployment, there is no
41
+ * key, or the key would cross the network in cleartext.
42
+ */
43
+ export function resolveOtelLogConfig(env = process.env) {
44
+ if (isTelemetryDisabled(env))
45
+ return undefined;
46
+ if (env.MDA_LOCAL_DEV === "1" || !nonempty(env.LANGSMITH_HOST_PROJECT_ID)) {
47
+ return undefined;
48
+ }
49
+ const apiKey = resolveServerApiKey(env);
50
+ if (!apiKey)
51
+ return undefined;
52
+ let url;
53
+ try {
54
+ url = new URL(LOGS_PATH, resolveAgentAuthBaseUrl(env));
55
+ }
56
+ catch {
57
+ return undefined;
58
+ }
59
+ if (!sendsKeySecurely(url))
60
+ return undefined;
61
+ return {
62
+ url: url.toString(),
63
+ headers: agentAuthHeaders({
64
+ apiKey,
65
+ workspaceId: resolveTenantWorkspaceId(env),
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,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AAgB,CACrC,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"}
@@ -0,0 +1,39 @@
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 const MAX_VALUE_BYTES = 32 << 10;
8
+ /** Kept from the start of a value that is too long; the rest keeps its end. */
9
+ const HEAD_BYTES = 1 << 10;
10
+ /** Room for the omission marker. */
11
+ const MARKER_BYTES = 48;
12
+ /** `value` within `maxBytes` of UTF-8: its start and end, with the cut size. */
13
+ export function truncateMiddle(value, maxBytes = MAX_VALUE_BYTES) {
14
+ // A UTF-16 code unit is at most 3 UTF-8 bytes.
15
+ if (value.length * 3 <= maxBytes)
16
+ return value;
17
+ const bytes = Buffer.from(value, "utf8");
18
+ if (bytes.length <= maxBytes)
19
+ return value;
20
+ const headEnd = floorBoundary(bytes, HEAD_BYTES);
21
+ const tailStart = ceilBoundary(bytes, bytes.length - (maxBytes - HEAD_BYTES - MARKER_BYTES));
22
+ return `${bytes.subarray(0, headEnd).toString("utf8")}\n… ${tailStart - headEnd} bytes omitted …\n${bytes.subarray(tailStart).toString("utf8")}`;
23
+ }
24
+ function isContinuation(byte) {
25
+ return byte !== undefined && (byte & 0xc0) === 0x80;
26
+ }
27
+ function floorBoundary(bytes, index) {
28
+ let at = index;
29
+ while (at > 0 && isContinuation(bytes[at]))
30
+ at--;
31
+ return at;
32
+ }
33
+ function ceilBoundary(bytes, index) {
34
+ let at = index;
35
+ while (at < bytes.length && isContinuation(bytes[at]))
36
+ at++;
37
+ return at;
38
+ }
39
+ //# sourceMappingURL=truncate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../../src/telemetry/otel/truncate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,IAAI,EAAE,CAAC;AACxC,+EAA+E;AAC/E,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,CAAC;AAC3B,oCAAoC;AACpC,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB,gFAAgF;AAChF,MAAM,UAAU,cAAc,CAC5B,KAAa,EACb,QAAQ,GAAW,eAAe;IAElC,+CAA+C;IAC/C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,YAAY,CAC5B,KAAK,EACL,KAAK,CAAC,MAAM,GAAG,CAAC,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC,CACtD,CAAC;IACF,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,OACnD,SAAS,GAAG,OACd,qBAAqB,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;AACpE,CAAC;AAED,SAAS,cAAc,CAAC,IAAwB;IAC9C,OAAO,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;AACtD,CAAC;AAED,SAAS,aAAa,CAAC,KAAa,EAAE,KAAa;IACjD,IAAI,EAAE,GAAG,KAAK,CAAC;IACf,OAAO,EAAE,GAAG,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAAE,EAAE,EAAE,CAAC;IACjD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,YAAY,CAAC,KAAa,EAAE,KAAa;IAChD,IAAI,EAAE,GAAG,KAAK,CAAC;IACf,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAAE,EAAE,EAAE,CAAC;IAC5D,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -14,7 +14,7 @@ export declare class RunTelemetryListener extends GraphCallbackHandler {
14
14
  handleChainStart(_chain: unknown, _inputs: unknown, runId: string): void;
15
15
  handleInterrupt(event: GraphInterruptEvent): void;
16
16
  handleChainEnd(_outputs: unknown, runId: string): void;
17
- handleChainError(_error: unknown, runId: string): void;
17
+ handleChainError(error: unknown, runId: string): void;
18
18
  private report;
19
19
  }
20
20
  //# sourceMappingURL=run-listener.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-listener.d.ts","sourceRoot":"","sources":["../../src/telemetry/run-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAm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