rivetkit 2.3.18-rc.4 → 2.3.19

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 (136) hide show
  1. package/dist/browser/client.d.ts +723 -616
  2. package/dist/browser/client.js +184 -28
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +3 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +6 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -1
  9. package/dist/tsup/actor/errors.d.ts +1 -1
  10. package/dist/tsup/actor/errors.js +5 -1
  11. package/dist/tsup/agent-os/index.cjs +3 -1
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +110 -3
  14. package/dist/tsup/agent-os/index.d.ts +110 -3
  15. package/dist/tsup/agent-os/index.js +3 -1
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-ENDOWQTM.js → chunk-464WE4RF.js} +2 -2
  18. package/dist/tsup/{chunk-KKG2CTSI.js → chunk-4SC2NSAV.js} +2 -2
  19. package/dist/tsup/{chunk-R2WRP6VV.cjs → chunk-7A5EIXJJ.cjs} +7 -7
  20. package/dist/tsup/{chunk-R2WRP6VV.cjs.map → chunk-7A5EIXJJ.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-GUVDWB2O.cjs → chunk-7BRRGBRY.cjs} +10 -10
  22. package/dist/tsup/{chunk-GUVDWB2O.cjs.map → chunk-7BRRGBRY.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-KVPU65TI.js → chunk-7HTST3NX.js} +3 -3
  24. package/dist/tsup/{chunk-MS6C3B2I.js → chunk-BKX7UDTA.js} +185 -28
  25. package/dist/tsup/chunk-BKX7UDTA.js.map +1 -0
  26. package/dist/tsup/{chunk-FL2FDUSZ.js → chunk-DK3L22R6.js} +4 -4
  27. package/dist/tsup/{chunk-CAL23WOC.js → chunk-DN6MD3KK.js} +7 -7
  28. package/dist/tsup/chunk-DN6MD3KK.js.map +1 -0
  29. package/dist/tsup/{chunk-6W5VGLFT.js → chunk-EB77NZL4.js} +1 -1
  30. package/dist/tsup/chunk-EB77NZL4.js.map +1 -0
  31. package/dist/tsup/{chunk-4KGXFC6M.cjs → chunk-EO5UOXXY.cjs} +1 -1
  32. package/dist/tsup/chunk-EO5UOXXY.cjs.map +1 -0
  33. package/dist/tsup/{chunk-QFLG6UB4.cjs → chunk-G4U5L6AX.cjs} +3 -3
  34. package/dist/tsup/{chunk-QFLG6UB4.cjs.map → chunk-G4U5L6AX.cjs.map} +1 -1
  35. package/dist/tsup/{chunk-TGGF6SZN.cjs → chunk-IJUXBWH4.cjs} +351 -194
  36. package/dist/tsup/chunk-IJUXBWH4.cjs.map +1 -0
  37. package/dist/tsup/{chunk-2JSYYH6P.cjs → chunk-JX2ITWAV.cjs} +13 -2
  38. package/dist/tsup/chunk-JX2ITWAV.cjs.map +1 -0
  39. package/dist/tsup/{chunk-N3DJTMSZ.cjs → chunk-OGPFN6BT.cjs} +3 -3
  40. package/dist/tsup/{chunk-N3DJTMSZ.cjs.map → chunk-OGPFN6BT.cjs.map} +1 -1
  41. package/dist/tsup/{chunk-OUQUIBVW.js → chunk-P2OFXH4G.js} +12 -1
  42. package/dist/tsup/chunk-P2OFXH4G.js.map +1 -0
  43. package/dist/tsup/{chunk-F3IP3SGO.cjs → chunk-PPEIPCW4.cjs} +4 -4
  44. package/dist/tsup/{chunk-F3IP3SGO.cjs.map → chunk-PPEIPCW4.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-7E2W2YSM.cjs → chunk-RJC5O2SD.cjs} +13 -13
  46. package/dist/tsup/chunk-RJC5O2SD.cjs.map +1 -0
  47. package/dist/tsup/{chunk-YQD6RRVP.js → chunk-WME6KOXW.js} +2 -2
  48. package/dist/tsup/{chunk-PLAJJOTE.js → chunk-X7RMJQGY.js} +2 -2
  49. package/dist/tsup/{chunk-4OMHYVOQ.cjs → chunk-Z4RAXFSD.cjs} +3 -3
  50. package/dist/tsup/{chunk-4OMHYVOQ.cjs.map → chunk-Z4RAXFSD.cjs.map} +1 -1
  51. package/dist/tsup/client/mod.cjs +6 -6
  52. package/dist/tsup/client/mod.d.cts +5 -5
  53. package/dist/tsup/client/mod.d.ts +5 -5
  54. package/dist/tsup/client/mod.js +5 -5
  55. package/dist/tsup/common/log.cjs +3 -3
  56. package/dist/tsup/common/log.js +2 -2
  57. package/dist/tsup/common/websocket.cjs +4 -4
  58. package/dist/tsup/common/websocket.js +3 -3
  59. package/dist/tsup/{config-gvHwMas-.d.cts → config-8n2AOhXK.d.cts} +114 -10
  60. package/dist/tsup/{config-Ug5M2MOr.d.ts → config-DEm0yIVV.d.ts} +114 -10
  61. package/dist/tsup/{context-DererUCI.d.ts → context-DGg2-IOm.d.ts} +1 -1
  62. package/dist/tsup/{context-BSCBvbfM.d.cts → context-DwjOVvlE.d.cts} +1 -1
  63. package/dist/tsup/db/drizzle.cjs +3 -3
  64. package/dist/tsup/db/drizzle.js +2 -2
  65. package/dist/tsup/db/mod.cjs +4 -4
  66. package/dist/tsup/db/mod.js +3 -3
  67. package/dist/tsup/dynamic/mod.cjs +2 -2
  68. package/dist/tsup/dynamic/mod.d.cts +3 -3
  69. package/dist/tsup/dynamic/mod.d.ts +3 -3
  70. package/dist/tsup/dynamic/mod.js +1 -1
  71. package/dist/tsup/inspector/mod.cjs +6 -6
  72. package/dist/tsup/inspector/mod.js +5 -5
  73. package/dist/tsup/inspector/workflow.cjs +5 -5
  74. package/dist/tsup/inspector/workflow.js +4 -4
  75. package/dist/tsup/inspector-tab/mod.cjs +2 -2
  76. package/dist/tsup/inspector-tab/mod.d.cts +4 -4
  77. package/dist/tsup/inspector-tab/mod.d.ts +4 -4
  78. package/dist/tsup/inspector-tab/mod.js +1 -1
  79. package/dist/tsup/mod.cjs +492 -319
  80. package/dist/tsup/mod.cjs.map +1 -1
  81. package/dist/tsup/mod.d.cts +5 -5
  82. package/dist/tsup/mod.d.ts +5 -5
  83. package/dist/tsup/mod.js +367 -194
  84. package/dist/tsup/mod.js.map +1 -1
  85. package/dist/tsup/test/mod.cjs +7 -7
  86. package/dist/tsup/test/mod.d.cts +3 -3
  87. package/dist/tsup/test/mod.d.ts +3 -3
  88. package/dist/tsup/test/mod.js +5 -5
  89. package/dist/tsup/{utils-Bbz-3411.d.cts → utils-CNFeS-Dk.d.cts} +1 -1
  90. package/dist/tsup/{utils-vvJQyygr.d.ts → utils-DsoDinPz.d.cts} +9 -1
  91. package/dist/tsup/{utils-vvJQyygr.d.cts → utils-DsoDinPz.d.ts} +9 -1
  92. package/dist/tsup/{utils-BqdWVlzm.d.ts → utils-OQHBjfcM.d.ts} +1 -1
  93. package/dist/tsup/utils.cjs +3 -3
  94. package/dist/tsup/utils.d.cts +2 -2
  95. package/dist/tsup/utils.d.ts +2 -2
  96. package/dist/tsup/utils.js +2 -2
  97. package/dist/tsup/workflow/mod.cjs +33 -27
  98. package/dist/tsup/workflow/mod.cjs.map +1 -1
  99. package/dist/tsup/workflow/mod.d.cts +5 -5
  100. package/dist/tsup/workflow/mod.d.ts +5 -5
  101. package/dist/tsup/workflow/mod.js +25 -19
  102. package/dist/tsup/workflow/mod.js.map +1 -1
  103. package/package.json +10 -8
  104. package/src/actor/config.ts +38 -0
  105. package/src/actor/errors.ts +31 -0
  106. package/src/client/actor-conn.ts +7 -0
  107. package/src/client/actor-handle.ts +57 -17
  108. package/src/client/client.ts +26 -6
  109. package/src/client/outbound-telemetry.ts +66 -0
  110. package/src/client/queue.ts +3 -0
  111. package/src/client/raw-utils.ts +3 -0
  112. package/src/common/actor-router-consts.ts +3 -0
  113. package/src/common/actor-telemetry-context.ts +19 -0
  114. package/src/common/otel-context.ts +99 -0
  115. package/src/common/utils.ts +1 -19
  116. package/src/engine-client/actor-http-client.ts +15 -0
  117. package/src/registry/index.ts +6 -0
  118. package/src/registry/napi-runtime.ts +155 -35
  119. package/src/registry/native.ts +277 -191
  120. package/src/registry/runtime.ts +66 -0
  121. package/src/registry/wasm-runtime.ts +40 -0
  122. package/src/workflow/driver.ts +20 -12
  123. package/dist/tsup/chunk-2JSYYH6P.cjs.map +0 -1
  124. package/dist/tsup/chunk-4KGXFC6M.cjs.map +0 -1
  125. package/dist/tsup/chunk-6W5VGLFT.js.map +0 -1
  126. package/dist/tsup/chunk-7E2W2YSM.cjs.map +0 -1
  127. package/dist/tsup/chunk-CAL23WOC.js.map +0 -1
  128. package/dist/tsup/chunk-MS6C3B2I.js.map +0 -1
  129. package/dist/tsup/chunk-OUQUIBVW.js.map +0 -1
  130. package/dist/tsup/chunk-TGGF6SZN.cjs.map +0 -1
  131. /package/dist/tsup/{chunk-ENDOWQTM.js.map → chunk-464WE4RF.js.map} +0 -0
  132. /package/dist/tsup/{chunk-KKG2CTSI.js.map → chunk-4SC2NSAV.js.map} +0 -0
  133. /package/dist/tsup/{chunk-KVPU65TI.js.map → chunk-7HTST3NX.js.map} +0 -0
  134. /package/dist/tsup/{chunk-FL2FDUSZ.js.map → chunk-DK3L22R6.js.map} +0 -0
  135. /package/dist/tsup/{chunk-YQD6RRVP.js.map → chunk-WME6KOXW.js.map} +0 -0
  136. /package/dist/tsup/{chunk-PLAJJOTE.js.map → chunk-X7RMJQGY.js.map} +0 -0
