@trigger.dev/core 0.0.0-v3-canary-20240325172431 → 0.0.0-v3-pnpm-fix-20240404110601
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.d.mts +816 -230
- package/dist/v3/index.d.ts +816 -230
- package/dist/v3/index.js +720 -133
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +692 -134
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/otel/index.js +37 -25
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +39 -27
- package/dist/v3/otel/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/v3/index.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
var api = require('@opentelemetry/api');
|
|
5
5
|
var async_hooks = require('async_hooks');
|
|
6
|
-
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
7
6
|
var socket_ioClient = require('socket.io-client');
|
|
8
7
|
var crypto = require('crypto');
|
|
9
8
|
var nodePath = require('path');
|
|
10
9
|
var apiLogs = require('@opentelemetry/api-logs');
|
|
11
10
|
var preciseDate = require('@google-cloud/precise-date');
|
|
12
11
|
var humanizeDuration = require('humanize-duration');
|
|
12
|
+
var promises = require('timers/promises');
|
|
13
13
|
var util = require('util');
|
|
14
14
|
var exporterLogsOtlpHttp = require('@opentelemetry/exporter-logs-otlp-http');
|
|
15
15
|
var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');
|
|
@@ -17,6 +17,7 @@ var instrumentation = require('@opentelemetry/instrumentation');
|
|
|
17
17
|
var resources = require('@opentelemetry/resources');
|
|
18
18
|
var sdkLogs = require('@opentelemetry/sdk-logs');
|
|
19
19
|
var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
|
|
20
|
+
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
20
21
|
|
|
21
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
23
|
|
|
@@ -224,6 +225,32 @@ var BatchTaskRunExecutionResult = zod.z.object({
|
|
|
224
225
|
});
|
|
225
226
|
|
|
226
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
|
+
});
|
|
227
254
|
var TaskRunExecutionPayload = zod.z.object({
|
|
228
255
|
execution: TaskRunExecution,
|
|
229
256
|
traceContext: zod.z.record(zod.z.unknown()),
|
|
@@ -253,11 +280,16 @@ var BackgroundWorkerServerMessages = zod.z.discriminatedUnion("type", [
|
|
|
253
280
|
}),
|
|
254
281
|
zod.z.object({
|
|
255
282
|
type: zod.z.literal("SCHEDULE_ATTEMPT"),
|
|
256
|
-
id: zod.z.string(),
|
|
257
283
|
image: zod.z.string(),
|
|
284
|
+
version: zod.z.string(),
|
|
285
|
+
machine: Machine,
|
|
286
|
+
// identifiers
|
|
287
|
+
id: zod.z.string(),
|
|
258
288
|
envId: zod.z.string(),
|
|
259
|
-
|
|
260
|
-
|
|
289
|
+
envType: EnvironmentType,
|
|
290
|
+
orgId: zod.z.string(),
|
|
291
|
+
projectId: zod.z.string(),
|
|
292
|
+
runId: zod.z.string()
|
|
261
293
|
})
|
|
262
294
|
]);
|
|
263
295
|
var serverWebsocketMessages = {
|
|
@@ -410,7 +442,7 @@ var QueueOptions = zod.z.object({
|
|
|
410
442
|
/** An optional property that specifies the maximum number of concurrent run executions.
|
|
411
443
|
*
|
|
412
444
|
* If this property is omitted, the task can potentially use up the full concurrency of an environment. */
|
|
413
|
-
concurrencyLimit: zod.z.number().int().min(
|
|
445
|
+
concurrencyLimit: zod.z.number().int().min(0).max(1e3).optional(),
|
|
414
446
|
/** @deprecated This feature is coming soon */
|
|
415
447
|
rateLimit: RateLimitOptions.optional()
|
|
416
448
|
});
|
|
@@ -419,7 +451,8 @@ var TaskMetadata = zod.z.object({
|
|
|
419
451
|
exportName: zod.z.string(),
|
|
420
452
|
packageVersion: zod.z.string(),
|
|
421
453
|
queue: QueueOptions.optional(),
|
|
422
|
-
retry: RetryOptions.optional()
|
|
454
|
+
retry: RetryOptions.optional(),
|
|
455
|
+
machine: Machine.partial().optional()
|
|
423
456
|
});
|
|
424
457
|
var TaskMetadataWithFilePath = TaskMetadata.extend({
|
|
425
458
|
filePath: zod.z.string()
|
|
@@ -436,6 +469,13 @@ var UncaughtExceptionMessage = zod.z.object({
|
|
|
436
469
|
"unhandledRejection"
|
|
437
470
|
])
|
|
438
471
|
});
|
|
472
|
+
var TaskMetadataFailedToParseData = zod.z.object({
|
|
473
|
+
version: zod.z.literal("v1").default("v1"),
|
|
474
|
+
tasks: zod.z.unknown(),
|
|
475
|
+
zodIssues: zod.z.custom((v) => {
|
|
476
|
+
return Array.isArray(v) && v.every((issue) => typeof issue === "object" && "message" in issue);
|
|
477
|
+
})
|
|
478
|
+
});
|
|
439
479
|
var childToWorkerMessages = {
|
|
440
480
|
TASK_RUN_COMPLETED: zod.z.object({
|
|
441
481
|
version: zod.z.literal("v1").default("v1"),
|
|
@@ -446,6 +486,7 @@ var childToWorkerMessages = {
|
|
|
446
486
|
version: zod.z.literal("v1").default("v1"),
|
|
447
487
|
tasks: TaskMetadataWithFilePath.array()
|
|
448
488
|
}),
|
|
489
|
+
TASKS_FAILED_TO_PARSE: TaskMetadataFailedToParseData,
|
|
449
490
|
TASK_HEARTBEAT: zod.z.object({
|
|
450
491
|
version: zod.z.literal("v1").default("v1"),
|
|
451
492
|
id: zod.z.string()
|
|
@@ -480,6 +521,9 @@ var ProdChildToWorkerMessages = {
|
|
|
480
521
|
tasks: TaskMetadataWithFilePath.array()
|
|
481
522
|
})
|
|
482
523
|
},
|
|
524
|
+
TASKS_FAILED_TO_PARSE: {
|
|
525
|
+
message: TaskMetadataFailedToParseData
|
|
526
|
+
},
|
|
483
527
|
TASK_HEARTBEAT: {
|
|
484
528
|
message: zod.z.object({
|
|
485
529
|
version: zod.z.literal("v1").default("v1"),
|
|
@@ -563,7 +607,8 @@ var TaskResource = zod.z.object({
|
|
|
563
607
|
filePath: zod.z.string(),
|
|
564
608
|
exportName: zod.z.string(),
|
|
565
609
|
queue: QueueOptions.optional(),
|
|
566
|
-
retry: RetryOptions.optional()
|
|
610
|
+
retry: RetryOptions.optional(),
|
|
611
|
+
machine: Machine.partial().optional()
|
|
567
612
|
});
|
|
568
613
|
var BackgroundWorkerMetadata = zod.z.object({
|
|
569
614
|
packageVersion: zod.z.string(),
|
|
@@ -674,6 +719,11 @@ var InitializeDeploymentRequestBody = zod.z.object({
|
|
|
674
719
|
contentHash: zod.z.string(),
|
|
675
720
|
userId: zod.z.string().optional()
|
|
676
721
|
});
|
|
722
|
+
var DeploymentErrorData = zod.z.object({
|
|
723
|
+
name: zod.z.string(),
|
|
724
|
+
message: zod.z.string(),
|
|
725
|
+
stack: zod.z.string().optional()
|
|
726
|
+
});
|
|
677
727
|
var GetDeploymentResponseBody = zod.z.object({
|
|
678
728
|
id: zod.z.string(),
|
|
679
729
|
status: zod.z.enum([
|
|
@@ -689,11 +739,7 @@ var GetDeploymentResponseBody = zod.z.object({
|
|
|
689
739
|
shortCode: zod.z.string(),
|
|
690
740
|
version: zod.z.string(),
|
|
691
741
|
imageReference: zod.z.string().optional(),
|
|
692
|
-
errorData:
|
|
693
|
-
name: zod.z.string(),
|
|
694
|
-
message: zod.z.string(),
|
|
695
|
-
stack: zod.z.string().optional()
|
|
696
|
-
}).optional().nullable(),
|
|
742
|
+
errorData: DeploymentErrorData.optional().nullable(),
|
|
697
743
|
worker: zod.z.object({
|
|
698
744
|
id: zod.z.string(),
|
|
699
745
|
version: zod.z.string(),
|
|
@@ -705,6 +751,17 @@ var GetDeploymentResponseBody = zod.z.object({
|
|
|
705
751
|
}))
|
|
706
752
|
}).optional()
|
|
707
753
|
});
|
|
754
|
+
var CreateUploadPayloadUrlResponseBody = zod.z.object({
|
|
755
|
+
presignedUrl: zod.z.string()
|
|
756
|
+
});
|
|
757
|
+
var PostStartCauses = zod.z.enum([
|
|
758
|
+
"index",
|
|
759
|
+
"create",
|
|
760
|
+
"restore"
|
|
761
|
+
]);
|
|
762
|
+
var PreStopCauses = zod.z.enum([
|
|
763
|
+
"terminate"
|
|
764
|
+
]);
|
|
708
765
|
var RegexSchema = zod.z.custom((val) => {
|
|
709
766
|
try {
|
|
710
767
|
return typeof val.test === "function";
|
|
@@ -727,11 +784,8 @@ var Config = zod.z.object({
|
|
|
727
784
|
dependenciesToBundle: zod.z.array(zod.z.union([
|
|
728
785
|
zod.z.string(),
|
|
729
786
|
RegexSchema
|
|
730
|
-
])).optional()
|
|
731
|
-
|
|
732
|
-
var Machine = zod.z.object({
|
|
733
|
-
cpu: zod.z.string().default("1").optional(),
|
|
734
|
-
memory: zod.z.string().default("500Mi").optional()
|
|
787
|
+
])).optional(),
|
|
788
|
+
logLevel: zod.z.string().optional()
|
|
735
789
|
});
|
|
736
790
|
var WaitReason = zod.z.enum([
|
|
737
791
|
"WAIT_FOR_DURATION",
|
|
@@ -769,9 +823,13 @@ var PlatformToProviderMessages = {
|
|
|
769
823
|
version: zod.z.literal("v1").default("v1"),
|
|
770
824
|
imageTag: zod.z.string(),
|
|
771
825
|
shortCode: zod.z.string(),
|
|
772
|
-
envId: zod.z.string(),
|
|
773
826
|
apiKey: zod.z.string(),
|
|
774
|
-
apiUrl: zod.z.string()
|
|
827
|
+
apiUrl: zod.z.string(),
|
|
828
|
+
// identifiers
|
|
829
|
+
envId: zod.z.string(),
|
|
830
|
+
envType: EnvironmentType,
|
|
831
|
+
orgId: zod.z.string(),
|
|
832
|
+
projectId: zod.z.string()
|
|
775
833
|
}),
|
|
776
834
|
callback: zod.z.discriminatedUnion("success", [
|
|
777
835
|
zod.z.object({
|
|
@@ -787,25 +845,25 @@ var PlatformToProviderMessages = {
|
|
|
787
845
|
})
|
|
788
846
|
])
|
|
789
847
|
},
|
|
790
|
-
|
|
791
|
-
message: zod.z.object({
|
|
792
|
-
version: zod.z.literal("v1").default("v1"),
|
|
793
|
-
name: zod.z.string(),
|
|
794
|
-
machine: Machine
|
|
795
|
-
})
|
|
796
|
-
},
|
|
848
|
+
// TODO: this should be a shared queue message instead
|
|
797
849
|
RESTORE: {
|
|
798
850
|
message: zod.z.object({
|
|
799
851
|
version: zod.z.literal("v1").default("v1"),
|
|
800
|
-
checkpointId: zod.z.string(),
|
|
801
|
-
runId: zod.z.string(),
|
|
802
852
|
type: zod.z.enum([
|
|
803
853
|
"DOCKER",
|
|
804
854
|
"KUBERNETES"
|
|
805
855
|
]),
|
|
806
856
|
location: zod.z.string(),
|
|
807
857
|
reason: zod.z.string().optional(),
|
|
808
|
-
imageRef: zod.z.string()
|
|
858
|
+
imageRef: zod.z.string(),
|
|
859
|
+
machine: Machine,
|
|
860
|
+
// identifiers
|
|
861
|
+
checkpointId: zod.z.string(),
|
|
862
|
+
envId: zod.z.string(),
|
|
863
|
+
envType: EnvironmentType,
|
|
864
|
+
orgId: zod.z.string(),
|
|
865
|
+
projectId: zod.z.string(),
|
|
866
|
+
runId: zod.z.string()
|
|
809
867
|
})
|
|
810
868
|
},
|
|
811
869
|
DELETE: {
|
|
@@ -1362,7 +1420,11 @@ var SpanMessagingEvent = zod.z.object({
|
|
|
1362
1420
|
});
|
|
1363
1421
|
|
|
1364
1422
|
// src/zodfetch.ts
|
|
1365
|
-
async function zodfetch(schema, url, requestInit) {
|
|
1423
|
+
async function zodfetch(schema, url, requestInit, options) {
|
|
1424
|
+
return await _doZodFetch(schema, url, requestInit, options);
|
|
1425
|
+
}
|
|
1426
|
+
__name(zodfetch, "zodfetch");
|
|
1427
|
+
async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
|
|
1366
1428
|
try {
|
|
1367
1429
|
const response = await fetch(url, requestInit);
|
|
1368
1430
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404) {
|
|
@@ -1371,7 +1433,7 @@ async function zodfetch(schema, url, requestInit) {
|
|
|
1371
1433
|
error: `404: ${response.statusText}`
|
|
1372
1434
|
};
|
|
1373
1435
|
}
|
|
1374
|
-
if (response.status >= 400 && response.status < 500) {
|
|
1436
|
+
if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
1375
1437
|
const body = await response.json();
|
|
1376
1438
|
if (!body.error) {
|
|
1377
1439
|
return {
|
|
@@ -1384,6 +1446,27 @@ async function zodfetch(schema, url, requestInit) {
|
|
|
1384
1446
|
error: body.error
|
|
1385
1447
|
};
|
|
1386
1448
|
}
|
|
1449
|
+
if (response.status === 429 || response.status >= 500) {
|
|
1450
|
+
if (!options?.retry) {
|
|
1451
|
+
return {
|
|
1452
|
+
ok: false,
|
|
1453
|
+
error: `Failed to fetch ${url}, got status code ${response.status}`
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
const retry = {
|
|
1457
|
+
...defaultRetryOptions,
|
|
1458
|
+
...options.retry
|
|
1459
|
+
};
|
|
1460
|
+
if (attempt > retry.maxAttempts) {
|
|
1461
|
+
return {
|
|
1462
|
+
ok: false,
|
|
1463
|
+
error: `Failed to fetch ${url}, got status code ${response.status}`
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
1467
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1468
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
1469
|
+
}
|
|
1387
1470
|
if (response.status !== 200) {
|
|
1388
1471
|
return {
|
|
1389
1472
|
ok: false,
|
|
@@ -1409,13 +1492,28 @@ async function zodfetch(schema, url, requestInit) {
|
|
|
1409
1492
|
error: parsedResult.error.message
|
|
1410
1493
|
};
|
|
1411
1494
|
} catch (error) {
|
|
1495
|
+
if (options?.retry) {
|
|
1496
|
+
const retry = {
|
|
1497
|
+
...defaultRetryOptions,
|
|
1498
|
+
...options.retry
|
|
1499
|
+
};
|
|
1500
|
+
if (attempt > retry.maxAttempts) {
|
|
1501
|
+
return {
|
|
1502
|
+
ok: false,
|
|
1503
|
+
error: error instanceof Error ? error.message : JSON.stringify(error)
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
1507
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1508
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
1509
|
+
}
|
|
1412
1510
|
return {
|
|
1413
1511
|
ok: false,
|
|
1414
1512
|
error: error instanceof Error ? error.message : JSON.stringify(error)
|
|
1415
1513
|
};
|
|
1416
1514
|
}
|
|
1417
1515
|
}
|
|
1418
|
-
__name(
|
|
1516
|
+
__name(_doZodFetch, "_doZodFetch");
|
|
1419
1517
|
|
|
1420
1518
|
// src/v3/utils/flattenAttributes.ts
|
|
1421
1519
|
function flattenAttributes(obj, prefix) {
|
|
@@ -1549,6 +1647,7 @@ var SemanticInternalAttributes = {
|
|
|
1549
1647
|
SPAN_PARTIAL: "$span.partial",
|
|
1550
1648
|
SPAN_ID: "$span.span_id",
|
|
1551
1649
|
OUTPUT: "$output",
|
|
1650
|
+
OUTPUT_TYPE: "$mime_type_output",
|
|
1552
1651
|
STYLE: "$style",
|
|
1553
1652
|
STYLE_ICON: "$style.icon",
|
|
1554
1653
|
STYLE_VARIANT: "$style.variant",
|
|
@@ -1556,6 +1655,7 @@ var SemanticInternalAttributes = {
|
|
|
1556
1655
|
METADATA: "$metadata",
|
|
1557
1656
|
TRIGGER: "$trigger",
|
|
1558
1657
|
PAYLOAD: "$payload",
|
|
1658
|
+
PAYLOAD_TYPE: "$mime_type_payload",
|
|
1559
1659
|
SHOW: "$show",
|
|
1560
1660
|
SHOW_ACTIONS: "$show.actions",
|
|
1561
1661
|
WORKER_ID: "worker.id",
|
|
@@ -1582,10 +1682,6 @@ var _TaskContextManager = class _TaskContextManager {
|
|
|
1582
1682
|
const store = __privateMethod(this, _getStore, getStore_fn).call(this);
|
|
1583
1683
|
return store?.ctx;
|
|
1584
1684
|
}
|
|
1585
|
-
get payload() {
|
|
1586
|
-
const store = __privateMethod(this, _getStore, getStore_fn).call(this);
|
|
1587
|
-
return store?.payload;
|
|
1588
|
-
}
|
|
1589
1685
|
get worker() {
|
|
1590
1686
|
const store = __privateMethod(this, _getStore, getStore_fn).call(this);
|
|
1591
1687
|
return store?.worker;
|
|
@@ -1594,19 +1690,11 @@ var _TaskContextManager = class _TaskContextManager {
|
|
|
1594
1690
|
if (this.ctx) {
|
|
1595
1691
|
return {
|
|
1596
1692
|
...this.contextAttributes,
|
|
1597
|
-
...this.workerAttributes
|
|
1598
|
-
...this.payloadAttributes,
|
|
1599
|
-
[semanticConventions.SemanticResourceAttributes.SERVICE_NAME]: this.ctx.task.id
|
|
1693
|
+
...this.workerAttributes
|
|
1600
1694
|
};
|
|
1601
1695
|
}
|
|
1602
1696
|
return {};
|
|
1603
1697
|
}
|
|
1604
|
-
get payloadAttributes() {
|
|
1605
|
-
if (this.payload) {
|
|
1606
|
-
return flattenAttributes(this.payload, "payload");
|
|
1607
|
-
}
|
|
1608
|
-
return {};
|
|
1609
|
-
}
|
|
1610
1698
|
get workerAttributes() {
|
|
1611
1699
|
if (this.worker) {
|
|
1612
1700
|
return {
|
|
@@ -1711,6 +1799,15 @@ function getEnvVar(name) {
|
|
|
1711
1799
|
__name(getEnvVar, "getEnvVar");
|
|
1712
1800
|
|
|
1713
1801
|
// src/v3/apiClient/index.ts
|
|
1802
|
+
var zodFetchOptions = {
|
|
1803
|
+
retry: {
|
|
1804
|
+
maxAttempts: 5,
|
|
1805
|
+
minTimeoutInMs: 1e3,
|
|
1806
|
+
maxTimeoutInMs: 3e4,
|
|
1807
|
+
factor: 2,
|
|
1808
|
+
randomize: false
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1714
1811
|
var _getHeaders, getHeaders_fn;
|
|
1715
1812
|
var _ApiClient = class _ApiClient {
|
|
1716
1813
|
constructor(baseUrl, accessToken) {
|
|
@@ -1723,14 +1820,26 @@ var _ApiClient = class _ApiClient {
|
|
|
1723
1820
|
method: "POST",
|
|
1724
1821
|
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
|
|
1725
1822
|
body: JSON.stringify(body)
|
|
1726
|
-
});
|
|
1823
|
+
}, zodFetchOptions);
|
|
1727
1824
|
}
|
|
1728
1825
|
batchTriggerTask(taskId, body, options) {
|
|
1729
1826
|
return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/batch`, {
|
|
1730
1827
|
method: "POST",
|
|
1731
1828
|
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
|
|
1732
1829
|
body: JSON.stringify(body)
|
|
1733
|
-
});
|
|
1830
|
+
}, zodFetchOptions);
|
|
1831
|
+
}
|
|
1832
|
+
createUploadPayloadUrl(filename) {
|
|
1833
|
+
return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
|
|
1834
|
+
method: "PUT",
|
|
1835
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1836
|
+
}, zodFetchOptions);
|
|
1837
|
+
}
|
|
1838
|
+
getPayloadUrl(filename) {
|
|
1839
|
+
return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
|
|
1840
|
+
method: "GET",
|
|
1841
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1842
|
+
}, zodFetchOptions);
|
|
1734
1843
|
}
|
|
1735
1844
|
};
|
|
1736
1845
|
_getHeaders = new WeakSet();
|
|
@@ -1757,7 +1866,7 @@ var _ApiClientManager = class _ApiClientManager {
|
|
|
1757
1866
|
}
|
|
1758
1867
|
get baseURL() {
|
|
1759
1868
|
const store = __privateMethod(this, _getStore2, getStore_fn2).call(this);
|
|
1760
|
-
return store?.baseURL ?? getEnvVar("TRIGGER_API_URL");
|
|
1869
|
+
return store?.baseURL ?? getEnvVar("TRIGGER_API_URL") ?? "https://api.trigger.dev";
|
|
1761
1870
|
}
|
|
1762
1871
|
get accessToken() {
|
|
1763
1872
|
const store = __privateMethod(this, _getStore2, getStore_fn2).call(this);
|
|
@@ -1780,6 +1889,15 @@ getStore_fn2 = /* @__PURE__ */ __name(function() {
|
|
|
1780
1889
|
__name(_ApiClientManager, "ApiClientManager");
|
|
1781
1890
|
var ApiClientManager = _ApiClientManager;
|
|
1782
1891
|
var apiClientManager = new ApiClientManager();
|
|
1892
|
+
var _ZodSchemaParsedError = class _ZodSchemaParsedError extends Error {
|
|
1893
|
+
constructor(error, payload) {
|
|
1894
|
+
super(error.message);
|
|
1895
|
+
this.error = error;
|
|
1896
|
+
this.payload = payload;
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
__name(_ZodSchemaParsedError, "ZodSchemaParsedError");
|
|
1900
|
+
var ZodSchemaParsedError = _ZodSchemaParsedError;
|
|
1783
1901
|
var ZodMessageSchema = zod.z.object({
|
|
1784
1902
|
version: zod.z.literal("v1").default("v1"),
|
|
1785
1903
|
type: zod.z.string(),
|
|
@@ -1876,7 +1994,7 @@ var _ZodMessageSender = class _ZodMessageSender {
|
|
|
1876
1994
|
}
|
|
1877
1995
|
const parsedPayload = schema.safeParse(payload);
|
|
1878
1996
|
if (!parsedPayload.success) {
|
|
1879
|
-
throw new
|
|
1997
|
+
throw new ZodSchemaParsedError(parsedPayload.error, payload);
|
|
1880
1998
|
}
|
|
1881
1999
|
await __privateGet(this, _sender).call(this, {
|
|
1882
2000
|
type,
|
|
@@ -2045,16 +2163,23 @@ var _ZodSocketConnection = class _ZodSocketConnection {
|
|
|
2045
2163
|
__privateAdd(this, _sender2, void 0);
|
|
2046
2164
|
__privateAdd(this, _handler, void 0);
|
|
2047
2165
|
__privateAdd(this, _logger, void 0);
|
|
2048
|
-
|
|
2166
|
+
const uri = `${opts.secure ? "wss" : "ws"}://${opts.host}:${opts.port ?? (opts.secure ? "443" : "80")}/${opts.namespace}`;
|
|
2167
|
+
const logger2 = new SimpleStructuredLogger(opts.namespace, exports.LogLevel.info);
|
|
2168
|
+
logger2.log("new zod socket", {
|
|
2169
|
+
uri
|
|
2170
|
+
});
|
|
2171
|
+
this.socket = socket_ioClient.io(uri, {
|
|
2049
2172
|
transports: [
|
|
2050
2173
|
"websocket"
|
|
2051
2174
|
],
|
|
2052
2175
|
auth: {
|
|
2053
2176
|
token: opts.authToken
|
|
2054
2177
|
},
|
|
2055
|
-
extraHeaders: opts.extraHeaders
|
|
2178
|
+
extraHeaders: opts.extraHeaders,
|
|
2179
|
+
reconnectionDelay: 500,
|
|
2180
|
+
reconnectionDelayMax: 1e3
|
|
2056
2181
|
});
|
|
2057
|
-
__privateSet(this, _logger,
|
|
2182
|
+
__privateSet(this, _logger, logger2.child({
|
|
2058
2183
|
socketId: this.socket.id
|
|
2059
2184
|
}));
|
|
2060
2185
|
__privateSet(this, _handler, new ZodSocketMessageHandler({
|
|
@@ -2373,7 +2498,7 @@ var _ZodIpcConnection = class _ZodIpcConnection {
|
|
|
2373
2498
|
}
|
|
2374
2499
|
const parsedPayload = schema.safeParse(payload);
|
|
2375
2500
|
if (!parsedPayload.success) {
|
|
2376
|
-
throw new
|
|
2501
|
+
throw new ZodSchemaParsedError(parsedPayload.error, payload);
|
|
2377
2502
|
}
|
|
2378
2503
|
await __privateMethod(this, _sendPacket, sendPacket_fn).call(this, {
|
|
2379
2504
|
type: "EVENT",
|
|
@@ -2562,6 +2687,41 @@ function correctStackTraceLine(line, projectDir) {
|
|
|
2562
2687
|
return line;
|
|
2563
2688
|
}
|
|
2564
2689
|
__name(correctStackTraceLine, "correctStackTraceLine");
|
|
2690
|
+
function groupTaskMetadataIssuesByTask(tasks, issues) {
|
|
2691
|
+
return issues.reduce((acc, issue) => {
|
|
2692
|
+
if (issue.path.length === 0) {
|
|
2693
|
+
return acc;
|
|
2694
|
+
}
|
|
2695
|
+
const taskIndex = issue.path[1];
|
|
2696
|
+
if (typeof taskIndex !== "number") {
|
|
2697
|
+
return acc;
|
|
2698
|
+
}
|
|
2699
|
+
const task = tasks[taskIndex];
|
|
2700
|
+
if (!task) {
|
|
2701
|
+
return acc;
|
|
2702
|
+
}
|
|
2703
|
+
const restOfPath = issue.path.slice(2);
|
|
2704
|
+
const taskId = task.id;
|
|
2705
|
+
const taskName = task.exportName;
|
|
2706
|
+
const filePath = task.filePath;
|
|
2707
|
+
const key = taskIndex;
|
|
2708
|
+
const existing = acc[key] ?? {
|
|
2709
|
+
id: taskId,
|
|
2710
|
+
exportName: taskName,
|
|
2711
|
+
filePath,
|
|
2712
|
+
issues: []
|
|
2713
|
+
};
|
|
2714
|
+
existing.issues.push({
|
|
2715
|
+
message: issue.message,
|
|
2716
|
+
path: restOfPath.length === 0 ? void 0 : restOfPath.join(".")
|
|
2717
|
+
});
|
|
2718
|
+
return {
|
|
2719
|
+
...acc,
|
|
2720
|
+
[key]: existing
|
|
2721
|
+
};
|
|
2722
|
+
}, {});
|
|
2723
|
+
}
|
|
2724
|
+
__name(groupTaskMetadataIssuesByTask, "groupTaskMetadataIssuesByTask");
|
|
2565
2725
|
|
|
2566
2726
|
// src/v3/utils/platform.ts
|
|
2567
2727
|
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
@@ -2711,27 +2871,58 @@ function iconStringForSeverity(severityNumber) {
|
|
|
2711
2871
|
}
|
|
2712
2872
|
}
|
|
2713
2873
|
__name(iconStringForSeverity, "iconStringForSeverity");
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2874
|
+
var _SimpleClock = class _SimpleClock {
|
|
2875
|
+
preciseNow() {
|
|
2876
|
+
const now = new preciseDate.PreciseDate();
|
|
2877
|
+
const nowStruct = now.toStruct();
|
|
2878
|
+
return [
|
|
2879
|
+
nowStruct.seconds,
|
|
2880
|
+
nowStruct.nanos
|
|
2881
|
+
];
|
|
2882
|
+
}
|
|
2883
|
+
reset() {
|
|
2884
|
+
}
|
|
2885
|
+
};
|
|
2886
|
+
__name(_SimpleClock, "SimpleClock");
|
|
2887
|
+
var SimpleClock = _SimpleClock;
|
|
2888
|
+
|
|
2889
|
+
// src/v3/clock/index.ts
|
|
2890
|
+
var API_NAME2 = "clock";
|
|
2891
|
+
var SIMPLE_CLOCK = new SimpleClock();
|
|
2892
|
+
var _getClock, getClock_fn;
|
|
2893
|
+
var _ClockAPI = class _ClockAPI {
|
|
2894
|
+
constructor() {
|
|
2895
|
+
__privateAdd(this, _getClock);
|
|
2896
|
+
}
|
|
2897
|
+
static getInstance() {
|
|
2898
|
+
if (!this._instance) {
|
|
2899
|
+
this._instance = new _ClockAPI();
|
|
2900
|
+
}
|
|
2901
|
+
return this._instance;
|
|
2902
|
+
}
|
|
2903
|
+
setGlobalClock(clock2) {
|
|
2904
|
+
return registerGlobal(API_NAME2, clock2);
|
|
2905
|
+
}
|
|
2906
|
+
preciseNow() {
|
|
2907
|
+
return __privateMethod(this, _getClock, getClock_fn).call(this).preciseNow();
|
|
2908
|
+
}
|
|
2909
|
+
reset() {
|
|
2910
|
+
__privateMethod(this, _getClock, getClock_fn).call(this).reset();
|
|
2911
|
+
}
|
|
2912
|
+
};
|
|
2913
|
+
_getClock = new WeakSet();
|
|
2914
|
+
getClock_fn = /* @__PURE__ */ __name(function() {
|
|
2915
|
+
return getGlobal(API_NAME2) ?? SIMPLE_CLOCK;
|
|
2916
|
+
}, "#getClock");
|
|
2917
|
+
__name(_ClockAPI, "ClockAPI");
|
|
2918
|
+
var ClockAPI = _ClockAPI;
|
|
2919
|
+
|
|
2920
|
+
// src/v3/clock-api.ts
|
|
2921
|
+
var clock = ClockAPI.getInstance();
|
|
2732
2922
|
|
|
2733
2923
|
// src/v3/logger/taskLogger.ts
|
|
2734
2924
|
var logLevels = [
|
|
2925
|
+
"none",
|
|
2735
2926
|
"error",
|
|
2736
2927
|
"warn",
|
|
2737
2928
|
"log",
|
|
@@ -2747,37 +2938,36 @@ var _OtelTaskLogger = class _OtelTaskLogger {
|
|
|
2747
2938
|
this._level = logLevels.indexOf(_config.level);
|
|
2748
2939
|
}
|
|
2749
2940
|
debug(message, properties) {
|
|
2750
|
-
if (this._level <
|
|
2941
|
+
if (this._level < 5)
|
|
2751
2942
|
return;
|
|
2752
|
-
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, "debug", apiLogs.SeverityNumber.DEBUG, properties);
|
|
2943
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "debug", apiLogs.SeverityNumber.DEBUG, properties);
|
|
2753
2944
|
}
|
|
2754
2945
|
log(message, properties) {
|
|
2755
|
-
if (this._level <
|
|
2946
|
+
if (this._level < 3)
|
|
2756
2947
|
return;
|
|
2757
|
-
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, "log", apiLogs.SeverityNumber.INFO, properties);
|
|
2948
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "log", apiLogs.SeverityNumber.INFO, properties);
|
|
2758
2949
|
}
|
|
2759
2950
|
info(message, properties) {
|
|
2760
|
-
if (this._level <
|
|
2951
|
+
if (this._level < 4)
|
|
2761
2952
|
return;
|
|
2762
|
-
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, "info", apiLogs.SeverityNumber.INFO, properties);
|
|
2953
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "info", apiLogs.SeverityNumber.INFO, properties);
|
|
2763
2954
|
}
|
|
2764
2955
|
warn(message, properties) {
|
|
2765
|
-
if (this._level <
|
|
2956
|
+
if (this._level < 2)
|
|
2766
2957
|
return;
|
|
2767
|
-
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, "warn", apiLogs.SeverityNumber.WARN, properties);
|
|
2958
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "warn", apiLogs.SeverityNumber.WARN, properties);
|
|
2768
2959
|
}
|
|
2769
2960
|
error(message, properties) {
|
|
2770
|
-
if (this._level <
|
|
2961
|
+
if (this._level < 1)
|
|
2771
2962
|
return;
|
|
2772
|
-
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, "error", apiLogs.SeverityNumber.ERROR, properties);
|
|
2963
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "error", apiLogs.SeverityNumber.ERROR, properties);
|
|
2773
2964
|
}
|
|
2774
2965
|
trace(name, fn, options) {
|
|
2775
2966
|
return this._config.tracer.startActiveSpan(name, fn, options);
|
|
2776
2967
|
}
|
|
2777
2968
|
};
|
|
2778
2969
|
_emitLog = new WeakSet();
|
|
2779
|
-
emitLog_fn = /* @__PURE__ */ __name(function(message, severityText, severityNumber, properties) {
|
|
2780
|
-
const timestamp = __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this);
|
|
2970
|
+
emitLog_fn = /* @__PURE__ */ __name(function(message, timestamp, severityText, severityNumber, properties) {
|
|
2781
2971
|
let attributes = {
|
|
2782
2972
|
...flattenAttributes(properties)
|
|
2783
2973
|
};
|
|
@@ -2795,7 +2985,7 @@ emitLog_fn = /* @__PURE__ */ __name(function(message, severityText, severityNumb
|
|
|
2795
2985
|
}, "#emitLog");
|
|
2796
2986
|
_getTimestampInHrTime = new WeakSet();
|
|
2797
2987
|
getTimestampInHrTime_fn = /* @__PURE__ */ __name(function() {
|
|
2798
|
-
return
|
|
2988
|
+
return clock.preciseNow();
|
|
2799
2989
|
}, "#getTimestampInHrTime");
|
|
2800
2990
|
__name(_OtelTaskLogger, "OtelTaskLogger");
|
|
2801
2991
|
var OtelTaskLogger = _OtelTaskLogger;
|
|
@@ -2818,7 +3008,7 @@ __name(_NoopTaskLogger, "NoopTaskLogger");
|
|
|
2818
3008
|
var NoopTaskLogger = _NoopTaskLogger;
|
|
2819
3009
|
|
|
2820
3010
|
// src/v3/logger/index.ts
|
|
2821
|
-
var
|
|
3011
|
+
var API_NAME3 = "logger";
|
|
2822
3012
|
var NOOP_TASK_LOGGER = new NoopTaskLogger();
|
|
2823
3013
|
var _getTaskLogger, getTaskLogger_fn;
|
|
2824
3014
|
var _LoggerAPI = class _LoggerAPI {
|
|
@@ -2832,10 +3022,10 @@ var _LoggerAPI = class _LoggerAPI {
|
|
|
2832
3022
|
return this._instance;
|
|
2833
3023
|
}
|
|
2834
3024
|
disable() {
|
|
2835
|
-
unregisterGlobal(
|
|
3025
|
+
unregisterGlobal(API_NAME3);
|
|
2836
3026
|
}
|
|
2837
3027
|
setGlobalTaskLogger(taskLogger) {
|
|
2838
|
-
return registerGlobal(
|
|
3028
|
+
return registerGlobal(API_NAME3, taskLogger);
|
|
2839
3029
|
}
|
|
2840
3030
|
debug(message, metadata) {
|
|
2841
3031
|
__privateMethod(this, _getTaskLogger, getTaskLogger_fn).call(this).debug(message, metadata);
|
|
@@ -2858,13 +3048,57 @@ var _LoggerAPI = class _LoggerAPI {
|
|
|
2858
3048
|
};
|
|
2859
3049
|
_getTaskLogger = new WeakSet();
|
|
2860
3050
|
getTaskLogger_fn = /* @__PURE__ */ __name(function() {
|
|
2861
|
-
return getGlobal(
|
|
3051
|
+
return getGlobal(API_NAME3) ?? NOOP_TASK_LOGGER;
|
|
2862
3052
|
}, "#getTaskLogger");
|
|
2863
3053
|
__name(_LoggerAPI, "LoggerAPI");
|
|
2864
3054
|
var LoggerAPI = _LoggerAPI;
|
|
2865
3055
|
|
|
2866
3056
|
// src/v3/logger-api.ts
|
|
2867
3057
|
var logger = LoggerAPI.getInstance();
|
|
3058
|
+
|
|
3059
|
+
// src/v3/limits.ts
|
|
3060
|
+
var OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = 256;
|
|
3061
|
+
var OTEL_LOG_ATTRIBUTE_COUNT_LIMIT = 256;
|
|
3062
|
+
var OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = 1028;
|
|
3063
|
+
var OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT = 1028;
|
|
3064
|
+
var OTEL_SPAN_EVENT_COUNT_LIMIT = 10;
|
|
3065
|
+
var OTEL_LINK_COUNT_LIMIT = 2;
|
|
3066
|
+
var OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT = 10;
|
|
3067
|
+
var OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT = 10;
|
|
3068
|
+
var OFFLOAD_IO_PACKET_LENGTH_LIMIT = 128 * 1024;
|
|
3069
|
+
function imposeAttributeLimits(attributes) {
|
|
3070
|
+
const newAttributes = {};
|
|
3071
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
3072
|
+
if (calculateAttributeValueLength(value) > OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT) {
|
|
3073
|
+
continue;
|
|
3074
|
+
}
|
|
3075
|
+
if (Object.keys(newAttributes).length >= OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT) {
|
|
3076
|
+
break;
|
|
3077
|
+
}
|
|
3078
|
+
newAttributes[key] = value;
|
|
3079
|
+
}
|
|
3080
|
+
return newAttributes;
|
|
3081
|
+
}
|
|
3082
|
+
__name(imposeAttributeLimits, "imposeAttributeLimits");
|
|
3083
|
+
function calculateAttributeValueLength(value) {
|
|
3084
|
+
if (value === void 0 || value === null) {
|
|
3085
|
+
return 0;
|
|
3086
|
+
}
|
|
3087
|
+
if (typeof value === "string") {
|
|
3088
|
+
return value.length;
|
|
3089
|
+
}
|
|
3090
|
+
if (typeof value === "number") {
|
|
3091
|
+
return 8;
|
|
3092
|
+
}
|
|
3093
|
+
if (typeof value === "boolean") {
|
|
3094
|
+
return 4;
|
|
3095
|
+
}
|
|
3096
|
+
if (Array.isArray(value)) {
|
|
3097
|
+
return value.reduce((acc, v) => acc + calculateAttributeValueLength(v), 0);
|
|
3098
|
+
}
|
|
3099
|
+
return 0;
|
|
3100
|
+
}
|
|
3101
|
+
__name(calculateAttributeValueLength, "calculateAttributeValueLength");
|
|
2868
3102
|
function dateDifference(date1, date2) {
|
|
2869
3103
|
return Math.abs(date1.getTime() - date2.getTime());
|
|
2870
3104
|
}
|
|
@@ -3029,11 +3263,10 @@ var _DevRuntimeManager = class _DevRuntimeManager {
|
|
|
3029
3263
|
};
|
|
3030
3264
|
__name(_DevRuntimeManager, "DevRuntimeManager");
|
|
3031
3265
|
var DevRuntimeManager = _DevRuntimeManager;
|
|
3032
|
-
|
|
3033
|
-
// src/v3/runtime/prodRuntimeManager.ts
|
|
3034
3266
|
var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
3035
|
-
constructor(ipc) {
|
|
3267
|
+
constructor(ipc, options = {}) {
|
|
3036
3268
|
this.ipc = ipc;
|
|
3269
|
+
this.options = options;
|
|
3037
3270
|
this._taskWaits = /* @__PURE__ */ new Map();
|
|
3038
3271
|
this._batchWaits = /* @__PURE__ */ new Map();
|
|
3039
3272
|
this._tasks = /* @__PURE__ */ new Map();
|
|
@@ -3049,12 +3282,9 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3049
3282
|
return this._tasks.get(id);
|
|
3050
3283
|
}
|
|
3051
3284
|
async waitForDuration(ms) {
|
|
3052
|
-
let timeout;
|
|
3053
3285
|
const now = Date.now();
|
|
3054
|
-
const resolveAfterDuration =
|
|
3055
|
-
|
|
3056
|
-
});
|
|
3057
|
-
if (ms < 1e4) {
|
|
3286
|
+
const resolveAfterDuration = promises.setTimeout(ms, "duration");
|
|
3287
|
+
if (ms <= this.waitThresholdInMs) {
|
|
3058
3288
|
await resolveAfterDuration;
|
|
3059
3289
|
return;
|
|
3060
3290
|
}
|
|
@@ -3078,13 +3308,13 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3078
3308
|
resolveAfterDuration
|
|
3079
3309
|
]);
|
|
3080
3310
|
this.ipc.send("CANCEL_CHECKPOINT", {});
|
|
3081
|
-
clearTimeout(timeout);
|
|
3082
3311
|
}
|
|
3083
3312
|
resumeAfterRestore() {
|
|
3084
3313
|
if (!this._waitForRestore) {
|
|
3085
3314
|
return;
|
|
3086
3315
|
}
|
|
3087
|
-
|
|
3316
|
+
clock.reset();
|
|
3317
|
+
this._waitForRestore.resolve("restore");
|
|
3088
3318
|
this._waitForRestore = void 0;
|
|
3089
3319
|
}
|
|
3090
3320
|
async waitUntil(date) {
|
|
@@ -3139,9 +3369,49 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3139
3369
|
}
|
|
3140
3370
|
this._taskWaits.delete(execution.run.id);
|
|
3141
3371
|
}
|
|
3372
|
+
get waitThresholdInMs() {
|
|
3373
|
+
return this.options.waitThresholdInMs ?? 3e4;
|
|
3374
|
+
}
|
|
3142
3375
|
};
|
|
3143
3376
|
__name(_ProdRuntimeManager, "ProdRuntimeManager");
|
|
3144
3377
|
var ProdRuntimeManager = _ProdRuntimeManager;
|
|
3378
|
+
var _originClockTime, originClockTime_get, _originPreciseDate, originPreciseDate_get;
|
|
3379
|
+
var _PreciseWallClock = class _PreciseWallClock {
|
|
3380
|
+
constructor(options = {}) {
|
|
3381
|
+
__privateAdd(this, _originClockTime);
|
|
3382
|
+
__privateAdd(this, _originPreciseDate);
|
|
3383
|
+
this._origin = {
|
|
3384
|
+
clockTime: options.origin ?? process.hrtime(),
|
|
3385
|
+
preciseDate: options.now ?? new preciseDate.PreciseDate()
|
|
3386
|
+
};
|
|
3387
|
+
}
|
|
3388
|
+
preciseNow() {
|
|
3389
|
+
const elapsedHrTime = process.hrtime(__privateGet(this, _originClockTime, originClockTime_get));
|
|
3390
|
+
const elapsedNanoseconds = BigInt(elapsedHrTime[0]) * BigInt(1e9) + BigInt(elapsedHrTime[1]);
|
|
3391
|
+
const preciseDate$1 = new preciseDate.PreciseDate(__privateGet(this, _originPreciseDate, originPreciseDate_get).getFullTime() + elapsedNanoseconds);
|
|
3392
|
+
const dateStruct = preciseDate$1.toStruct();
|
|
3393
|
+
return [
|
|
3394
|
+
dateStruct.seconds,
|
|
3395
|
+
dateStruct.nanos
|
|
3396
|
+
];
|
|
3397
|
+
}
|
|
3398
|
+
reset() {
|
|
3399
|
+
this._origin = {
|
|
3400
|
+
clockTime: process.hrtime(),
|
|
3401
|
+
preciseDate: new preciseDate.PreciseDate()
|
|
3402
|
+
};
|
|
3403
|
+
}
|
|
3404
|
+
};
|
|
3405
|
+
_originClockTime = new WeakSet();
|
|
3406
|
+
originClockTime_get = /* @__PURE__ */ __name(function() {
|
|
3407
|
+
return this._origin.clockTime;
|
|
3408
|
+
}, "#originClockTime");
|
|
3409
|
+
_originPreciseDate = new WeakSet();
|
|
3410
|
+
originPreciseDate_get = /* @__PURE__ */ __name(function() {
|
|
3411
|
+
return this._origin.preciseDate;
|
|
3412
|
+
}, "#originPreciseDate");
|
|
3413
|
+
__name(_PreciseWallClock, "PreciseWallClock");
|
|
3414
|
+
var PreciseWallClock = _PreciseWallClock;
|
|
3145
3415
|
var _TriggerTracer = class _TriggerTracer {
|
|
3146
3416
|
constructor(_config) {
|
|
3147
3417
|
this._config = _config;
|
|
@@ -3170,7 +3440,8 @@ var _TriggerTracer = class _TriggerTracer {
|
|
|
3170
3440
|
const attributes = options?.attributes ?? {};
|
|
3171
3441
|
return this.tracer.startActiveSpan(name, {
|
|
3172
3442
|
...options,
|
|
3173
|
-
attributes
|
|
3443
|
+
attributes,
|
|
3444
|
+
startTime: clock.preciseNow()
|
|
3174
3445
|
}, parentContext, async (span) => {
|
|
3175
3446
|
this.tracer.startSpan(name, {
|
|
3176
3447
|
...options,
|
|
@@ -3191,7 +3462,7 @@ var _TriggerTracer = class _TriggerTracer {
|
|
|
3191
3462
|
});
|
|
3192
3463
|
throw e;
|
|
3193
3464
|
} finally {
|
|
3194
|
-
span.end();
|
|
3465
|
+
span.end(clock.preciseNow());
|
|
3195
3466
|
}
|
|
3196
3467
|
});
|
|
3197
3468
|
}
|
|
@@ -3214,12 +3485,11 @@ __name(_TriggerTracer, "TriggerTracer");
|
|
|
3214
3485
|
var TriggerTracer = _TriggerTracer;
|
|
3215
3486
|
var _handleLog, handleLog_fn, _getTimestampInHrTime2, getTimestampInHrTime_fn2, _getAttributes, getAttributes_fn;
|
|
3216
3487
|
var _ConsoleInterceptor = class _ConsoleInterceptor {
|
|
3217
|
-
constructor(logger2
|
|
3488
|
+
constructor(logger2) {
|
|
3218
3489
|
__privateAdd(this, _handleLog);
|
|
3219
3490
|
__privateAdd(this, _getTimestampInHrTime2);
|
|
3220
3491
|
__privateAdd(this, _getAttributes);
|
|
3221
3492
|
this.logger = logger2;
|
|
3222
|
-
this.preciseDateOrigin = preciseDateOrigin;
|
|
3223
3493
|
}
|
|
3224
3494
|
// Intercept the console and send logs to the OpenTelemetry logger
|
|
3225
3495
|
// during the execution of the callback
|
|
@@ -3244,22 +3514,21 @@ var _ConsoleInterceptor = class _ConsoleInterceptor {
|
|
|
3244
3514
|
}
|
|
3245
3515
|
}
|
|
3246
3516
|
log(...args) {
|
|
3247
|
-
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, "Log", ...args);
|
|
3517
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Log", ...args);
|
|
3248
3518
|
}
|
|
3249
3519
|
info(...args) {
|
|
3250
|
-
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, "Info", ...args);
|
|
3520
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.INFO, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Info", ...args);
|
|
3251
3521
|
}
|
|
3252
3522
|
warn(...args) {
|
|
3253
|
-
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.WARN, "Warn", ...args);
|
|
3523
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.WARN, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Warn", ...args);
|
|
3254
3524
|
}
|
|
3255
3525
|
error(...args) {
|
|
3256
|
-
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.ERROR, "Error", ...args);
|
|
3526
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, apiLogs.SeverityNumber.ERROR, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Error", ...args);
|
|
3257
3527
|
}
|
|
3258
3528
|
};
|
|
3259
3529
|
_handleLog = new WeakSet();
|
|
3260
|
-
handleLog_fn = /* @__PURE__ */ __name(function(severityNumber, severityText, ...args) {
|
|
3530
|
+
handleLog_fn = /* @__PURE__ */ __name(function(severityNumber, timestamp, severityText, ...args) {
|
|
3261
3531
|
const body = util__default.default.format(...args);
|
|
3262
|
-
const timestamp = __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this);
|
|
3263
3532
|
const parsed = tryParseJSON(body);
|
|
3264
3533
|
if (parsed.ok) {
|
|
3265
3534
|
this.logger.emit({
|
|
@@ -3284,7 +3553,7 @@ handleLog_fn = /* @__PURE__ */ __name(function(severityNumber, severityText, ...
|
|
|
3284
3553
|
}, "#handleLog");
|
|
3285
3554
|
_getTimestampInHrTime2 = new WeakSet();
|
|
3286
3555
|
getTimestampInHrTime_fn2 = /* @__PURE__ */ __name(function() {
|
|
3287
|
-
return
|
|
3556
|
+
return clock.preciseNow();
|
|
3288
3557
|
}, "#getTimestampInHrTime");
|
|
3289
3558
|
_getAttributes = new WeakSet();
|
|
3290
3559
|
getAttributes_fn = /* @__PURE__ */ __name(function(severityNumber1) {
|
|
@@ -3658,19 +3927,24 @@ var _TracingSDK = class _TracingSDK {
|
|
|
3658
3927
|
forceFlushTimeoutMillis: config.forceFlushTimeoutMillis ?? 500,
|
|
3659
3928
|
resource: commonResources,
|
|
3660
3929
|
spanLimits: {
|
|
3661
|
-
attributeCountLimit:
|
|
3662
|
-
attributeValueLengthLimit:
|
|
3663
|
-
eventCountLimit:
|
|
3664
|
-
attributePerEventCountLimit:
|
|
3665
|
-
linkCountLimit:
|
|
3666
|
-
attributePerLinkCountLimit:
|
|
3930
|
+
attributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
|
|
3931
|
+
attributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT,
|
|
3932
|
+
eventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT,
|
|
3933
|
+
attributePerEventCountLimit: OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT,
|
|
3934
|
+
linkCountLimit: OTEL_LINK_COUNT_LIMIT,
|
|
3935
|
+
attributePerLinkCountLimit: OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT
|
|
3667
3936
|
}
|
|
3668
3937
|
});
|
|
3669
3938
|
const spanExporter = new exporterTraceOtlpHttp.OTLPTraceExporter({
|
|
3670
3939
|
url: `${config.url}/v1/traces`,
|
|
3671
3940
|
timeoutMillis: config.forceFlushTimeoutMillis ?? 1e3
|
|
3672
3941
|
});
|
|
3673
|
-
traceProvider.addSpanProcessor(new TaskContextSpanProcessor(new sdkTraceNode.
|
|
3942
|
+
traceProvider.addSpanProcessor(new TaskContextSpanProcessor(getEnvVar("OTEL_BATCH_PROCESSING_ENABLED") === "1" ? new sdkTraceNode.BatchSpanProcessor(spanExporter, {
|
|
3943
|
+
maxExportBatchSize: parseInt(getEnvVar("OTEL_SPAN_MAX_EXPORT_BATCH_SIZE") ?? "64"),
|
|
3944
|
+
scheduledDelayMillis: parseInt(getEnvVar("OTEL_SPAN_SCHEDULED_DELAY_MILLIS") ?? "200"),
|
|
3945
|
+
exportTimeoutMillis: parseInt(getEnvVar("OTEL_SPAN_EXPORT_TIMEOUT_MILLIS") ?? "30000"),
|
|
3946
|
+
maxQueueSize: parseInt(getEnvVar("OTEL_SPAN_MAX_QUEUE_SIZE") ?? "512")
|
|
3947
|
+
}) : new sdkTraceNode.SimpleSpanProcessor(spanExporter)));
|
|
3674
3948
|
traceProvider.register();
|
|
3675
3949
|
instrumentation.registerInstrumentations({
|
|
3676
3950
|
instrumentations: config.instrumentations ?? [],
|
|
@@ -3682,11 +3956,16 @@ var _TracingSDK = class _TracingSDK {
|
|
|
3682
3956
|
const loggerProvider = new sdkLogs.LoggerProvider({
|
|
3683
3957
|
resource: commonResources,
|
|
3684
3958
|
logRecordLimits: {
|
|
3685
|
-
attributeCountLimit:
|
|
3686
|
-
attributeValueLengthLimit:
|
|
3959
|
+
attributeCountLimit: OTEL_LOG_ATTRIBUTE_COUNT_LIMIT,
|
|
3960
|
+
attributeValueLengthLimit: OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT
|
|
3687
3961
|
}
|
|
3688
3962
|
});
|
|
3689
|
-
loggerProvider.addLogRecordProcessor(new TaskContextLogProcessor(new sdkLogs.
|
|
3963
|
+
loggerProvider.addLogRecordProcessor(new TaskContextLogProcessor(getEnvVar("OTEL_BATCH_PROCESSING_ENABLED") === "1" ? new sdkLogs.BatchLogRecordProcessor(logExporter, {
|
|
3964
|
+
maxExportBatchSize: parseInt(getEnvVar("OTEL_LOG_MAX_EXPORT_BATCH_SIZE") ?? "64"),
|
|
3965
|
+
scheduledDelayMillis: parseInt(getEnvVar("OTEL_LOG_SCHEDULED_DELAY_MILLIS") ?? "200"),
|
|
3966
|
+
exportTimeoutMillis: parseInt(getEnvVar("OTEL_LOG_EXPORT_TIMEOUT_MILLIS") ?? "30000"),
|
|
3967
|
+
maxQueueSize: parseInt(getEnvVar("OTEL_LOG_MAX_QUEUE_SIZE") ?? "512")
|
|
3968
|
+
}) : new sdkLogs.SimpleLogRecordProcessor(logExporter)));
|
|
3690
3969
|
this._logProvider = loggerProvider;
|
|
3691
3970
|
this._spanExporter = spanExporter;
|
|
3692
3971
|
this._traceProvider = traceProvider;
|
|
@@ -3695,11 +3974,11 @@ var _TracingSDK = class _TracingSDK {
|
|
|
3695
3974
|
this.getTracer = traceProvider.getTracer.bind(traceProvider);
|
|
3696
3975
|
}
|
|
3697
3976
|
async flush() {
|
|
3698
|
-
await this.
|
|
3977
|
+
await this._traceProvider.forceFlush();
|
|
3699
3978
|
await this._logProvider.forceFlush();
|
|
3700
3979
|
}
|
|
3701
3980
|
async shutdown() {
|
|
3702
|
-
await this.
|
|
3981
|
+
await this._traceProvider.shutdown();
|
|
3703
3982
|
await this._logProvider.shutdown();
|
|
3704
3983
|
}
|
|
3705
3984
|
};
|
|
@@ -3750,6 +4029,275 @@ function recordSpanException(span, error) {
|
|
|
3750
4029
|
});
|
|
3751
4030
|
}
|
|
3752
4031
|
__name(recordSpanException, "recordSpanException");
|
|
4032
|
+
|
|
4033
|
+
// src/v3/utils/ioSerialization.ts
|
|
4034
|
+
async function parsePacket(value) {
|
|
4035
|
+
if (!value.data) {
|
|
4036
|
+
return void 0;
|
|
4037
|
+
}
|
|
4038
|
+
switch (value.dataType) {
|
|
4039
|
+
case "application/json":
|
|
4040
|
+
return JSON.parse(value.data);
|
|
4041
|
+
case "application/super+json":
|
|
4042
|
+
const { parse } = await loadSuperJSON();
|
|
4043
|
+
return parse(value.data);
|
|
4044
|
+
case "text/plain":
|
|
4045
|
+
return value.data;
|
|
4046
|
+
case "application/store":
|
|
4047
|
+
throw new Error(`Cannot parse an application/store packet (${value.data}). Needs to be imported first.`);
|
|
4048
|
+
default:
|
|
4049
|
+
return value.data;
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
__name(parsePacket, "parsePacket");
|
|
4053
|
+
async function stringifyIO(value) {
|
|
4054
|
+
if (value === void 0) {
|
|
4055
|
+
return {
|
|
4056
|
+
dataType: "application/json"
|
|
4057
|
+
};
|
|
4058
|
+
}
|
|
4059
|
+
if (typeof value === "string") {
|
|
4060
|
+
return {
|
|
4061
|
+
data: value,
|
|
4062
|
+
dataType: "text/plain"
|
|
4063
|
+
};
|
|
4064
|
+
}
|
|
4065
|
+
try {
|
|
4066
|
+
const { stringify } = await loadSuperJSON();
|
|
4067
|
+
const data = stringify(value);
|
|
4068
|
+
return {
|
|
4069
|
+
data,
|
|
4070
|
+
dataType: "application/super+json"
|
|
4071
|
+
};
|
|
4072
|
+
} catch {
|
|
4073
|
+
return {
|
|
4074
|
+
dataType: "application/json"
|
|
4075
|
+
};
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
__name(stringifyIO, "stringifyIO");
|
|
4079
|
+
async function conditionallyExportPacket(packet, pathPrefix, tracer) {
|
|
4080
|
+
if (apiClientManager.client) {
|
|
4081
|
+
const { needsOffloading, size } = packetRequiresOffloading(packet);
|
|
4082
|
+
if (needsOffloading) {
|
|
4083
|
+
if (!tracer) {
|
|
4084
|
+
return await exportPacket(packet, pathPrefix);
|
|
4085
|
+
} else {
|
|
4086
|
+
const result = await tracer.startActiveSpan("store.uploadOutput", async (span) => {
|
|
4087
|
+
return await exportPacket(packet, pathPrefix);
|
|
4088
|
+
}, {
|
|
4089
|
+
attributes: {
|
|
4090
|
+
byteLength: size,
|
|
4091
|
+
[SemanticInternalAttributes.STYLE_ICON]: "cloud-upload"
|
|
4092
|
+
}
|
|
4093
|
+
});
|
|
4094
|
+
return result ?? packet;
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
return packet;
|
|
4099
|
+
}
|
|
4100
|
+
__name(conditionallyExportPacket, "conditionallyExportPacket");
|
|
4101
|
+
function packetRequiresOffloading(packet) {
|
|
4102
|
+
if (!packet.data) {
|
|
4103
|
+
return {
|
|
4104
|
+
needsOffloading: false,
|
|
4105
|
+
size: 0
|
|
4106
|
+
};
|
|
4107
|
+
}
|
|
4108
|
+
const byteSize = Buffer.byteLength(packet.data, "utf8");
|
|
4109
|
+
return {
|
|
4110
|
+
needsOffloading: byteSize >= OFFLOAD_IO_PACKET_LENGTH_LIMIT,
|
|
4111
|
+
size: byteSize
|
|
4112
|
+
};
|
|
4113
|
+
}
|
|
4114
|
+
__name(packetRequiresOffloading, "packetRequiresOffloading");
|
|
4115
|
+
async function exportPacket(packet, pathPrefix) {
|
|
4116
|
+
const filename = `${pathPrefix}.${getPacketExtension(packet.dataType)}`;
|
|
4117
|
+
const presignedResponse = await apiClientManager.client.createUploadPayloadUrl(filename);
|
|
4118
|
+
if (presignedResponse.ok) {
|
|
4119
|
+
const uploadResponse = await fetch(presignedResponse.data.presignedUrl, {
|
|
4120
|
+
method: "PUT",
|
|
4121
|
+
headers: {
|
|
4122
|
+
"Content-Type": packet.dataType
|
|
4123
|
+
},
|
|
4124
|
+
body: packet.data
|
|
4125
|
+
});
|
|
4126
|
+
if (!uploadResponse.ok) {
|
|
4127
|
+
throw new Error(`Failed to upload output to ${presignedResponse.data.presignedUrl}: ${uploadResponse.statusText}`);
|
|
4128
|
+
}
|
|
4129
|
+
return {
|
|
4130
|
+
data: filename,
|
|
4131
|
+
dataType: "application/store"
|
|
4132
|
+
};
|
|
4133
|
+
}
|
|
4134
|
+
return packet;
|
|
4135
|
+
}
|
|
4136
|
+
__name(exportPacket, "exportPacket");
|
|
4137
|
+
async function conditionallyImportPacket(packet, tracer) {
|
|
4138
|
+
if (packet.dataType !== "application/store") {
|
|
4139
|
+
return packet;
|
|
4140
|
+
}
|
|
4141
|
+
if (!tracer) {
|
|
4142
|
+
return await importPacket(packet);
|
|
4143
|
+
} else {
|
|
4144
|
+
const result = await tracer.startActiveSpan("store.downloadPayload", async (span) => {
|
|
4145
|
+
return await importPacket(packet, span);
|
|
4146
|
+
}, {
|
|
4147
|
+
attributes: {
|
|
4148
|
+
[SemanticInternalAttributes.STYLE_ICON]: "cloud-download"
|
|
4149
|
+
}
|
|
4150
|
+
});
|
|
4151
|
+
return result ?? packet;
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
__name(conditionallyImportPacket, "conditionallyImportPacket");
|
|
4155
|
+
async function importPacket(packet, span) {
|
|
4156
|
+
if (!packet.data) {
|
|
4157
|
+
return packet;
|
|
4158
|
+
}
|
|
4159
|
+
if (!apiClientManager.client) {
|
|
4160
|
+
return packet;
|
|
4161
|
+
}
|
|
4162
|
+
const presignedResponse = await apiClientManager.client.getPayloadUrl(packet.data);
|
|
4163
|
+
if (presignedResponse.ok) {
|
|
4164
|
+
const response = await fetch(presignedResponse.data.presignedUrl);
|
|
4165
|
+
if (!response.ok) {
|
|
4166
|
+
throw new Error(`Failed to import packet ${presignedResponse.data.presignedUrl}: ${response.statusText}`);
|
|
4167
|
+
}
|
|
4168
|
+
const data = await response.text();
|
|
4169
|
+
span?.setAttribute("size", Buffer.byteLength(data, "utf8"));
|
|
4170
|
+
return {
|
|
4171
|
+
data,
|
|
4172
|
+
dataType: response.headers.get("content-type") ?? "application/json"
|
|
4173
|
+
};
|
|
4174
|
+
}
|
|
4175
|
+
return packet;
|
|
4176
|
+
}
|
|
4177
|
+
__name(importPacket, "importPacket");
|
|
4178
|
+
async function createPacketAttributes(packet, dataKey, dataTypeKey) {
|
|
4179
|
+
if (!packet.data) {
|
|
4180
|
+
return;
|
|
4181
|
+
}
|
|
4182
|
+
switch (packet.dataType) {
|
|
4183
|
+
case "application/json":
|
|
4184
|
+
return {
|
|
4185
|
+
...flattenAttributes(packet, dataKey),
|
|
4186
|
+
[dataTypeKey]: packet.dataType
|
|
4187
|
+
};
|
|
4188
|
+
case "application/super+json":
|
|
4189
|
+
const { parse } = await loadSuperJSON();
|
|
4190
|
+
if (typeof packet.data === "undefined" || packet.data === null) {
|
|
4191
|
+
return;
|
|
4192
|
+
}
|
|
4193
|
+
try {
|
|
4194
|
+
const parsed = parse(packet.data);
|
|
4195
|
+
const jsonified = JSON.parse(JSON.stringify(parsed, safeReplacer));
|
|
4196
|
+
return {
|
|
4197
|
+
...flattenAttributes(jsonified, dataKey),
|
|
4198
|
+
[dataTypeKey]: "application/json"
|
|
4199
|
+
};
|
|
4200
|
+
} catch {
|
|
4201
|
+
return;
|
|
4202
|
+
}
|
|
4203
|
+
case "application/store":
|
|
4204
|
+
return {
|
|
4205
|
+
[dataKey]: packet.data,
|
|
4206
|
+
[dataTypeKey]: packet.dataType
|
|
4207
|
+
};
|
|
4208
|
+
case "text/plain":
|
|
4209
|
+
return {
|
|
4210
|
+
[dataKey]: packet.data,
|
|
4211
|
+
[dataTypeKey]: packet.dataType
|
|
4212
|
+
};
|
|
4213
|
+
default:
|
|
4214
|
+
return;
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
__name(createPacketAttributes, "createPacketAttributes");
|
|
4218
|
+
async function createPacketAttributesAsJson(data, dataType) {
|
|
4219
|
+
if (typeof data === "string" || typeof data === "number" || typeof data === "boolean" || data === null || data === void 0) {
|
|
4220
|
+
return data;
|
|
4221
|
+
}
|
|
4222
|
+
switch (dataType) {
|
|
4223
|
+
case "application/json":
|
|
4224
|
+
return imposeAttributeLimits(flattenAttributes(data, void 0));
|
|
4225
|
+
case "application/super+json":
|
|
4226
|
+
const { deserialize } = await loadSuperJSON();
|
|
4227
|
+
const deserialized = deserialize(data);
|
|
4228
|
+
const jsonify = safeJsonParse(JSON.stringify(deserialized, safeReplacer));
|
|
4229
|
+
return imposeAttributeLimits(flattenAttributes(jsonify, void 0));
|
|
4230
|
+
case "application/store":
|
|
4231
|
+
return data;
|
|
4232
|
+
default:
|
|
4233
|
+
return {};
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
__name(createPacketAttributesAsJson, "createPacketAttributesAsJson");
|
|
4237
|
+
async function prettyPrintPacket(rawData, dataType) {
|
|
4238
|
+
if (rawData === void 0) {
|
|
4239
|
+
return "";
|
|
4240
|
+
}
|
|
4241
|
+
if (dataType === "application/super+json") {
|
|
4242
|
+
const { deserialize } = await loadSuperJSON();
|
|
4243
|
+
return await prettyPrintPacket(deserialize(rawData), "application/json");
|
|
4244
|
+
}
|
|
4245
|
+
if (dataType === "application/json") {
|
|
4246
|
+
return JSON.stringify(rawData, safeReplacer, 2);
|
|
4247
|
+
}
|
|
4248
|
+
if (typeof rawData === "string") {
|
|
4249
|
+
return rawData;
|
|
4250
|
+
}
|
|
4251
|
+
return JSON.stringify(rawData, safeReplacer, 2);
|
|
4252
|
+
}
|
|
4253
|
+
__name(prettyPrintPacket, "prettyPrintPacket");
|
|
4254
|
+
function safeReplacer(key, value) {
|
|
4255
|
+
if (typeof value === "bigint") {
|
|
4256
|
+
return value.toString();
|
|
4257
|
+
}
|
|
4258
|
+
if (value instanceof RegExp) {
|
|
4259
|
+
return value.toString();
|
|
4260
|
+
}
|
|
4261
|
+
if (value instanceof Set) {
|
|
4262
|
+
return Array.from(value);
|
|
4263
|
+
}
|
|
4264
|
+
if (value instanceof Map) {
|
|
4265
|
+
const obj = {};
|
|
4266
|
+
value.forEach((v, k) => {
|
|
4267
|
+
obj[k] = v;
|
|
4268
|
+
});
|
|
4269
|
+
return obj;
|
|
4270
|
+
}
|
|
4271
|
+
return value;
|
|
4272
|
+
}
|
|
4273
|
+
__name(safeReplacer, "safeReplacer");
|
|
4274
|
+
function getPacketExtension(outputType) {
|
|
4275
|
+
switch (outputType) {
|
|
4276
|
+
case "application/json":
|
|
4277
|
+
return "json";
|
|
4278
|
+
case "application/super+json":
|
|
4279
|
+
return "json";
|
|
4280
|
+
case "text/plain":
|
|
4281
|
+
return "txt";
|
|
4282
|
+
default:
|
|
4283
|
+
return "txt";
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
__name(getPacketExtension, "getPacketExtension");
|
|
4287
|
+
async function loadSuperJSON() {
|
|
4288
|
+
return await import('superjson');
|
|
4289
|
+
}
|
|
4290
|
+
__name(loadSuperJSON, "loadSuperJSON");
|
|
4291
|
+
function safeJsonParse(value) {
|
|
4292
|
+
try {
|
|
4293
|
+
return JSON.parse(value);
|
|
4294
|
+
} catch {
|
|
4295
|
+
return;
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
__name(safeJsonParse, "safeJsonParse");
|
|
4299
|
+
|
|
4300
|
+
// src/v3/workers/taskExecutor.ts
|
|
3753
4301
|
var _callRun, callRun_fn, _callTaskInit, callTaskInit_fn, _callTaskCleanup, callTaskCleanup_fn, _handleError, handleError_fn;
|
|
3754
4302
|
var _TaskExecutor = class _TaskExecutor {
|
|
3755
4303
|
constructor(task, options) {
|
|
@@ -3766,12 +4314,14 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
3766
4314
|
this._handleErrorFn = options.handleErrorFn;
|
|
3767
4315
|
}
|
|
3768
4316
|
async execute(execution, worker, traceContext) {
|
|
3769
|
-
const parsedPayload = JSON.parse(execution.run.payload);
|
|
3770
4317
|
const ctx = TaskRunContext.parse(execution);
|
|
3771
4318
|
const attemptMessage = `Attempt ${execution.attempt.number}`;
|
|
4319
|
+
const originalPacket = {
|
|
4320
|
+
data: execution.run.payload,
|
|
4321
|
+
dataType: execution.run.payloadType
|
|
4322
|
+
};
|
|
3772
4323
|
const result = await taskContextManager.runWith({
|
|
3773
4324
|
ctx,
|
|
3774
|
-
payload: parsedPayload,
|
|
3775
4325
|
worker
|
|
3776
4326
|
}, async () => {
|
|
3777
4327
|
this._tracingSDK.asyncResourceDetector.resolveWithAttributes({
|
|
@@ -3781,17 +4331,25 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
3781
4331
|
});
|
|
3782
4332
|
return await this._tracer.startActiveSpan(attemptMessage, async (span) => {
|
|
3783
4333
|
return await this._consoleInterceptor.intercept(console, async () => {
|
|
3784
|
-
|
|
4334
|
+
let parsedPayload;
|
|
4335
|
+
let initOutput;
|
|
3785
4336
|
try {
|
|
3786
|
-
const
|
|
4337
|
+
const payloadPacket = await conditionallyImportPacket(originalPacket, this._tracer);
|
|
4338
|
+
parsedPayload = await parsePacket(payloadPacket);
|
|
4339
|
+
initOutput = await __privateMethod(this, _callTaskInit, callTaskInit_fn).call(this, parsedPayload, ctx);
|
|
4340
|
+
const output = await __privateMethod(this, _callRun, callRun_fn).call(this, parsedPayload, ctx, initOutput);
|
|
3787
4341
|
try {
|
|
3788
|
-
|
|
3789
|
-
const
|
|
4342
|
+
const stringifiedOutput = await stringifyIO(output);
|
|
4343
|
+
const finalOutput = await conditionallyExportPacket(stringifiedOutput, `${execution.attempt.id}/output`, this._tracer);
|
|
4344
|
+
const attributes = await createPacketAttributes(finalOutput, SemanticInternalAttributes.OUTPUT, SemanticInternalAttributes.OUTPUT_TYPE);
|
|
4345
|
+
if (attributes) {
|
|
4346
|
+
span.setAttributes(attributes);
|
|
4347
|
+
}
|
|
3790
4348
|
return {
|
|
3791
4349
|
ok: true,
|
|
3792
4350
|
id: execution.attempt.id,
|
|
3793
|
-
output:
|
|
3794
|
-
outputType:
|
|
4351
|
+
output: finalOutput.data,
|
|
4352
|
+
outputType: finalOutput.dataType
|
|
3795
4353
|
};
|
|
3796
4354
|
} catch (stringifyError) {
|
|
3797
4355
|
recordSpanException(span, stringifyError);
|
|
@@ -3829,14 +4387,13 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
3829
4387
|
};
|
|
3830
4388
|
}
|
|
3831
4389
|
} finally {
|
|
3832
|
-
await __privateMethod(this, _callTaskCleanup, callTaskCleanup_fn).call(this, parsedPayload, ctx,
|
|
4390
|
+
await __privateMethod(this, _callTaskCleanup, callTaskCleanup_fn).call(this, parsedPayload, ctx, initOutput);
|
|
3833
4391
|
}
|
|
3834
4392
|
});
|
|
3835
4393
|
}, {
|
|
3836
4394
|
kind: api.SpanKind.CONSUMER,
|
|
3837
4395
|
attributes: {
|
|
3838
4396
|
[SemanticInternalAttributes.STYLE_ICON]: "attempt",
|
|
3839
|
-
...flattenAttributes(parsedPayload, SemanticInternalAttributes.PAYLOAD),
|
|
3840
4397
|
...accessoryAttributes({
|
|
3841
4398
|
items: [
|
|
3842
4399
|
{
|
|
@@ -4007,6 +4564,7 @@ var dependencies = {
|
|
|
4007
4564
|
"humanize-duration": "^3.27.3",
|
|
4008
4565
|
"socket.io": "^4.7.4",
|
|
4009
4566
|
"socket.io-client": "^4.7.4",
|
|
4567
|
+
superjson: "^2.2.1",
|
|
4010
4568
|
ulidx: "^2.2.1",
|
|
4011
4569
|
zod: "3.22.3",
|
|
4012
4570
|
"zod-error": "1.5.0"
|
|
@@ -4046,7 +4604,11 @@ exports.CoordinatorToProdWorkerMessages = CoordinatorToProdWorkerMessages;
|
|
|
4046
4604
|
exports.CreateAuthorizationCodeResponseSchema = CreateAuthorizationCodeResponseSchema;
|
|
4047
4605
|
exports.CreateBackgroundWorkerRequestBody = CreateBackgroundWorkerRequestBody;
|
|
4048
4606
|
exports.CreateBackgroundWorkerResponse = CreateBackgroundWorkerResponse;
|
|
4607
|
+
exports.CreateUploadPayloadUrlResponseBody = CreateUploadPayloadUrlResponseBody;
|
|
4608
|
+
exports.DeploymentErrorData = DeploymentErrorData;
|
|
4049
4609
|
exports.DevRuntimeManager = DevRuntimeManager;
|
|
4610
|
+
exports.DurableClock = PreciseWallClock;
|
|
4611
|
+
exports.EnvironmentType = EnvironmentType;
|
|
4050
4612
|
exports.EventFilter = EventFilter;
|
|
4051
4613
|
exports.ExceptionEventProperties = ExceptionEventProperties;
|
|
4052
4614
|
exports.ExceptionSpanEvent = ExceptionSpanEvent;
|
|
@@ -4070,11 +4632,24 @@ exports.ImageDetailsMetadata = ImageDetailsMetadata;
|
|
|
4070
4632
|
exports.InitializeDeploymentRequestBody = InitializeDeploymentRequestBody;
|
|
4071
4633
|
exports.InitializeDeploymentResponseBody = InitializeDeploymentResponseBody;
|
|
4072
4634
|
exports.Machine = Machine;
|
|
4635
|
+
exports.MachineCpu = MachineCpu;
|
|
4636
|
+
exports.MachineMemory = MachineMemory;
|
|
4637
|
+
exports.OFFLOAD_IO_PACKET_LENGTH_LIMIT = OFFLOAD_IO_PACKET_LENGTH_LIMIT;
|
|
4638
|
+
exports.OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT = OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT;
|
|
4639
|
+
exports.OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT = OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT;
|
|
4640
|
+
exports.OTEL_LINK_COUNT_LIMIT = OTEL_LINK_COUNT_LIMIT;
|
|
4641
|
+
exports.OTEL_LOG_ATTRIBUTE_COUNT_LIMIT = OTEL_LOG_ATTRIBUTE_COUNT_LIMIT;
|
|
4642
|
+
exports.OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT = OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT;
|
|
4643
|
+
exports.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT;
|
|
4644
|
+
exports.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT;
|
|
4645
|
+
exports.OTEL_SPAN_EVENT_COUNT_LIMIT = OTEL_SPAN_EVENT_COUNT_LIMIT;
|
|
4073
4646
|
exports.OtelTaskLogger = OtelTaskLogger;
|
|
4074
4647
|
exports.OtherSpanEvent = OtherSpanEvent;
|
|
4075
4648
|
exports.PRIMARY_VARIANT = PRIMARY_VARIANT;
|
|
4076
4649
|
exports.PlatformToCoordinatorMessages = PlatformToCoordinatorMessages;
|
|
4077
4650
|
exports.PlatformToProviderMessages = PlatformToProviderMessages;
|
|
4651
|
+
exports.PostStartCauses = PostStartCauses;
|
|
4652
|
+
exports.PreStopCauses = PreStopCauses;
|
|
4078
4653
|
exports.ProdChildToWorkerMessages = ProdChildToWorkerMessages;
|
|
4079
4654
|
exports.ProdRuntimeManager = ProdRuntimeManager;
|
|
4080
4655
|
exports.ProdTaskRunExecution = ProdTaskRunExecution;
|
|
@@ -4099,6 +4674,7 @@ exports.TaskContextSpanProcessor = TaskContextSpanProcessor;
|
|
|
4099
4674
|
exports.TaskEventStyle = TaskEventStyle;
|
|
4100
4675
|
exports.TaskExecutor = TaskExecutor;
|
|
4101
4676
|
exports.TaskMetadata = TaskMetadata;
|
|
4677
|
+
exports.TaskMetadataFailedToParseData = TaskMetadataFailedToParseData;
|
|
4102
4678
|
exports.TaskMetadataWithFilePath = TaskMetadataWithFilePath;
|
|
4103
4679
|
exports.TaskResource = TaskResource;
|
|
4104
4680
|
exports.TaskRun = TaskRun;
|
|
@@ -4134,18 +4710,23 @@ exports.ZodMessageHandler = ZodMessageHandler;
|
|
|
4134
4710
|
exports.ZodMessageSchema = ZodMessageSchema;
|
|
4135
4711
|
exports.ZodMessageSender = ZodMessageSender;
|
|
4136
4712
|
exports.ZodNamespace = ZodNamespace;
|
|
4713
|
+
exports.ZodSchemaParsedError = ZodSchemaParsedError;
|
|
4137
4714
|
exports.ZodSocketConnection = ZodSocketConnection;
|
|
4138
4715
|
exports.ZodSocketMessageHandler = ZodSocketMessageHandler;
|
|
4139
4716
|
exports.ZodSocketMessageSender = ZodSocketMessageSender;
|
|
4140
4717
|
exports.accessoryAttributes = accessoryAttributes;
|
|
4141
4718
|
exports.apiClientManager = apiClientManager;
|
|
4142
4719
|
exports.calculateNextRetryDelay = calculateNextRetryDelay;
|
|
4143
|
-
exports.calculatePreciseDateHrTime = calculatePreciseDateHrTime;
|
|
4144
4720
|
exports.calculateResetAt = calculateResetAt2;
|
|
4145
4721
|
exports.childToWorkerMessages = childToWorkerMessages;
|
|
4146
4722
|
exports.clientWebsocketMessages = clientWebsocketMessages;
|
|
4723
|
+
exports.clock = clock;
|
|
4724
|
+
exports.conditionallyExportPacket = conditionallyExportPacket;
|
|
4725
|
+
exports.conditionallyImportPacket = conditionallyImportPacket;
|
|
4147
4726
|
exports.correctErrorStackTrace = correctErrorStackTrace;
|
|
4148
4727
|
exports.createErrorTaskError = createErrorTaskError;
|
|
4728
|
+
exports.createPacketAttributes = createPacketAttributes;
|
|
4729
|
+
exports.createPacketAttributesAsJson = createPacketAttributesAsJson;
|
|
4149
4730
|
exports.defaultFetchRetryOptions = defaultFetchRetryOptions;
|
|
4150
4731
|
exports.defaultRetryOptions = defaultRetryOptions;
|
|
4151
4732
|
exports.detectDependencyVersion = detectDependencyVersion;
|
|
@@ -4156,22 +4737,28 @@ exports.formatDurationInDays = formatDurationInDays;
|
|
|
4156
4737
|
exports.formatDurationMilliseconds = formatDurationMilliseconds;
|
|
4157
4738
|
exports.formatDurationNanoseconds = formatDurationNanoseconds;
|
|
4158
4739
|
exports.getEnvVar = getEnvVar;
|
|
4740
|
+
exports.groupTaskMetadataIssuesByTask = groupTaskMetadataIssuesByTask;
|
|
4159
4741
|
exports.iconStringForSeverity = iconStringForSeverity;
|
|
4742
|
+
exports.imposeAttributeLimits = imposeAttributeLimits;
|
|
4160
4743
|
exports.isCancellationSpanEvent = isCancellationSpanEvent;
|
|
4161
4744
|
exports.isExceptionSpanEvent = isExceptionSpanEvent;
|
|
4745
|
+
exports.logLevels = logLevels;
|
|
4162
4746
|
exports.logger = logger;
|
|
4163
4747
|
exports.millisecondsToNanoseconds = millisecondsToNanoseconds;
|
|
4164
4748
|
exports.nanosecondsToMilliseconds = nanosecondsToMilliseconds;
|
|
4165
4749
|
exports.omit = omit;
|
|
4750
|
+
exports.packetRequiresOffloading = packetRequiresOffloading;
|
|
4166
4751
|
exports.parseBatchTriggerTaskRequestBody = parseBatchTriggerTaskRequestBody;
|
|
4167
4752
|
exports.parseError = parseError;
|
|
4753
|
+
exports.parsePacket = parsePacket;
|
|
4168
4754
|
exports.parseTriggerTaskRequestBody = parseTriggerTaskRequestBody;
|
|
4169
|
-
exports.
|
|
4755
|
+
exports.prettyPrintPacket = prettyPrintPacket;
|
|
4170
4756
|
exports.primitiveValueOrflattenedAttributes = primitiveValueOrflattenedAttributes;
|
|
4171
4757
|
exports.recordSpanException = recordSpanException;
|
|
4172
4758
|
exports.runtime = runtime;
|
|
4173
4759
|
exports.serverWebsocketMessages = serverWebsocketMessages;
|
|
4174
4760
|
exports.stringPatternMatchers = stringPatternMatchers;
|
|
4761
|
+
exports.stringifyIO = stringifyIO;
|
|
4175
4762
|
exports.taskContextManager = taskContextManager;
|
|
4176
4763
|
exports.unflattenAttributes = unflattenAttributes;
|
|
4177
4764
|
exports.workerToChildMessages = workerToChildMessages;
|