@trigger.dev/core 3.0.0-beta.0 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/v3/index.js CHANGED
@@ -9,6 +9,7 @@ var nodePath = require('path');
9
9
  var apiLogs = require('@opentelemetry/api-logs');
10
10
  var preciseDate = require('@google-cloud/precise-date');
11
11
  var humanizeDuration = require('humanize-duration');
12
+ var promises = require('timers/promises');
12
13
  var util = require('util');
13
14
  var exporterLogsOtlpHttp = require('@opentelemetry/exporter-logs-otlp-http');
14
15
  var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');
@@ -17,7 +18,6 @@ var resources = require('@opentelemetry/resources');
17
18
  var sdkLogs = require('@opentelemetry/sdk-logs');
18
19
  var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
19
20
  var semanticConventions = require('@opentelemetry/semantic-conventions');
20
- var superjson = require('superjson');
21
21
 
22
22
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
23
23
 
@@ -225,6 +225,32 @@ var BatchTaskRunExecutionResult = zod.z.object({
225
225
  });
226
226
 
227
227
  // src/v3/schemas/messages.ts
228
+ var EnvironmentType = zod.z.enum([
229
+ "PRODUCTION",
230
+ "STAGING",
231
+ "DEVELOPMENT",
232
+ "PREVIEW"
233
+ ]);
234
+ var MachineCpu = zod.z.union([
235
+ zod.z.literal(0.25),
236
+ zod.z.literal(0.5),
237
+ zod.z.literal(1),
238
+ zod.z.literal(2),
239
+ zod.z.literal(4)
240
+ ]).default(0.5);
241
+ var MachineMemory = zod.z.union([
242
+ zod.z.literal(0.25),
243
+ zod.z.literal(0.5),
244
+ zod.z.literal(1),
245
+ zod.z.literal(2),
246
+ zod.z.literal(4),
247
+ zod.z.literal(8)
248
+ ]).default(1);
249
+ var Machine = zod.z.object({
250
+ version: zod.z.literal("v1").default("v1"),
251
+ cpu: MachineCpu,
252
+ memory: MachineMemory
253
+ });
228
254
  var TaskRunExecutionPayload = zod.z.object({
229
255
  execution: TaskRunExecution,
230
256
  traceContext: zod.z.record(zod.z.unknown()),
@@ -254,11 +280,16 @@ var BackgroundWorkerServerMessages = zod.z.discriminatedUnion("type", [
254
280
  }),
255
281
  zod.z.object({
256
282
  type: zod.z.literal("SCHEDULE_ATTEMPT"),
257
- id: zod.z.string(),
258
283
  image: zod.z.string(),
284
+ version: zod.z.string(),
285
+ machine: Machine,
286
+ // identifiers
287
+ id: zod.z.string(),
259
288
  envId: zod.z.string(),
260
- runId: zod.z.string(),
261
- version: zod.z.string()
289
+ envType: EnvironmentType,
290
+ orgId: zod.z.string(),
291
+ projectId: zod.z.string(),
292
+ runId: zod.z.string()
262
293
  })
263
294
  ]);