@@ -9,6 +9,7 @@ import { z as z2 } from "zod/v4";
9
9
  var INTERNAL_ERROR_CODE = "internal_error";
10
10
  var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
11
11
  var USER_ERROR_CODE = "user_error";
12
+ var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
12
13
  function looksLikeRivetErrorOptions(value) {
13
14
  return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
14
15
  }
@@ -64,6 +65,27 @@ var UserError = class extends RivetError {
64
65
  });
65
66
  }
66
67
  };
68
+ function encodeBridgeRivetError(error) {
69
+ return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
70
+ group: error.group,
71
+ code: error.code,
72
+ message: error.message,
73
+ metadata: error.metadata,
74
+ rayId: error.rayId,
75
+ public: error.public,
76
+ statusCode: error.statusCode,
77
+ actor: error.actor
78
+ })}`;
79
+ }
80
+ function encodeErrorForBridge(error) {
81
+ if (isCanonicalStructuredRivetError(error)) {
82
+ return encodeBridgeRivetError(error);
83
+ }
84
+ return String(error);
85
+ }
86
+ function isCanonicalStructuredRivetError(error) {
87
+ return error instanceof RivetError || typeof error === "object" && error !== null && "__type" in error && error.__type === "RivetError" && "group" in error && typeof error.group === "string" && "code" in error && typeof error.code === "string" && "message" in error && typeof error.message === "string";
88
+ }
67
89
  function invalidRequest(error) {
68
90
  return new RivetError(
69
91
  "request",
@@ -88,9 +110,6 @@ function actorNotFound(identifier) {
88
110
  function assertUnreachable(x) {
89
111
  throw new Error(`Unreachable case: ${x}`);
90
112
  }
91
- function isCanonicalStructuredRivetError(error) {
92
- return error instanceof RivetError || typeof error === "object" && error !== null && "__type" in error && error.__type === "RivetError" && "group" in error && typeof error.group === "string" && "code" in error && typeof error.code === "string" && "message" in error && typeof error.message === "string";
93
- }
94
113
  function deconstructError(error, exposeInternalError = false) {
95
114
  let statusCode;
96
115
  let public_;
@@ -201,7 +220,7 @@ function noopNext() {
201
220
  // package.json
202
221
  var package_default = {
203
222
  name: "rivetkit",
204
- version: "2.3.18-rc.4",
223
+ version: "2.3.19",
205
224
  description: "Lightweight libraries for building stateful actors on edge platforms",
206
225
  license: "Apache-2.0",
207
226
  keywords: [
@@ -410,6 +429,7 @@ var package_default = {
410
429
  },
411
430
  dependencies: {
412
431
  "@hono/zod-openapi": "^1.1.5",
432
+ "@opentelemetry/api": "^1.1.0",
413
433
  "@rivet-dev/agent-os-core": "^0.1.1",
414
434
  "@rivet-dev/services": "^0.1.5",
415
435
  "@rivetkit/bare-ts": "^0.6.2",
@@ -436,6 +456,7 @@ var package_default = {
436
456
  "@copilotkit/llmock": "^1.6.0",
437
457
  "@hono/node-server": "^1.18.2",
438
458
  "@hono/node-ws": "^1.1.1",
459
+ "@opentelemetry/sdk-trace-node": "2.11.0",
439
460
  "@rivet-dev/agent-os-common": "*",
440
461
  "@rivet-dev/agent-os-pi": "^0.1.1",
441
462
  "@standard-schema/spec": "^1.0.0",
@@ -1132,6 +1153,9 @@ var HEADER_ENCODING = "x-rivet-encoding";
1132
1153
  var HEADER_CONN_PARAMS = "x-rivet-conn-params";
1133
1154
  var HEADER_ORIGINAL_REQUEST_URL = "x-rivet-internal-original-request-url";
1134
1155
  var HEADER_RIVET_TOKEN = "x-rivet-token";
1156
+ var HEADER_RIVET_RAY_ID = "x-rivet-ray-id";
1157
+ var HEADER_TRACEPARENT = "traceparent";
1158
+ var HEADER_TRACESTATE = "tracestate";
1135
1159
  var HEADER_RIVET_TARGET = "x-rivet-target";
1136
1160
  var HEADER_RIVET_ACTOR = "x-rivet-actor";
1137
1161
  var HEADER_RIVET_SKIP_READY_WAIT = "x-rivet-skip-ready-wait";
@@ -1179,6 +1203,17 @@ function buildGuardHeaders(runConfig, actorRequest, options) {
1179
1203
  for (const [key, value] of Object.entries(runConfig.headers)) {
1180
1204
  headers.set(key, value);
1181
1205
  }
1206
+ for (const name of [HEADER_TRACEPARENT, HEADER_TRACESTATE]) {
1207
+ headers.delete(name);
1208
+ const value = actorRequest.headers.get(name);
1209
+ if (value !== null) {
1210
+ headers.set(name, value);
1211
+ }
1212
+ }
1213
+ const requestRayId = actorRequest.headers.get(HEADER_RIVET_RAY_ID);
1214
+ if (requestRayId !== null) {
1215
+ headers.set(HEADER_RIVET_RAY_ID, requestRayId);
1216
+ }
1182
1217
  if (runConfig.token) {
1183
1218
  headers.set(HEADER_RIVET_TOKEN, runConfig.token);
1184
1219
  }
@@ -4742,6 +4777,81 @@ async function retryOnLifecycleBoundary(run, opts) {
4742
4777
  throw lastError;
4743
4778
  }
4744
4779
 
4780
+ // src/common/otel-context.ts
4781
+ import {
4782
+ context,
4783
+ createTraceState,
4784
+ isSpanContextValid,
4785
+ propagation,
4786
+ trace
4787
+ } from "@opentelemetry/api";
4788
+ function readActiveTraceHeaders() {
4789
+ return traceHeaders(trace.getSpanContext(context.active()));
4790
+ }
4791
+ var RAY_BAGGAGE_KEY = "rivet.ray.id";
4792
+ function readActiveRayId() {
4793
+ const value = propagation.getBaggage(context.active())?.getEntry(RAY_BAGGAGE_KEY)?.value;
4794
+ if (value && value.length <= 30 && /^[A-Za-z0-9_-]+$/.test(value)) {
4795
+ return value;
4796
+ }
4797
+ return void 0;
4798
+ }
4799
+ function actorInvocationTraceHeaders(invocation) {
4800
+ const spanContext = invocationSpanContext(invocation);
4801
+ if (!spanContext) return void 0;
4802
+ return traceHeaders(spanContext);
4803
+ }
4804
+ function traceHeaders(spanContext) {
4805
+ if (!spanContext || !isSpanContextValid(spanContext)) return void 0;
4806
+ const tracestate = spanContext.traceState?.serialize();
4807
+ return {
4808
+ traceparent: `00-${spanContext.traceId}-${spanContext.spanId}-${spanContext.traceFlags.toString(16).padStart(2, "0")}`,
4809
+ ...tracestate ? { tracestate } : {}
4810
+ };
4811
+ }
4812
+ function invocationSpanContext(invocation) {
4813
+ if (!invocation) return void 0;
4814
+ try {
4815
+ const spanContext = {
4816
+ traceId: invocation.traceId,
4817
+ spanId: invocation.spanId,
4818
+ traceFlags: invocation.traceFlags,
4819
+ traceState: invocation.tracestate ? createTraceState(invocation.tracestate) : void 0,
4820
+ isRemote: false
4821
+ };
4822
+ return isSpanContextValid(spanContext) ? spanContext : void 0;
4823
+ } catch {
4824
+ return void 0;
4825
+ }
4826
+ }
4827
+
4828
+ // src/client/outbound-telemetry.ts
4829
+ function outboundTelemetryHeaders(invocation, callSpan) {
4830
+ const headers = {};
4831
+ const rayId = invocation?.rayId ?? readActiveRayId();
4832
+ if (rayId) {
4833
+ headers[HEADER_RIVET_RAY_ID] = rayId;
4834
+ }
4835
+ const traceHeaders2 = actorInvocationTraceHeaders(callSpan) ?? readActiveTraceHeaders() ?? actorInvocationTraceHeaders(invocation?.span);
4836
+ if (traceHeaders2) {
4837
+ headers[HEADER_TRACEPARENT] = traceHeaders2.traceparent;
4838
+ if (traceHeaders2.tracestate) {
4839
+ headers[HEADER_TRACESTATE] = traceHeaders2.tracestate;
4840
+ }
4841
+ }
4842
+ return headers;
4843
+ }
4844
+ function addOutboundTelemetryHeaders(headers, telemetry) {
4845
+ const callerSetTraceContext = headers.has(HEADER_TRACEPARENT) || headers.has(HEADER_TRACESTATE);
4846
+ for (const [name, value] of Object.entries(telemetry)) {
4847
+ const isTraceContext = name === HEADER_TRACEPARENT || name === HEADER_TRACESTATE;
4848
+ if (isTraceContext ? callerSetTraceContext : headers.has(name)) {
4849
+ continue;
4850
+ }
4851
+ headers.set(name, value);
4852
+ }
4853
+ }
4854
+
4745
4855
  // src/client/queue.ts
4746
4856
  function createQueueSender(senderOptions) {
4747
4857
  async function send(name, body, options) {
@@ -4752,6 +4862,7 @@ function createQueueSender(senderOptions) {
4752
4862
  method: "POST",
4753
4863
  headers: {
4754
4864
  [HEADER_ENCODING]: senderOptions.encoding,
4865
+ ...senderOptions.telemetryHeaders(),
4755
4866
  ...senderOptions.params !== void 0 ? {
4756
4867
  [HEADER_CONN_PARAMS]: JSON.stringify(
4757
4868
  senderOptions.params
@@ -4840,6 +4951,7 @@ var ActorConnRaw = class {
4840
4951
  #websocket;
4841
4952
  #client;
4842
4953
  #driver;
4954
+ #currentActorInvocation;
4843
4955
  #params;
4844
4956
  #getParams;
4845
4957
  #encoding;
@@ -4853,8 +4965,9 @@ var ActorConnRaw = class {
4853
4965
  *
4854
4966
  * @protected
4855
4967
  */
4856
- constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}) {
4968
+ constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}, currentActorInvocation) {
4857
4969
  this.#client = client;
4970
+ this.#currentActorInvocation = currentActorInvocation;
4858
4971
  this.#driver = driver;
4859
4972
  this.#params = params;
4860
4973
  this.#getParams = getParams;
@@ -4873,6 +4986,7 @@ var ActorConnRaw = class {
4873
4986
  this.#queueSender = createQueueSender({
4874
4987
  encoding: this.#encoding,
4875
4988
  params: this.#params,
4989
+ telemetryHeaders: () => outboundTelemetryHeaders(this.#currentActorInvocation?.()),
4876
4990
  customFetch: async (request) => {
4877
4991
  return await this.#driver.sendRequest(
4878
4992
  getGatewayTarget(this.#actorResolutionState),
@@ -5930,7 +6044,7 @@ async function prepareRetryableInit(init) {
5930
6044
  }
5931
6045
  return init;
5932
6046
  }
5933
- async function rawHttpFetch(driver, target, params, input, init, options = {}) {
6047
+ async function rawHttpFetch(driver, target, params, input, init, options = {}, telemetryHeaders = {}) {
5934
6048
  let path;
5935
6049
  let originalUrl;
5936
6050
  let mergedInit = init || {};
@@ -5991,6 +6105,7 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
5991
6105
  if (params) {
5992
6106
  proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
5993
6107
  }
6108
+ addOutboundTelemetryHeaders(proxyRequestHeaders, telemetryHeaders);
5994
6109
  const proxyRequest = new Request(url, {
5995
6110
  ...mergedInit,
5996
6111
  headers: proxyRequestHeaders
@@ -6090,6 +6205,8 @@ var ActorHandleRaw = class {
6090
6205
  #resolvedActorId;
6091
6206
  #resolvingActorId;
6092
6207
  #queueSendMutex = new AsyncMutex();
6208
+ #currentActorInvocation;
6209
+ #startCallSpan;
6093
6210
  /**
6094
6211
  * Do not call this directly.
6095
6212
  *
@@ -6097,7 +6214,7 @@ var ActorHandleRaw = class {
6097
6214
  *
6098
6215
  * @protected
6099
6216
  */
6100
- constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}, signal) {
6217
+ constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}, signal, currentActorInvocation, startCallSpan) {
6101
6218
  this.#client = client;
6102
6219
  this.#driver = driver;
6103
6220
  this.#encoding = encoding;
@@ -6106,6 +6223,8 @@ var ActorHandleRaw = class {
6106
6223
  this.#params = params;
6107
6224
  this.#getParams = getParams;
6108
6225
  this.#signal = signal;
6226
+ this.#currentActorInvocation = currentActorInvocation;
6227
+ this.#startCallSpan = startCallSpan;
6109
6228
  }
6110
6229
  async #resolveConnectionParams() {
6111
6230
  if (this.#getParams) {
@@ -6136,6 +6255,9 @@ var ActorHandleRaw = class {
6136
6255
  return await createQueueSender({
6137
6256
  encoding: this.#encoding,
6138
6257
  params: this.#params,
6258
+ telemetryHeaders: () => outboundTelemetryHeaders(
6259
+ this.#currentActorInvocation?.()
6260
+ ),
6139
6261
  customFetch: async (request) => {
6140
6262
  return await this.#driver.sendRequest(
6141
6263
  target,
@@ -6216,13 +6338,33 @@ var ActorHandleRaw = class {
6216
6338
  }
6217
6339
  const signal = opts.signal ?? this.#signal;
6218
6340
  const optsWithSignal = { ...opts, signal };
6219
- const run = async () => await this.#sendActionNow(optsWithSignal);
6220
- if (opts.name === "destroy") {
6221
- return await run();
6341
+ const call = this.#startCallSpan?.(
6342
+ getActorNameFromQuery(this.#actorResolutionState),
6343
+ opts.name
6344
+ );
6345
+ const run = async () => await this.#sendActionAttempts(
6346
+ optsWithSignal,
6347
+ call?.span
6348
+ );
6349
+ const send = async () => {
6350
+ if (opts.name === "destroy") {
6351
+ return await run();
6352
+ }
6353
+ return await retryOnLifecycleBoundary(run, { signal });
6354
+ };
6355
+ if (!call) {
6356
+ return await send();
6357
+ }
6358
+ try {
6359
+ const output = await send();
6360
+ call.finish();
6361
+ return output;
6362
+ } catch (error) {
6363
+ call.finish(encodeErrorForBridge(error));
6364
+ throw error;
6222
6365
  }
6223
- return await retryOnLifecycleBoundary(run, { signal });
6224
6366
  }
6225
- async #sendActionNow(opts) {
6367
+ async #sendActionAttempts(opts, callSpan) {
6226
6368
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
6227
6369
  let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
6228
6370
  const gatewayOptions = resolveActorGatewayOptions(
@@ -6248,17 +6390,20 @@ var ActorHandleRaw = class {
6248
6390
  name: opts.name,
6249
6391
  encoding: this.#encoding
6250
6392
  });
6393
+ const headers = {
6394
+ [HEADER_ENCODING]: this.#encoding,
6395
+ ...outboundTelemetryHeaders(
6396
+ this.#currentActorInvocation?.(),
6397
+ callSpan
6398
+ )
6399
+ };
6400
+ if (this.#params !== void 0) {
6401
+ headers[HEADER_CONN_PARAMS] = JSON.stringify(this.#params);
6402
+ }
6251
6403
  const output = await sendHttpRequest({
6252
6404
  url: `http://actor/action/${encodeURIComponent(opts.name)}`,
6253
6405
  method: "POST",
6254
- headers: {
6255
- [HEADER_ENCODING]: this.#encoding,
6256
- ...this.#params !== void 0 ? {
6257
- [HEADER_CONN_PARAMS]: JSON.stringify(
6258
- this.#params
6259
- )
6260
- } : {}
6261
- },
6406
+ headers,
6262
6407
  body: opts.args,
6263
6408
  encoding: this.#encoding,
6264
6409
  customFetch: async (request) => await this.#driver.sendRequest(
@@ -6458,7 +6603,8 @@ var ActorHandleRaw = class {
6458
6603
  getParams,
6459
6604
  this.#encoding,
6460
6605
  this.#actorResolutionState,
6461
- resolveActorGatewayOptions(this.#gatewayOptions, options)
6606
+ resolveActorGatewayOptions(this.#gatewayOptions, options),
6607
+ this.#currentActorInvocation
6462
6608
  );
6463
6609
  return this.#client[CREATE_ACTOR_CONN_PROXY](
6464
6610
  conn
@@ -6483,6 +6629,9 @@ var ActorHandleRaw = class {
6483
6629
  skipReadyWait
6484
6630
  }
6485
6631
  );
6632
+ const telemetryHeaders = outboundTelemetryHeaders(
6633
+ this.#currentActorInvocation?.()
6634
+ );
6486
6635
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
6487
6636
  let actorId;
6488
6637
  try {
@@ -6499,7 +6648,8 @@ var ActorHandleRaw = class {
6499
6648
  // NOTE: This holds the body in memory until GC (unavoidable).
6500
6649
  clonesInputBody ? input.clone() : input,
6501
6650
  requestInit,
6502
- gatewayOptions
6651
+ gatewayOptions,
6652
+ telemetryHeaders
6503
6653
  );
6504
6654
  const retry = await this.#shouldRetryRawFetchResponse(
6505
6655
  response,
@@ -6720,13 +6870,17 @@ var ClientRaw = class {
6720
6870
  #driver;
6721
6871
  #encodingKind;
6722
6872
  #gatewayOptions;
6873
+ #currentActorInvocation;
6874
+ #startCallSpan;
6723
6875
  /**
6724
6876
  * Creates an instance of Client.
6725
6877
  */
6726
- constructor(driver, encoding, gatewayOptions = {}) {
6878
+ constructor(driver, options = {}) {
6727
6879
  this.#driver = driver;
6728
- this.#encodingKind = encoding ?? "bare";
6729
- this.#gatewayOptions = gatewayOptions;
6880
+ this.#encodingKind = options.encoding ?? "bare";
6881
+ this.#gatewayOptions = options.gateway ?? {};
6882
+ this.#currentActorInvocation = options.currentActorInvocation;
6883
+ this.#startCallSpan = options.startCallSpan;
6730
6884
  }
6731
6885
  /**
6732
6886
  * Gets a stateless handle to a actor by its ID.
@@ -6882,7 +7036,9 @@ var ClientRaw = class {
6882
7036
  this.#encodingKind,
6883
7037
  actorQuery,
6884
7038
  this.#gatewayOptions,
6885
- signal
7039
+ signal,
7040
+ this.#currentActorInvocation,
7041
+ this.#startCallSpan
6886
7042
  );
6887
7043
  }
6888
7044
  [CREATE_ACTOR_CONN_PROXY](conn) {
@@ -6909,8 +7065,8 @@ var ClientRaw = class {
6909
7065
  await Promise.all(disposePromises);
6910
7066
  }
6911
7067
  };
6912
- function createClientWithDriver(driver, config = {}) {
6913
- const client = new ClientRaw(driver, config.encoding, config.gateway);
7068
+ function createClientWithDriver(driver, options = {}) {
7069
+ const client = new ClientRaw(driver, options);
6914
7070
  return new Proxy(client, {
6915
7071
  get: (target, prop, receiver) => {
6916
7072
  if (typeof prop === "symbol" || prop in target) {