264
295
  var serverWebsocketMessages = {
@@ -420,7 +451,8 @@ var TaskMetadata = zod.z.object({
420
451
  exportName: zod.z.string(),
421
452
  packageVersion: zod.z.string(),
422
453
  queue: QueueOptions.optional(),
423
- retry: RetryOptions.optional()
454
+ retry: RetryOptions.optional(),
455
+ machine: Machine.partial().optional()
424
456
  });
425
457
  var TaskMetadataWithFilePath = TaskMetadata.extend({
426
458
  filePath: zod.z.string()
@@ -564,7 +596,8 @@ var TaskResource = zod.z.object({
564
596
  filePath: zod.z.string(),
565
597
  exportName: zod.z.string(),
566
598
  queue: QueueOptions.optional(),
567
- retry: RetryOptions.optional()
599
+ retry: RetryOptions.optional(),
600
+ machine: Machine.partial().optional()
568
601
  });
569
602
  var BackgroundWorkerMetadata = zod.z.object({
570
603
  packageVersion: zod.z.string(),
@@ -709,6 +742,14 @@ var GetDeploymentResponseBody = zod.z.object({
709
742
  var CreateUploadPayloadUrlResponseBody = zod.z.object({
710
743
  presignedUrl: zod.z.string()
711
744
  });
745
+ var PostStartCauses = zod.z.enum([
746
+ "index",
747
+ "create",
748
+ "restore"
749
+ ]);
750
+ var PreStopCauses = zod.z.enum([
751
+ "terminate"
752
+ ]);
712
753
  var RegexSchema = zod.z.custom((val) => {
713
754
  try {
714
755
  return typeof val.test === "function";
@@ -733,10 +774,6 @@ var Config = zod.z.object({
733
774
  RegexSchema
734
775
  ])).optional()
735
776
  });
736
- var Machine = zod.z.object({
737
- cpu: zod.z.string().default("1").optional(),
738
- memory: zod.z.string().default("500Mi").optional()
739
- });
740
777
  var WaitReason = zod.z.enum([
741
778
  "WAIT_FOR_DURATION",
742
779
  "WAIT_FOR_TASK",
@@ -773,9 +810,13 @@ var PlatformToProviderMessages = {
773
810
  version: zod.z.literal("v1").default("v1"),
774
811
  imageTag: zod.z.string(),
775
812
  shortCode: zod.z.string(),
776
- envId: zod.z.string(),
777
813
  apiKey: zod.z.string(),
778
- apiUrl: zod.z.string()
814
+ apiUrl: zod.z.string(),
815
+ // identifiers
816
+ envId: zod.z.string(),
817
+ envType: EnvironmentType,
818
+ orgId: zod.z.string(),
819
+ projectId: zod.z.string()
779
820
  }),
780
821
  callback: zod.z.discriminatedUnion("success", [
781
822
  zod.z.object({
@@ -791,25 +832,25 @@ var PlatformToProviderMessages = {
791
832
  })
792
833
  ])
793
834
  },
794
- INVOKE: {
795
- message: zod.z.object({
796
- version: zod.z.literal("v1").default("v1"),
797
- name: zod.z.string(),
798
- machine: Machine
799
- })
800
- },
835
+ // TODO: this should be a shared queue message instead
801
836
  RESTORE: {
802
837
  message: zod.z.object({
803
838
  version: zod.z.literal("v1").default("v1"),
804
- checkpointId: zod.z.string(),
805
- runId: zod.z.string(),
806
839
  type: zod.z.enum([
807
840
  "DOCKER",
808
841
  "KUBERNETES"
809
842
  ]),
810
843
  location: zod.z.string(),
811
844
  reason: zod.z.string().optional(),
812
- imageRef: zod.z.string()
845
+ imageRef: zod.z.string(),
846
+ machine: Machine,
847
+ // identifiers
848
+ checkpointId: zod.z.string(),
849
+ envId: zod.z.string(),
850
+ envType: EnvironmentType,
851
+ orgId: zod.z.string(),
852
+ projectId: zod.z.string(),
853
+ runId: zod.z.string()
813
854
  })
814
855
  },
815
856
  DELETE: {
@@ -2051,16 +2092,23 @@ var _ZodSocketConnection = class _ZodSocketConnection {
2051
2092
  __privateAdd(this, _sender2, void 0);
2052
2093
  __privateAdd(this, _handler, void 0);
2053
2094
  __privateAdd(this, _logger, void 0);
2054
- this.socket = socket_ioClient.io(`ws://${opts.host}:${opts.port}/${opts.namespace}`, {
2095
+ const uri = `${opts.secure ? "wss" : "ws"}://${opts.host}:${opts.port ?? (opts.secure ? "443" : "80")}/${opts.namespace}`;
2096
+ const logger2 = new SimpleStructuredLogger(opts.namespace, exports.LogLevel.info);
2097
+ logger2.log("new zod socket", {
2098
+ uri
2099
+ });
2100
+ this.socket = socket_ioClient.io(uri, {
2055
2101
  transports: [
2056
2102
  "websocket"
2057
2103
  ],
2058
2104
  auth: {
2059
2105
  token: opts.authToken
2060
2106
  },
2061
- extraHeaders: opts.extraHeaders
2107
+ extraHeaders: opts.extraHeaders,
2108
+ reconnectionDelay: 500,
2109
+ reconnectionDelayMax: 1e3
2062
2110
  });
2063
- __privateSet(this, _logger, new SimpleStructuredLogger(opts.namespace, exports.LogLevel.info, {
2111
+ __privateSet(this, _logger, logger2.child({
2064
2112
  socketId: this.socket.id
2065
2113
  }));
2066
2114
  __privateSet(this, _handler, new ZodSocketMessageHandler({
@@ -2717,24 +2765,54 @@ function iconStringForSeverity(severityNumber) {
2717
2765
  }
2718
2766
  }
2719
2767
  __name(iconStringForSeverity, "iconStringForSeverity");
2720
- function preciseDateOriginNow() {
2721
- return {
2722
- hrtime: process.hrtime(),
2723
- timestamp: new preciseDate.PreciseDate()
2724
- };
2725
- }
2726
- __name(preciseDateOriginNow, "preciseDateOriginNow");
2727
- function calculatePreciseDateHrTime(origin) {
2728
- const elapsedHrTime = process.hrtime(origin.hrtime);
2729
- const elapsedNanoseconds = BigInt(elapsedHrTime[0]) * BigInt(1e9) + BigInt(elapsedHrTime[1]);
2730
- const preciseDate$1 = new preciseDate.PreciseDate(origin.timestamp.getFullTime() + elapsedNanoseconds);
2731
- const dateStruct = preciseDate$1.toStruct();
2732
- return [
2733
- dateStruct.seconds,
2734
- dateStruct.nanos
2735
- ];
2736
- }
2737
- __name(calculatePreciseDateHrTime, "calculatePreciseDateHrTime");
2768
+ var _SimpleClock = class _SimpleClock {
2769
+ preciseNow() {
2770
+ const now = new preciseDate.PreciseDate();
2771
+ const nowStruct = now.toStruct();
2772
+ return [
2773
+ nowStruct.seconds,
2774
+ nowStruct.nanos
2775
+ ];
2776
+ }
2777
+ reset() {
2778
+ }
2779
+ };
2780
+ __name(_SimpleClock, "SimpleClock");
2781
+ var SimpleClock = _SimpleClock;
2782
+
2783
+ // src/v3/clock/index.ts
2784
+ var API_NAME2 = "clock";
2785
+ var SIMPLE_CLOCK = new SimpleClock();
2786
+ var _getClock, getClock_fn;
2787
+ var _ClockAPI = class _ClockAPI {
2788
+ constructor() {
2789
+ __privateAdd(this, _getClock);
2790
+ }
2791
+ static getInstance() {
2792
+ if (!this._instance) {
2793
+ this._instance = new _ClockAPI();
2794
+ }
2795
+ return this._instance;
2796
+ }
2797
+ setGlobalClock(clock2) {
2798
+ return registerGlobal(API_NAME2, clock2);
2799
+ }
2800
+ preciseNow() {
2801
+ return __privateMethod(this, _getClock, getClock_fn).call(this).preciseNow();
2802
+ }
2803
+ reset() {
2804
+ __privateMethod(this, _getClock, getClock_fn).call(this).reset();
2805
+ }
2806
+ };
2807
+ _getClock = new WeakSet();
2808
+ getClock_fn = /* @__PURE__ */ __name(function() {
2809
+ return getGlobal(API_NAME2) ?? SIMPLE_CLOCK;
2810
+ }, "#getClock");
2811
+ __name(_ClockAPI, "ClockAPI");
2812
+ var ClockAPI = _ClockAPI;
2813
+
2814
+ // src/v3/clock-api.ts
2815
+ var clock = ClockAPI.getInstance();
2738
2816
 
2739
2817
  // src/v3/logger/taskLogger.ts
2740
2818
  var logLevels = [
@@ -2755,35 +2833,34 @@ var _OtelTaskLogger = class _OtelTaskLogger {
2755
2833
  debug(message, properties) {
2756
2834
  if (this._level < 4)
2757
2835
  return;
2758
- __privateMethod(this, _emitLog, emitLog_fn).call(this, message, "debug", apiLogs.SeverityNumber.DEBUG, properties);
2836
+ __privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "debug", apiLogs.SeverityNumber.DEBUG, properties);
2759
2837
  }
2760
2838
  log(message, properties) {
2761
2839
  if (this._level < 2)
2762
2840
  return;
2763
- __privateMethod(this, _emitLog, emitLog_fn).call(this, message, "log", apiLogs.SeverityNumber.INFO, properties);
2841
+ __privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "log", apiLogs.SeverityNumber.INFO, properties);
2764
2842
  }
2765
2843
  info(message, properties) {
2766
2844
  if (this._level < 3)
2767
2845
  return;
2768
- __privateMethod(this, _emitLog, emitLog_fn).call(this, message, "info", apiLogs.SeverityNumber.INFO, properties);
2846
+ __privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "info", apiLogs.SeverityNumber.INFO, properties);
2769
2847
  }
2770
2848
  warn(message, properties) {
2771
2849
  if (this._level < 1)
2772
2850
  return;
2773
- __privateMethod(this, _emitLog, emitLog_fn).call(this, message, "warn", apiLogs.SeverityNumber.WARN, properties);
2851
+ __privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "warn", apiLogs.SeverityNumber.WARN, properties);
2774
2852
  }
2775
2853
  error(message, properties) {
2776
2854
  if (this._level < 0)
2777
2855
  return;
2778
- __privateMethod(this, _emitLog, emitLog_fn).call(this, message, "error", apiLogs.SeverityNumber.ERROR, properties);
2856
+ __privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "error", apiLogs.SeverityNumber.ERROR, properties);
2779
2857
  }
2780
2858
  trace(name, fn, options) {
2781
2859
  return this._config.tracer.startActiveSpan(name, fn, options);
2782
2860
  }
2783
2861
  };
2784
2862
  _emitLog = new WeakSet();
2785
- emitLog_fn = /* @__PURE__ */ __name(function(message, severityText, severityNumber, properties) {
2786
- const timestamp = __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this);
2863
+ emitLog_fn = /* @__PURE__ */ __name(function(message, timestamp, severityText, severityNumber, properties) {
2787
2864
  let attributes = {
2788
2865
  ...flattenAttributes(properties)
2789
2866
  };
@@ -2801,7 +2878,7 @@ emitLog_fn = /* @__PURE__ */ __name(function(message, severityText, severityNumb
2801
2878
  }, "#emitLog");
2802
2879
  _getTimestampInHrTime = new WeakSet();
2803
2880
  getTimestampInHrTime_fn = /* @__PURE__ */ __name(function() {
2804
- return calculatePreciseDateHrTime(this._config.preciseDateOrigin);
2881
+ return clock.preciseNow();
2805
2882
  }, "#getTimestampInHrTime");
2806
2883
  __name(_OtelTaskLogger, "OtelTaskLogger");
2807
2884
  var OtelTaskLogger = _OtelTaskLogger;
@@ -2824,7 +2901,7 @@ __name(_NoopTaskLogger, "NoopTaskLogger");
2824
2901
  var NoopTaskLogger = _NoopTaskLogger;
2825
2902
 
2826
2903
  // src/v3/logger/index.ts
2827
- var API_NAME2 = "logger";
2904
+ var API_NAME3 = "logger";
2828
2905
  var NOOP_TASK_LOGGER = new NoopTaskLogger();
2829
2906
  var _getTaskLogger, getTaskLogger_fn;
2830
2907
  var _LoggerAPI = class _LoggerAPI {
@@ -2838,10 +2915,10 @@ var _LoggerAPI = class _LoggerAPI {
2838
2915
  return this._instance;
2839
2916
  }
2840
2917
  disable() {
2841
- unregisterGlobal(API_NAME2);
2918
+ unregisterGlobal(API_NAME3);
2842
2919
  }
2843
2920
  setGlobalTaskLogger(taskLogger) {
2844
- return registerGlobal(API_NAME2, taskLogger);
2921
+ return registerGlobal(API_NAME3, taskLogger);
2845
2922
  }
2846
2923
  debug(message, metadata) {
2847
2924
  __privateMethod(this, _getTaskLogger, getTaskLogger_fn).call(this).debug(message, metadata);
@@ -2864,7 +2941,7 @@ var _LoggerAPI = class _LoggerAPI {
2864
2941
  };
2865
2942
  _getTaskLogger = new WeakSet();
2866
2943
  getTaskLogger_fn = /* @__PURE__ */ __name(function() {
2867
- return getGlobal(API_NAME2) ?? NOOP_TASK_LOGGER;
2944
+ return getGlobal(API_NAME3) ?? NOOP_TASK_LOGGER;
2868
2945
  }, "#getTaskLogger");
2869
2946
  __name(_LoggerAPI, "LoggerAPI");
2870
2947
  var LoggerAPI = _LoggerAPI;
@@ -3079,11 +3156,10 @@ var _DevRuntimeManager = class _DevRuntimeManager {
3079
3156
  };
3080
3157
  __name(_DevRuntimeManager, "DevRuntimeManager");
3081
3158
  var DevRuntimeManager = _DevRuntimeManager;
3082
-
3083
- // src/v3/runtime/prodRuntimeManager.ts
3084
3159
  var _ProdRuntimeManager = class _ProdRuntimeManager {
3085
- constructor(ipc) {
3160
+ constructor(ipc, options = {}) {
3086
3161
  this.ipc = ipc;
3162
+ this.options = options;
3087
3163
  this._taskWaits = /* @__PURE__ */ new Map();
3088
3164
  this._batchWaits = /* @__PURE__ */ new Map();
3089
3165
  this._tasks = /* @__PURE__ */ new Map();
@@ -3099,12 +3175,9 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
3099
3175
  return this._tasks.get(id);
3100
3176
  }
3101
3177
  async waitForDuration(ms) {
3102
- let timeout;
3103
3178
  const now = Date.now();
3104
- const resolveAfterDuration = new Promise((resolve) => {
3105
- timeout = setTimeout(resolve, ms);
3106
- });
3107
- if (ms < 1e4) {
3179
+ const resolveAfterDuration = promises.setTimeout(ms, "duration");
3180
+ if (ms <= this.waitThresholdInMs) {
3108
3181
  await resolveAfterDuration;
3109
3182
  return;
3110
3183
  }
@@ -3128,13 +3201,13 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
3128
3201
  resolveAfterDuration
3129
3202
  ]);
3130
3203
  this.ipc.send("CANCEL_CHECKPOINT", {});
3131
- clearTimeout(timeout);
3132
3204
  }
3133
3205
  resumeAfterRestore() {
3134
3206
  if (!this._waitForRestore) {
3135
3207
  return;
3136
3208
  }
3137
- this._waitForRestore.resolve();
3209
+ clock.reset();
3210
+ this._waitForRestore.resolve("restore");
3138
3211
  this._waitForRestore = void 0;
3139
3212
  }
3140
3213
  async waitUntil(date) {
@@ -3189,9 +3262,49 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
3189
3262
  }
3190
3263
  this._taskWaits.delete(execution.run.id);
3191
3264
  }
3265
+ get waitThresholdInMs() {
3266
+ return this.options.waitThresholdInMs ?? 3e4;
3267
+ }
3192
3268
  };
3193
3269
  __name(_ProdRuntimeManager, "ProdRuntimeManager");
3194
3270
  var ProdRuntimeManager = _ProdRuntimeManager;
3271
+ var _originClockTime, originClockTime_get, _originPreciseDate, originPreciseDate_get;
3272
+ var _PreciseWallClock = class _PreciseWallClock {
3273
+ constructor(options = {}) {
3274
+ __privateAdd(this, _originClockTime);
3275
+ __privateAdd(this, _originPreciseDate);
3276
+ this._origin = {
3277
+ clockTime: options.origin ?? process.hrtime(),
3278
+ preciseDate: options.now ?? new preciseDate.PreciseDate()
3279
+ };
3280
+ }
3281
+ preciseNow() {
3282
+ const elapsedHrTime = process.hrtime(__privateGet(this, _originClockTime, originClockTime_get));
3283
+ const elapsedNanoseconds = BigInt(elapsedHrTime[0]) * BigInt(1e9) + BigInt(elapsedHrTime[1]);
3284
+ const preciseDate$1 = new preciseDate.PreciseDate(__privateGet(this, _originPreciseDate, originPreciseDate_get).getFullTime() + elapsedNanoseconds);
3285
+ const dateStruct = preciseDate$1.toStruct();
3286
+ return [
3287
+ dateStruct.seconds,
3288
+ dateStruct.nanos
3289
+ ];
3290
+ }
3291
+ reset() {
3292
+ this._origin = {
3293
+ clockTime: process.hrtime(),
3294
+ preciseDate: new preciseDate.PreciseDate()
3295
+ };
3296
+ }
3297
+ };
3298
+ _originClockTime = new WeakSet();
3299
+ originClockTime_get = /* @__PURE__ */ __name(function() {
3300
+ return this._origin.clockTime;
3301
+ }, "#originClockTime");
3302
+ _originPreciseDate = new WeakSet();
3303
+ originPreciseDate_get = /* @__PURE__ */ __name(function() {
3304
+ return this._origin.preciseDate;
3305
+ }, "#originPreciseDate");
3306
+ __name(_PreciseWallClock, "PreciseWallClock");
3307
+ var PreciseWallClock = _PreciseWallClock;
3195
3308
  var _TriggerTracer = class _TriggerTracer {
3196
3309
  constructor(_config) {
3197
3310
  this._config = _config;
@@ -3220,7 +3333,8 @@ var _TriggerTracer = class _TriggerTracer {
3220
3333
  const attributes = options?.attributes ?? {};
3221
3334
  return this.tracer.startActiveSpan(name, {
3222
3335
  ...options,
3223
- attributes
3336
+ attributes,
3337
+ startTime: clock.preciseNow()
3224
3338
  }, parentContext, async (span) => {
3225
3339
  this.tracer.startSpan(name, {
3226
3340
  ...options,
@@ -3241,7 +3355,7 @@ var _TriggerTracer = class _TriggerTracer {
3241
3355
  });
3242
3356
  throw e;
3243
3357
  } finally {
3244
- span.end();
3358
+ span.end(clock.preciseNow());
3245
3359
  }
3246
3360
  });
3247
3361
  }
@@ -3264,12 +3378,11 @@ __name(_TriggerTracer, "TriggerTracer");
3264
3378
  var TriggerTracer = _TriggerTracer;
3265
3379
  var _handleLog, handleLog_fn, _getTimestampInHrTime2, getTimestampInHrTime_fn2, _getAttributes, getAttributes_fn;
3266
3380
  var _ConsoleInterceptor = class _ConsoleInterceptor {
3267
- constructor(logger2, preciseDateOrigin) {
3381
+ constructor(logger2) {
3268
3382
  __privateAdd(this, _handleLog);
3269
3383
  __privateAdd(this, _getTimestampInHrTime2);
3270
3384
  __privateAdd(this, _getAttributes);
3271
3385
  this.logger = logger2;
3272
- this.preciseDateOrigin = preciseDateOrigin;
3273
3386
  }
3274
3387
  // Intercept the console and send logs to the OpenTelemetry logger
3275
3388
  // during the execution of the callback
@@ -3294,22 +3407,21 @@ var _ConsoleInterceptor = class _ConsoleInterceptor {
3294
3407
  }
3295
3408
  }
3296
3409
  log(...args) {
3297
- __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, "Log", ...args);
3410
+ __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Log", ...args);
3298
3411
  }
3299
3412
  info(...args) {
3300
- __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, "Info", ...args);
3413
+ __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Info", ...args);
3301
3414
  }
3302
3415
  warn(...args) {
3303
- __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.WARN, "Warn", ...args);
3416
+ __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.WARN, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Warn", ...args);
3304
3417
  }
3305
3418
  error(...args) {
3306
- __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.ERROR, "Error", ...args);
3419
+ __privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.ERROR, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Error", ...args);
3307
3420
  }
3308
3421
  };
3309
3422
  _handleLog = new WeakSet();
3310
- handleLog_fn = /* @__PURE__ */ __name(function(severityNumber, severityText, ...args) {
3423
+ handleLog_fn = /* @__PURE__ */ __name(function(severityNumber, timestamp, severityText, ...args) {
3311
3424
  const body = util__default.default.format(...args);
3312
- const timestamp = __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this);
3313
3425
  const parsed = tryParseJSON(body);
3314
3426
  if (parsed.ok) {
3315
3427
  this.logger.emit({
@@ -3334,7 +3446,7 @@ handleLog_fn = /* @__PURE__ */ __name(function(severityNumber, severityText, ...
3334
3446
  }, "#handleLog");
3335
3447
  _getTimestampInHrTime2 = new WeakSet();
3336
3448
  getTimestampInHrTime_fn2 = /* @__PURE__ */ __name(function() {
3337
- return calculatePreciseDateHrTime(this.preciseDateOrigin);
3449
+ return clock.preciseNow();
3338
3450
  }, "#getTimestampInHrTime");
3339
3451
  _getAttributes = new WeakSet();
3340
3452
  getAttributes_fn = /* @__PURE__ */ __name(function(severityNumber1) {
@@ -3720,7 +3832,12 @@ var _TracingSDK = class _TracingSDK {
3720
3832
  url: `${config.url}/v1/traces`,
3721
3833
  timeoutMillis: config.forceFlushTimeoutMillis ?? 1e3
3722
3834
  });
3723
- traceProvider.addSpanProcessor(new TaskContextSpanProcessor(new sdkTraceNode.SimpleSpanProcessor(spanExporter)));
3835
+ traceProvider.addSpanProcessor(new TaskContextSpanProcessor(getEnvVar("OTEL_BATCH_PROCESSING_ENABLED") === "1" ? new sdkTraceNode.BatchSpanProcessor(spanExporter, {
3836
+ maxExportBatchSize: parseInt(getEnvVar("OTEL_SPAN_MAX_EXPORT_BATCH_SIZE") ?? "64"),
3837
+ scheduledDelayMillis: parseInt(getEnvVar("OTEL_SPAN_SCHEDULED_DELAY_MILLIS") ?? "200"),
3838
+ exportTimeoutMillis: parseInt(getEnvVar("OTEL_SPAN_EXPORT_TIMEOUT_MILLIS") ?? "30000"),
3839
+ maxQueueSize: parseInt(getEnvVar("OTEL_SPAN_MAX_QUEUE_SIZE") ?? "512")
3840
+ }) : new sdkTraceNode.SimpleSpanProcessor(spanExporter)));
3724
3841
  traceProvider.register();
3725
3842
  instrumentation.registerInstrumentations({
3726
3843
  instrumentations: config.instrumentations ?? [],
@@ -3736,7 +3853,12 @@ var _TracingSDK = class _TracingSDK {
3736
3853
  attributeValueLengthLimit: OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT
3737
3854
  }
3738
3855
  });
3739
- loggerProvider.addLogRecordProcessor(new TaskContextLogProcessor(new sdkLogs.SimpleLogRecordProcessor(logExporter)));
3856
+ loggerProvider.addLogRecordProcessor(new TaskContextLogProcessor(getEnvVar("OTEL_BATCH_PROCESSING_ENABLED") === "1" ? new sdkLogs.BatchLogRecordProcessor(logExporter, {
3857
+ maxExportBatchSize: parseInt(getEnvVar("OTEL_LOG_MAX_EXPORT_BATCH_SIZE") ?? "64"),
3858
+ scheduledDelayMillis: parseInt(getEnvVar("OTEL_LOG_SCHEDULED_DELAY_MILLIS") ?? "200"),
3859
+ exportTimeoutMillis: parseInt(getEnvVar("OTEL_LOG_EXPORT_TIMEOUT_MILLIS") ?? "30000"),
3860
+ maxQueueSize: parseInt(getEnvVar("OTEL_LOG_MAX_QUEUE_SIZE") ?? "512")
3861
+ }) : new sdkLogs.SimpleLogRecordProcessor(logExporter)));
3740
3862
  this._logProvider = loggerProvider;
3741
3863
  this._spanExporter = spanExporter;
3742
3864
  this._traceProvider = traceProvider;
@@ -3800,7 +3922,9 @@ function recordSpanException(span, error) {
3800
3922
  });
3801
3923
  }
3802
3924
  __name(recordSpanException, "recordSpanException");
3803
- function parsePacket(value) {
3925
+
3926
+ // src/v3/utils/ioSerialization.ts
3927
+ async function parsePacket(value) {
3804
3928
  if (!value.data) {
3805
3929
  return void 0;
3806
3930
  }
@@ -3808,7 +3932,8 @@ function parsePacket(value) {
3808
3932
  case "application/json":
3809
3933
  return JSON.parse(value.data);
3810
3934
  case "application/super+json":
3811
- return superjson.parse(value.data);
3935
+ const { parse } = await loadSuperJSON();
3936
+ return parse(value.data);
3812
3937
  case "text/plain":
3813
3938
  return value.data;
3814
3939
  case "application/store":
@@ -3818,7 +3943,7 @@ function parsePacket(value) {
3818
3943
  }
3819
3944
  }
3820
3945
  __name(parsePacket, "parsePacket");
3821
- function stringifyIO(value) {
3946
+ async function stringifyIO(value) {
3822
3947
  if (value === void 0) {
3823
3948
  return {
3824
3949
  dataType: "application/json"
@@ -3830,10 +3955,18 @@ function stringifyIO(value) {
3830
3955
  dataType: "text/plain"
3831
3956
  };
3832
3957
  }
3833
- return {
3834
- data: superjson.stringify(value),
3835
- dataType: "application/super+json"
3836
- };
3958
+ try {
3959
+ const { stringify } = await loadSuperJSON();
3960
+ const data = stringify(value);
3961
+ return {
3962
+ data,
3963
+ dataType: "application/super+json"
3964
+ };
3965
+ } catch {
3966
+ return {
3967
+ dataType: "application/json"
3968
+ };
3969
+ }
3837
3970
  }
3838
3971
  __name(stringifyIO, "stringifyIO");
3839
3972
  async function conditionallyExportPacket(packet, pathPrefix, tracer) {
@@ -3935,9 +4068,9 @@ async function importPacket(packet, span) {
3935
4068
  return packet;
3936
4069
  }
3937
4070
  __name(importPacket, "importPacket");
3938
- function createPacketAttributes(packet, dataKey, dataTypeKey) {
4071
+ async function createPacketAttributes(packet, dataKey, dataTypeKey) {
3939
4072
  if (!packet.data) {
3940
- return {};
4073
+ return;
3941
4074
  }
3942
4075
  switch (packet.dataType) {
3943
4076
  case "application/json":
@@ -3946,12 +4079,20 @@ function createPacketAttributes(packet, dataKey, dataTypeKey) {
3946
4079
  [dataTypeKey]: packet.dataType
3947
4080
  };
3948
4081
  case "application/super+json":
3949
- const parsed = superjson.parse(packet.data);
3950
- const jsonified = JSON.parse(JSON.stringify(parsed, safeReplacer));
3951
- return {
3952
- ...flattenAttributes(jsonified, dataKey),
3953
- [dataTypeKey]: "application/json"
3954
- };
4082
+ const { parse } = await loadSuperJSON();
4083
+ if (typeof packet.data === "undefined" || packet.data === null) {
4084
+ return;
4085
+ }
4086
+ try {
4087
+ const parsed = parse(packet.data);
4088
+ const jsonified = JSON.parse(JSON.stringify(parsed, safeReplacer));
4089
+ return {
4090
+ ...flattenAttributes(jsonified, dataKey),
4091
+ [dataTypeKey]: "application/json"
4092
+ };
4093
+ } catch {
4094
+ return;
4095
+ }
3955
4096
  case "application/store":
3956
4097
  return {
3957
4098
  [dataKey]: packet.data,
@@ -3959,15 +4100,15 @@ function createPacketAttributes(packet, dataKey, dataTypeKey) {
3959
4100
  };
3960
4101
  case "text/plain":
3961
4102
  return {
3962
- [SemanticInternalAttributes.OUTPUT]: packet.data,
3963
- [SemanticInternalAttributes.OUTPUT_TYPE]: packet.dataType
4103
+ [dataKey]: packet.data,
4104
+ [dataTypeKey]: packet.dataType
3964
4105
  };
3965
4106
  default:
3966
- return {};
4107
+ return;
3967
4108
  }
3968
4109
  }
3969
4110
  __name(createPacketAttributes, "createPacketAttributes");
3970
- function createPackageAttributesAsJson(data, dataType) {
4111
+ async function createPacketAttributesAsJson(data, dataType) {
3971
4112
  if (typeof data === "string" || typeof data === "number" || typeof data === "boolean" || data === null || data === void 0) {
3972
4113
  return data;
3973
4114
  }
@@ -3975,8 +4116,9 @@ function createPackageAttributesAsJson(data, dataType) {
3975
4116
  case "application/json":
3976
4117
  return imposeAttributeLimits(flattenAttributes(data, void 0));
3977
4118
  case "application/super+json":
3978
- const deserialized = superjson.deserialize(data);
3979
- const jsonify = JSON.parse(JSON.stringify(deserialized, safeReplacer));
4119
+ const { deserialize } = await loadSuperJSON();
4120
+ const deserialized = deserialize(data);
4121
+ const jsonify = safeJsonParse(JSON.stringify(deserialized, safeReplacer));
3980
4122
  return imposeAttributeLimits(flattenAttributes(jsonify, void 0));
3981
4123
  case "application/store":
3982
4124
  return data;
@@ -3984,13 +4126,14 @@ function createPackageAttributesAsJson(data, dataType) {
3984
4126
  return {};
3985
4127
  }
3986
4128
  }
3987
- __name(createPackageAttributesAsJson, "createPackageAttributesAsJson");
3988
- function prettyPrintPacket(rawData, dataType) {
4129
+ __name(createPacketAttributesAsJson, "createPacketAttributesAsJson");
4130
+ async function prettyPrintPacket(rawData, dataType) {
3989
4131
  if (rawData === void 0) {
3990
4132
  return "";
3991
4133
  }
3992
4134
  if (dataType === "application/super+json") {
3993
- return prettyPrintPacket(superjson.deserialize(rawData), "application/json");
4135
+ const { deserialize } = await loadSuperJSON();
4136
+ return await prettyPrintPacket(deserialize(rawData), "application/json");
3994
4137
  }
3995
4138
  if (dataType === "application/json") {
3996
4139
  return JSON.stringify(rawData, safeReplacer, 2);
@@ -4034,6 +4177,18 @@ function getPacketExtension(outputType) {
4034
4177
  }
4035
4178
  }
4036
4179
  __name(getPacketExtension, "getPacketExtension");
4180
+ async function loadSuperJSON() {
4181
+ return await import('superjson');
4182
+ }
4183
+ __name(loadSuperJSON, "loadSuperJSON");
4184
+ function safeJsonParse(value) {
4185
+ try {
4186
+ return JSON.parse(value);
4187
+ } catch {
4188
+ return;
4189
+ }
4190
+ }
4191
+ __name(safeJsonParse, "safeJsonParse");
4037
4192
 
4038
4193
  // src/v3/workers/taskExecutor.ts
4039
4194
  var _callRun, callRun_fn, _callTaskInit, callTaskInit_fn, _callTaskCleanup, callTaskCleanup_fn, _handleError, handleError_fn;
@@ -4073,13 +4228,16 @@ var _TaskExecutor = class _TaskExecutor {
4073
4228
  let initOutput;
4074
4229
  try {
4075
4230
  const payloadPacket = await conditionallyImportPacket(originalPacket, this._tracer);
4076
- parsedPayload = parsePacket(payloadPacket);
4231
+ parsedPayload = await parsePacket(payloadPacket);
4077
4232
  initOutput = await __privateMethod(this, _callTaskInit, callTaskInit_fn).call(this, parsedPayload, ctx);
4078
4233
  const output = await __privateMethod(this, _callRun, callRun_fn).call(this, parsedPayload, ctx, initOutput);
4079
4234
  try {
4080
- const stringifiedOutput = stringifyIO(output);
4235
+ const stringifiedOutput = await stringifyIO(output);
4081
4236
  const finalOutput = await conditionallyExportPacket(stringifiedOutput, `${execution.attempt.id}/output`, this._tracer);
4082
- span.setAttributes(createPacketAttributes(finalOutput, SemanticInternalAttributes.OUTPUT, SemanticInternalAttributes.OUTPUT_TYPE));
4237
+ const attributes = await createPacketAttributes(finalOutput, SemanticInternalAttributes.OUTPUT, SemanticInternalAttributes.OUTPUT_TYPE);
4238
+ if (attributes) {
4239
+ span.setAttributes(attributes);
4240
+ }
4083
4241
  return {
4084
4242
  ok: true,
4085
4243
  id: execution.attempt.id,
@@ -4341,6 +4499,8 @@ exports.CreateBackgroundWorkerRequestBody = CreateBackgroundWorkerRequestBody;
4341
4499
  exports.CreateBackgroundWorkerResponse = CreateBackgroundWorkerResponse;
4342
4500
  exports.CreateUploadPayloadUrlResponseBody = CreateUploadPayloadUrlResponseBody;
4343
4501
  exports.DevRuntimeManager = DevRuntimeManager;
4502
+ exports.DurableClock = PreciseWallClock;
4503
+ exports.EnvironmentType = EnvironmentType;
4344
4504
  exports.EventFilter = EventFilter;
4345
4505
  exports.ExceptionEventProperties = ExceptionEventProperties;
4346
4506
  exports.ExceptionSpanEvent = ExceptionSpanEvent;
@@ -4364,6 +4524,8 @@ exports.ImageDetailsMetadata = ImageDetailsMetadata;
4364
4524
  exports.InitializeDeploymentRequestBody = InitializeDeploymentRequestBody;
4365
4525
  exports.InitializeDeploymentResponseBody = InitializeDeploymentResponseBody;
4366
4526
  exports.Machine = Machine;
4527
+ exports.MachineCpu = MachineCpu;
4528
+ exports.MachineMemory = MachineMemory;
4367
4529
  exports.OFFLOAD_IO_PACKET_LENGTH_LIMIT = OFFLOAD_IO_PACKET_LENGTH_LIMIT;
4368
4530
  exports.OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT = OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT;
4369
4531
  exports.OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT = OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT;
@@ -4378,6 +4540,8 @@ exports.OtherSpanEvent = OtherSpanEvent;
4378
4540
  exports.PRIMARY_VARIANT = PRIMARY_VARIANT;
4379
4541
  exports.PlatformToCoordinatorMessages = PlatformToCoordinatorMessages;
4380
4542
  exports.PlatformToProviderMessages = PlatformToProviderMessages;
4543
+ exports.PostStartCauses = PostStartCauses;
4544
+ exports.PreStopCauses = PreStopCauses;
4381
4545
  exports.ProdChildToWorkerMessages = ProdChildToWorkerMessages;
4382
4546
  exports.ProdRuntimeManager = ProdRuntimeManager;
4383
4547
  exports.ProdTaskRunExecution = ProdTaskRunExecution;
@@ -4443,16 +4607,16 @@ exports.ZodSocketMessageSender = ZodSocketMessageSender;
4443
4607
  exports.accessoryAttributes = accessoryAttributes;
4444
4608
  exports.apiClientManager = apiClientManager;
4445
4609
  exports.calculateNextRetryDelay = calculateNextRetryDelay;
4446
- exports.calculatePreciseDateHrTime = calculatePreciseDateHrTime;
4447
4610
  exports.calculateResetAt = calculateResetAt2;
4448
4611
  exports.childToWorkerMessages = childToWorkerMessages;
4449
4612
  exports.clientWebsocketMessages = clientWebsocketMessages;
4613
+ exports.clock = clock;
4450
4614
  exports.conditionallyExportPacket = conditionallyExportPacket;
4451
4615
  exports.conditionallyImportPacket = conditionallyImportPacket;
4452
4616
  exports.correctErrorStackTrace = correctErrorStackTrace;
4453
4617
  exports.createErrorTaskError = createErrorTaskError;
4454
- exports.createPackageAttributesAsJson = createPackageAttributesAsJson;
4455
4618
  exports.createPacketAttributes = createPacketAttributes;
4619
+ exports.createPacketAttributesAsJson = createPacketAttributesAsJson;
4456
4620
  exports.defaultFetchRetryOptions = defaultFetchRetryOptions;
4457
4621
  exports.defaultRetryOptions = defaultRetryOptions;
4458
4622
  exports.detectDependencyVersion = detectDependencyVersion;
@@ -4476,7 +4640,6 @@ exports.parseBatchTriggerTaskRequestBody = parseBatchTriggerTaskRequestBody;
4476
4640
  exports.parseError = parseError;
4477
4641
  exports.parsePacket = parsePacket;
4478
4642
  exports.parseTriggerTaskRequestBody = parseTriggerTaskRequestBody;
4479
- exports.preciseDateOriginNow = preciseDateOriginNow;
4480
4643
  exports.prettyPrintPacket = prettyPrintPacket;
4481
4644
  exports.primitiveValueOrflattenedAttributes = primitiveValueOrflattenedAttributes;
4482
4645
  exports.recordSpanException = recordSpanException;