@versori/run 0.5.9 → 0.6.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/esm/src/connection/internal/CredentialHolder.js +1 -1
  2. package/esm/src/connection/internal/FetchBuilder.d.ts +9 -2
  3. package/esm/src/connection/internal/FetchBuilder.d.ts.map +1 -1
  4. package/esm/src/connection/internal/FetchBuilder.js +124 -3
  5. package/esm/src/context/Context.d.ts +5 -0
  6. package/esm/src/context/Context.d.ts.map +1 -1
  7. package/esm/src/context/Context.js +6 -0
  8. package/esm/src/dsl/Workflow.d.ts.map +1 -1
  9. package/esm/src/dsl/Workflow.js +2 -0
  10. package/esm/src/dsl/http/types.d.ts +2 -0
  11. package/esm/src/dsl/http/types.d.ts.map +1 -1
  12. package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
  13. package/esm/src/dsl/http/versori/configloader.js +1 -1
  14. package/esm/src/dsl/http/versori/cronapi.d.ts +2 -3
  15. package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -1
  16. package/esm/src/dsl/http/versori/cronapi.js +14 -15
  17. package/esm/src/dsl/http/versori/kvapi/core/OpenAPI.js +1 -1
  18. package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
  19. package/esm/src/dsl/triggers/WebhookTrigger.js +3 -1
  20. package/esm/src/internal/constants.d.ts +3 -0
  21. package/esm/src/internal/constants.d.ts.map +1 -1
  22. package/esm/src/internal/constants.js +3 -0
  23. package/esm/src/internal/supervisor.d.ts +23 -0
  24. package/esm/src/internal/supervisor.d.ts.map +1 -0
  25. package/esm/src/internal/supervisor.js +267 -0
  26. package/esm/src/interpreter/durable/DurableInterpreter.d.ts +9 -2
  27. package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
  28. package/esm/src/interpreter/durable/DurableInterpreter.js +57 -13
  29. package/esm/src/interpreter/durable/ObservableCompiler.d.ts +6 -1
  30. package/esm/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -1
  31. package/esm/src/interpreter/durable/Queue.js +1 -1
  32. package/esm/src/interpreter/durable/compilers/catch.d.ts.map +1 -1
  33. package/esm/src/interpreter/durable/compilers/catch.js +3 -1
  34. package/esm/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
  35. package/esm/src/interpreter/durable/compilers/fn.js +29 -6
  36. package/esm/src/interpreter/durable/compilers/http.d.ts.map +1 -1
  37. package/esm/src/interpreter/durable/compilers/http.js +45 -11
  38. package/esm/src/interpreter/durable/compilers/schedule.d.ts.map +1 -1
  39. package/esm/src/interpreter/durable/compilers/schedule.js +4 -3
  40. package/esm/src/interpreter/durable/compilers/webhook.d.ts.map +1 -1
  41. package/esm/src/interpreter/durable/compilers/webhook.js +2 -0
  42. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +8 -1
  43. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  44. package/esm/src/interpreter/memory/MemoryInterpreter.js +56 -12
  45. package/esm/src/interpreter/memory/ObservableCompiler.d.ts +6 -1
  46. package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
  47. package/esm/src/interpreter/memory/compilers/catch.d.ts.map +1 -1
  48. package/esm/src/interpreter/memory/compilers/catch.js +5 -0
  49. package/esm/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
  50. package/esm/src/interpreter/memory/compilers/fn.js +29 -18
  51. package/esm/src/interpreter/memory/compilers/http.d.ts.map +1 -1
  52. package/esm/src/interpreter/memory/compilers/http.js +44 -10
  53. package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
  54. package/esm/src/interpreter/memory/compilers/schedule.js +61 -4
  55. package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
  56. package/esm/src/interpreter/memory/compilers/webhook.js +9 -3
  57. package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts +1 -0
  58. package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -1
  59. package/esm/src/interpreter/vanilla/VanillaInterpreter.js +30 -6
  60. package/esm/src/interpreter/vanilla/compilers/schedule.js +1 -1
  61. package/esm/src/issues/Issues.d.ts.map +1 -1
  62. package/esm/src/issues/Issues.js +6 -1
  63. package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
  64. package/package.json +3 -1
  65. package/script/src/connection/internal/CredentialHolder.js +1 -1
  66. package/script/src/connection/internal/FetchBuilder.d.ts +9 -2
  67. package/script/src/connection/internal/FetchBuilder.d.ts.map +1 -1
  68. package/script/src/connection/internal/FetchBuilder.js +147 -3
  69. package/script/src/context/Context.d.ts +5 -0
  70. package/script/src/context/Context.d.ts.map +1 -1
  71. package/script/src/context/Context.js +6 -0
  72. package/script/src/dsl/Workflow.d.ts.map +1 -1
  73. package/script/src/dsl/Workflow.js +2 -0
  74. package/script/src/dsl/http/types.d.ts +2 -0
  75. package/script/src/dsl/http/types.d.ts.map +1 -1
  76. package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
  77. package/script/src/dsl/http/versori/configloader.js +1 -1
  78. package/script/src/dsl/http/versori/cronapi.d.ts +2 -3
  79. package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -1
  80. package/script/src/dsl/http/versori/cronapi.js +14 -15
  81. package/script/src/dsl/http/versori/kvapi/core/OpenAPI.js +1 -1
  82. package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
  83. package/script/src/dsl/triggers/WebhookTrigger.js +3 -1
  84. package/script/src/internal/constants.d.ts +3 -0
  85. package/script/src/internal/constants.d.ts.map +1 -1
  86. package/script/src/internal/constants.js +4 -1
  87. package/script/src/internal/supervisor.d.ts +23 -0
  88. package/script/src/internal/supervisor.d.ts.map +1 -0
  89. package/script/src/internal/supervisor.js +275 -0
  90. package/script/src/interpreter/durable/DurableInterpreter.d.ts +9 -2
  91. package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
  92. package/script/src/interpreter/durable/DurableInterpreter.js +62 -18
  93. package/script/src/interpreter/durable/ObservableCompiler.d.ts +6 -1
  94. package/script/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -1
  95. package/script/src/interpreter/durable/Queue.js +1 -1
  96. package/script/src/interpreter/durable/compilers/catch.d.ts.map +1 -1
  97. package/script/src/interpreter/durable/compilers/catch.js +3 -1
  98. package/script/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
  99. package/script/src/interpreter/durable/compilers/fn.js +28 -5
  100. package/script/src/interpreter/durable/compilers/http.d.ts.map +1 -1
  101. package/script/src/interpreter/durable/compilers/http.js +45 -11
  102. package/script/src/interpreter/durable/compilers/schedule.d.ts.map +1 -1
  103. package/script/src/interpreter/durable/compilers/schedule.js +4 -3
  104. package/script/src/interpreter/durable/compilers/webhook.d.ts.map +1 -1
  105. package/script/src/interpreter/durable/compilers/webhook.js +2 -0
  106. package/script/src/interpreter/memory/MemoryInterpreter.d.ts +8 -1
  107. package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  108. package/script/src/interpreter/memory/MemoryInterpreter.js +55 -11
  109. package/script/src/interpreter/memory/ObservableCompiler.d.ts +6 -1
  110. package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
  111. package/script/src/interpreter/memory/compilers/catch.d.ts.map +1 -1
  112. package/script/src/interpreter/memory/compilers/catch.js +5 -0
  113. package/script/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
  114. package/script/src/interpreter/memory/compilers/fn.js +28 -17
  115. package/script/src/interpreter/memory/compilers/http.d.ts.map +1 -1
  116. package/script/src/interpreter/memory/compilers/http.js +44 -10
  117. package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
  118. package/script/src/interpreter/memory/compilers/schedule.js +61 -4
  119. package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
  120. package/script/src/interpreter/memory/compilers/webhook.js +9 -3
  121. package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts +1 -0
  122. package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -1
  123. package/script/src/interpreter/vanilla/VanillaInterpreter.js +30 -6
  124. package/script/src/interpreter/vanilla/compilers/schedule.js +1 -1
  125. package/script/src/issues/Issues.d.ts.map +1 -1
  126. package/script/src/issues/Issues.js +6 -1
  127. package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
  128. package/esm/src/dsl/http/versori/constants.d.ts +0 -21
  129. package/esm/src/dsl/http/versori/constants.d.ts.map +0 -1
  130. package/esm/src/dsl/http/versori/constants.js +0 -38
  131. package/script/src/dsl/http/versori/constants.d.ts +0 -21
  132. package/script/src/dsl/http/versori/constants.d.ts.map +0 -1
  133. package/script/src/dsl/http/versori/constants.js +0 -41
@@ -11,8 +11,9 @@
11
11
  * use of this software will be governed by the Apache License, Version 2.0.
12
12
  */
13
13
  import { Observable } from 'rxjs';
14
- import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../dsl/http/versori/constants.js';
15
14
  import { ScheduleTrigger } from '../../../dsl/triggers/ScheduleTrigger.js';
15
+ import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../internal/constants.js';
16
+ import { sendTaskStartEvent } from '../../../internal/supervisor.js';
16
17
  function compileSchedule(ctx, trigger, signal) {
17
18
  return new Observable((subscriber) => {
18
19
  // Add HTTP endpoint for manual triggering
@@ -25,8 +26,43 @@ function compileSchedule(ctx, trigger, signal) {
25
26
  const orgId = Deno.env.get(envVarOrgId) || 'example-org';
26
27
  const client = ctx.platformApi;
27
28
  ctx.cronRegistry.set(trigger.id, trigger.schedule);
28
- async function handleSchedule(_req, res, span) {
29
+ async function handleSchedule(req, res, span) {
29
30
  try {
31
+ // run for a single activation
32
+ const activationId = req.params.activationId;
33
+ if (activationId) {
34
+ const { data: activation } = await client.getActivation({
35
+ path: {
36
+ organisation_id: ctx.organisationId,
37
+ environment_id: environmentId,
38
+ activation_id: activationId,
39
+ },
40
+ throwOnError: false,
41
+ });
42
+ if (!activation) {
43
+ res.status(412).json({
44
+ status: 'error',
45
+ message: `No activation found for ID: ${activationId}`,
46
+ });
47
+ return;
48
+ }
49
+ const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
50
+ span.setAttribute('execution.id', executionCtx.executionId);
51
+ await sendTaskStartEvent(trigger.id, executionCtx, span);
52
+ try {
53
+ ctx.log.info(`Running schedule ${trigger.id} for activation ${activationId}`);
54
+ subscriber.next(executionCtx);
55
+ }
56
+ catch (error) {
57
+ executionCtx.log.error('execution error inside schedule', { error });
58
+ }
59
+ res.status(200).json({
60
+ status: 'triggered',
61
+ executionId: executionCtx.executionId,
62
+ });
63
+ return;
64
+ }
65
+ // run for static activation only
30
66
  if (trigger.activationPredicate === undefined) {
31
67
  const { data: activation } = await client.listActivations({
32
68
  path: {
@@ -45,8 +81,9 @@ function compileSchedule(ctx, trigger, signal) {
45
81
  });
46
82
  return;
47
83
  }
48
- const executionCtx = ctx.contextProvider.create(activation[0], {});
84
+ const executionCtx = ctx.contextProvider.create(activation[0], {}, { workflowId: trigger.id });
49
85
  span.setAttribute('execution.id', executionCtx.executionId);
86
+ await sendTaskStartEvent(trigger.id, executionCtx, span);
50
87
  try {
51
88
  subscriber.next(executionCtx);
52
89
  }
@@ -59,6 +96,7 @@ function compileSchedule(ctx, trigger, signal) {
59
96
  });
60
97
  return;
61
98
  }
99
+ // run for all activations
62
100
  const { data: activations } = await client.listActivations({
63
101
  path: {
64
102
  organisation_id: ctx.organisationId,
@@ -77,8 +115,9 @@ function compileSchedule(ctx, trigger, signal) {
77
115
  return;
78
116
  }
79
117
  activations.forEach((activation) => {
80
- const executionCtx = ctx.contextProvider.create(activation, {});
118
+ const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
81
119
  try {
120
+ ctx.log.info(`Running schedule ${trigger.id} for activation ${activation.id}`);
82
121
  subscriber.next(executionCtx);
83
122
  }
84
123
  catch (error) {
@@ -96,11 +135,29 @@ function compileSchedule(ctx, trigger, signal) {
96
135
  await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
97
136
  span.setAttribute('task.id', trigger.id);
98
137
  span.setAttribute('task.type', 'schedule');
138
+ span.setAttribute('type', 'task');
139
+ span.setAttribute('schedule', trigger.schedule);
140
+ span.setAttribute('project.id', projectId);
141
+ span.setAttribute('environment.id', environmentId);
142
+ span.setAttribute('environment.name', environmentName);
143
+ span.setAttribute('org.id', orgId);
144
+ span.setAttribute('workflow.id', trigger.id);
145
+ await handleSchedule(req, res, span);
146
+ span.end();
147
+ });
148
+ });
149
+ ctx.cronRouter.post(`/cron/${trigger.id}/activations/:activationId`, async (req, res) => {
150
+ await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
151
+ span.setAttribute('task.id', trigger.id);
152
+ span.setAttribute('activation.id', req.params.activationId);
153
+ span.setAttribute('task.type', 'schedule');
154
+ span.setAttribute('type', 'task');
99
155
  span.setAttribute('schedule', trigger.schedule);
100
156
  span.setAttribute('project.id', projectId);
101
157
  span.setAttribute('environment.id', environmentId);
102
158
  span.setAttribute('environment.name', environmentName);
103
159
  span.setAttribute('org.id', orgId);
160
+ span.setAttribute('workflow.id', trigger.id);
104
161
  await handleSchedule(req, res, span);
105
162
  span.end();
106
163
  });
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAGtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA0SxE,CAAC"}
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAItF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAmTxE,CAAC"}
@@ -18,6 +18,7 @@ import { Observable } from 'rxjs';
18
18
  import { createActIdDynamicWebhookMiddleware, createStaticWebhookMiddleware, createUserIdDynamicWebhookMiddleware, } from '../../../dsl/http/versori/webhookmiddleware.js';
19
19
  import { WebhookTrigger } from '../../../dsl/triggers/WebhookTrigger.js';
20
20
  import { envVarEnvId } from '../../../internal/constants.js';
21
+ import { sendTaskStartEvent } from '../../../internal/supervisor.js';
21
22
  const xml2jsDefaults = {
22
23
  explicitArray: false,
23
24
  normalize: false,
@@ -84,6 +85,7 @@ export const webhookCompiler = {
84
85
  onError = trigger.options.response.onError;
85
86
  }
86
87
  const ctxOptionsFn = (req, res) => ({
88
+ workflowId: trigger.id,
87
89
  onSuccess: (ctx) => {
88
90
  if (isSync) {
89
91
  sendResponse(res, onSuccess(ctx));
@@ -104,6 +106,7 @@ export const webhookCompiler = {
104
106
  else {
105
107
  routeMiddleware.push(express.raw({ type: '*/*', limit: '50mb' }));
106
108
  }
109
+ ctx.webhookRegistry.set(trigger.id, { method, path: `/${trigger.id}`, options: trigger.options });
107
110
  return new Observable((subscriber) => {
108
111
  if (!ctx.webhookRouter) {
109
112
  throw new Error('Router not available in compiler context');
@@ -129,12 +132,13 @@ export const webhookCompiler = {
129
132
  cfgReader: ctx.configReader,
130
133
  log: ctx.log,
131
134
  }), async (req, res) => {
132
- await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
135
+ await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
133
136
  span.setAttribute('task.id', trigger.id);
134
137
  span.setAttribute('task.type', 'webhook');
135
138
  const staticActivation = res.locals.activation;
136
139
  const executionCtx = ctx.contextProvider.create(staticActivation, req.body, ctxOptionsFn(req, res));
137
140
  span.setAttribute('execution.id', executionCtx.executionId);
141
+ await sendTaskStartEvent(trigger.id, executionCtx, span);
138
142
  try {
139
143
  subscriber.next(executionCtx);
140
144
  if (isAsync) {
@@ -165,7 +169,7 @@ export const webhookCompiler = {
165
169
  cfgReader: ctx.configReader,
166
170
  log: ctx.log,
167
171
  }), async (req, res) => {
168
- await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
172
+ await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
169
173
  span.setAttribute('task.id', trigger.id);
170
174
  span.setAttribute('task.type', 'webhook');
171
175
  span.setAttribute('user.id', req.params.userId);
@@ -186,6 +190,7 @@ export const webhookCompiler = {
186
190
  }
187
191
  const executionCtx = ctx.contextProvider.create(activation, req.body, ctxOptionsFn(req, res));
188
192
  span.setAttribute('execution.id', executionCtx.executionId);
193
+ await sendTaskStartEvent(trigger.id, executionCtx, span);
189
194
  const errors = [];
190
195
  try {
191
196
  subscriber.next(executionCtx);
@@ -221,7 +226,7 @@ export const webhookCompiler = {
221
226
  cfgReader: ctx.configReader,
222
227
  log: ctx.log,
223
228
  }), async (req, res) => {
224
- await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
229
+ await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
225
230
  span.setAttribute('task.id', trigger.id);
226
231
  span.setAttribute('task.type', 'webhook');
227
232
  span.setAttribute('activation.id', req.params.activationId);
@@ -240,6 +245,7 @@ export const webhookCompiler = {
240
245
  }
241
246
  const activationCtx = ctx.contextProvider.create(activation, req.body, ctxOptionsFn(req, res));
242
247
  span.setAttribute('execution.id', activationCtx.executionId);
248
+ await sendTaskStartEvent(trigger.id, activationCtx, span);
243
249
  try {
244
250
  subscriber.next(activationCtx);
245
251
  if (isAsync) {
@@ -86,6 +86,7 @@ export declare class VanillaInterpreter {
86
86
  private cronServer?;
87
87
  private shutdownServer?;
88
88
  private isShuttingDown;
89
+ private wfRegistration;
89
90
  constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, webhookRouter: Router, cronRouter: Router, cronRegistry: Map<string, string>, cnxFetchFactory: DefaultConnectionFactory, cronProvider: CronProvider, tracer: Tracer, cfgReader: ConfigReader, queueProvider: QueueAPI, otelSDK?: NodeSDK | undefined);
90
91
  static newInstance(options?: VanillaInterpreterOptions): Promise<VanillaInterpreter>;
91
92
  register<O>(workflow: Workflow<O>, options?: VanillaInterpreterOptions): Registration;
@@ -1 +1 @@
1
- {"version":3,"file":"VanillaInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/vanilla/VanillaInterpreter.ts"],"names":[],"mappings":"AAaA,OAAsB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAE7D,OAAO,EAA+B,UAAU,EAAM,YAAY,EAAO,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAarE,OAAO,EAAE,QAAQ,EAAgB,MAAM,uBAAuB,CAAC;AAM/D,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAa,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAA0B,MAAM,yBAAyB,CAAC;AAErF;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACpC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAE9B;;OAEG;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,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IArB7B,OAAO,CAAC,mBAAmB,CAA2B;IACtD,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAC,CAAa;IACpC,OAAO,CAAC,cAAc,CAAS;IAG/B,OAAO,CAAC,cAAc,CAAuB;gBAGxB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,kBAAkB,EAC5B,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,eAAe,EAAE,wBAAwB,EACzC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,YAAY,EACvB,aAAa,EAAE,QAAQ,EACvB,OAAO,CAAC,EAAE,OAAO,YAAA;WASzB,WAAW,CAAC,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAoG9F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB;IA0DhE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA2M5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CASxB"}
@@ -19,7 +19,8 @@ import { catchError, EMPTY, mergeMap, of, tap } from 'rxjs';
19
19
  import { DefaultConnectionFactory } from '../../connection/VanillaConnectionFactory.js';
20
20
  import { VanillaContextProvider } from '../../context/VanillaContext.js';
21
21
  import { VersoriConfigReader } from '../../dsl/http/versori/configloader.js';
22
- import { envVarEnvId, envVarEnvironmentName, envVarLocalRun, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarVersion, } from '../../dsl/http/versori/constants.js';
22
+ import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarVersion, } from '../../internal/constants.js';
23
+ import { Fake, registerWorkflow, signalReady, enabled as supervisorEnabled } from '../../internal/supervisor.js';
23
24
  import { CronAPIClient } from '../../dsl/http/versori/cronapi.js';
24
25
  import { WorkflowImpl } from '../../dsl/Workflow.js';
25
26
  import { IssueImpl } from '../../issues/Issues.js';
@@ -28,8 +29,8 @@ import { SDKKeyValueProvider } from '../../kv/sdk/SDKKeyValueProvider.js';
28
29
  import { ConsoleLogger } from '../../observability/logging/ConsoleLogger.js';
29
30
  import { QueueImpl } from '../durable/Queue.js';
30
31
  import { ObservableCompiler } from './ObservableCompiler.js';
31
- function getKVProvider(runLocal) {
32
- if (runLocal) {
32
+ function getKVProvider() {
33
+ if (supervisorEnabled) {
33
34
  return Promise.resolve(new MemoryKeyValueProvider());
34
35
  }
35
36
  return SDKKeyValueProvider.fromEnv();
@@ -161,6 +162,13 @@ export class VanillaInterpreter {
161
162
  writable: true,
162
163
  value: false
163
164
  });
165
+ // Workflow registration promises only used when supervisor is enabled
166
+ Object.defineProperty(this, "wfRegistration", {
167
+ enumerable: true,
168
+ configurable: true,
169
+ writable: true,
170
+ value: []
171
+ });
164
172
  if (typeof this.log === 'undefined') {
165
173
  throw new Error('VanillaInterpreter should not be instantiated directly. Use VanillaInterpreter.newInstance() instead.');
166
174
  }
@@ -177,7 +185,6 @@ export class VanillaInterpreter {
177
185
  const otelTracesURL = Deno.env.get(envVarOtelTracesURL);
178
186
  let otelSDK;
179
187
  const configReader = VersoriConfigReader.fromEnv(log);
180
- const runLocal = Deno.env.get(envVarLocalRun) === 'true';
181
188
  await waitForReady(log);
182
189
  // Do NOT change these attributes, they are used by the API to filter on
183
190
  const resource = resourceFromAttributes({
@@ -199,6 +206,15 @@ export class VanillaInterpreter {
199
206
  log.info('Starting OpenTelemetry SDK');
200
207
  otelSDK.start();
201
208
  }
209
+ else if (supervisorEnabled) {
210
+ otelSDK = new NodeSDK({
211
+ traceExporter: new Fake(),
212
+ serviceName: serviceName,
213
+ resource: resource,
214
+ });
215
+ log.info('Starting Testing OpenTelemetry SDK');
216
+ otelSDK.start();
217
+ }
202
218
  const tracer = opentelemetry.trace.getTracer(serviceName, version);
203
219
  const queueProvider = await QueueImpl.fromEnv(log);
204
220
  const connectionFactory = new DefaultConnectionFactory();
@@ -206,7 +222,7 @@ export class VanillaInterpreter {
206
222
  if (options.contextProvider) {
207
223
  return new VanillaInterpreter(log, compiler, options.contextProvider, express.Router(), express.Router(), new Map(), connectionFactory, CronAPIClient.fromEnv(), tracer, configReader, queueProvider, otelSDK);
208
224
  }
209
- const kvp = await getKVProvider(runLocal);
225
+ const kvp = await getKVProvider();
210
226
  const organisationId = Deno.env.get(envVarOrgId) || 'development';
211
227
  const environmentId = Deno.env.get(envVarEnvId) || 'development';
212
228
  const ctxProvider = new VanillaContextProvider(log, kvp, organisationId, environmentId, issuesProvider, queueProvider);
@@ -249,9 +265,12 @@ export class VanillaInterpreter {
249
265
  },
250
266
  };
251
267
  this.registeredWorkflows.push(registration);
268
+ if (supervisorEnabled) {
269
+ this.wfRegistration.push(registerWorkflow(workflow));
270
+ }
252
271
  return registration;
253
272
  }
254
- start() {
273
+ async start() {
255
274
  const port = Deno.env.get('PORT') || 3000;
256
275
  const cronPort = Deno.env.get('CRON_PORT') || 3001;
257
276
  const webhookApp = express();
@@ -360,6 +379,7 @@ export class VanillaInterpreter {
360
379
  if (this.cronServer) {
361
380
  this.cronServer.close();
362
381
  }
382
+ this.otelSDK?.shutdown();
363
383
  for (const registration of this.registeredWorkflows) {
364
384
  Deno.removeSignalListener('SIGINT', registration.sigintListener);
365
385
  if (registration.subscription) {
@@ -372,6 +392,10 @@ export class VanillaInterpreter {
372
392
  }
373
393
  };
374
394
  Deno.addSignalListener('SIGINT', this.shutdownServer);
395
+ if (supervisorEnabled) {
396
+ await Promise.all(this.wfRegistration);
397
+ await signalReady();
398
+ }
375
399
  return new Promise((resolve) => {
376
400
  let serversClosed = 0;
377
401
  const totalServers = [this.webhookServer, this.cronServer].filter(Boolean).length;
@@ -11,7 +11,7 @@
11
11
  * use of this software will be governed by the Apache License, Version 2.0.
12
12
  */
13
13
  import { Observable } from 'rxjs';
14
- import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../dsl/http/versori/constants.js';
14
+ import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../internal/constants.js';
15
15
  import { ScheduleTrigger } from '../../../dsl/triggers/ScheduleTrigger.js';
16
16
  import { VanillaActivation } from '../ObservableCompiler.js';
17
17
  function compileSchedule(ctx, trigger, signal) {
@@ -1 +1 @@
1
- {"version":3,"file":"Issues.d.ts","sourceRoot":"","sources":["../../../src/src/issues/Issues.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAWjD,MAAM,MAAM,WAAW,GAAG;IACtB,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC3B,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,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CAAC;IAI1C,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE;QACnC,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KAC3B,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;CAG5B"}
@@ -11,7 +11,8 @@
11
11
  * use of this software will be governed by the Apache License, Version 2.0.
12
12
  */
13
13
  import { createHash } from 'node:crypto';
14
- import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarOrgSlug, envVarProjectId, envVarSDKApiBaseURL, envVarVersion, } from '../dsl/http/versori/constants.js';
14
+ import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarOrgSlug, envVarProjectId, envVarSDKApiBaseURL, envVarVersion, } from '../internal/constants.js';
15
+ import { enabled as supervisorEnabled } from '../internal/supervisor.js';
15
16
  export class IssueImpl {
16
17
  constructor(log) {
17
18
  Object.defineProperty(this, "baseUrl", {
@@ -107,6 +108,10 @@ export class IssueImpl {
107
108
  issue.annotations['environmentId'] = this.environmentId;
108
109
  issue.annotations['organisationId'] = this.organisationId;
109
110
  try {
111
+ if (supervisorEnabled) {
112
+ this.log.info('Issue to be submitted', { issue: issue });
113
+ return Promise.resolve(null);
114
+ }
110
115
  const response = await fetch(`${this.baseUrl}/v1/issues/submit`, {
111
116
  method: 'POST',
112
117
  headers: {
@@ -1 +1 @@
1
- {"version":3,"file":"ConsoleLogger.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/logging/ConsoleLogger.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,GAAG,MAAM,+CAA+C,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAmN/C;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,MAAM;IACxC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAEhB,KAAK,EAAE,QAAQ,CAAC;IAEhB,MAAM,EAAE,MAAM,CAAC,MAAM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BAEpB,KAAK,GAAE,QAAqD,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;IAO9G,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO7D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAC3E,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAsB9D,KAAK,CAAC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,aAAa;IAOvD,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;CAIlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versori/run",
3
- "version": "0.5.9",
3
+ "version": "0.6.0-alpha.1",
4
4
  "description": "Versori Run",
5
5
  "homepage": "https://github.com/versori/versori-run#readme",
6
6
  "repository": {
@@ -27,9 +27,11 @@
27
27
  "@connectrpc/connect": "^2.0.4",
28
28
  "@connectrpc/connect-node": "^2.0.4",
29
29
  "@opentelemetry/api": "^1.9.0",
30
+ "@opentelemetry/core": "^2.1.0",
30
31
  "@opentelemetry/exporter-trace-otlp-proto": "^0.200.0",
31
32
  "@opentelemetry/resources": "^2.0.0",
32
33
  "@opentelemetry/sdk-node": "^0.200.0",
34
+ "@opentelemetry/sdk-trace-node": "^2.0.0",
33
35
  "cors": "^2.8.5",
34
36
  "express": "^4.21.2",
35
37
  "express-xml-bodyparser": "^0.3.0",
@@ -47,7 +47,7 @@ class CredentialHolder {
47
47
  this.refresh();
48
48
  return __classPrivateFieldGet(this, _CredentialHolder_value, "f");
49
49
  }
50
- // if this.refresh returns a rejected promise we are stuck with it until a restart.
50
+ // if this.refresh returns a rejected promise we are stuck with it until a restart.
51
51
  // the try/catch bellow just keeps on trying to refresh the token if this.#value is rejected.
52
52
  //
53
53
  // We might have to change this because if credentials has an issue we might just make that issue worse by pamming more requests
@@ -1,5 +1,9 @@
1
1
  import { FetchLike, OutboundMiddleware } from '../types.js';
2
- import { Connection } from '../../services/platform/mod.js';
2
+ export type FetchConnection = {
3
+ name: string;
4
+ id?: string;
5
+ baseUrl?: string;
6
+ };
3
7
  /**
4
8
  * FetchBuilder is used to build a fetch function which can be composed by multiple middlewares for
5
9
  * modifying the request/response and makes the implementation of {@link ConnectionFetchFactory}
@@ -8,8 +12,11 @@ import { Connection } from '../../services/platform/mod.js';
8
12
  export declare class FetchBuilder {
9
13
  #private;
10
14
  middlewares: OutboundMiddleware[];
11
- constructor(fetch: FetchLike, cnx: Connection);
15
+ constructor(fetch: FetchLike, cnx: FetchConnection);
12
16
  use(fn: OutboundMiddleware): void;
13
17
  build(): FetchLike;
18
+ buildSupervisedFetch(): FetchLike;
19
+ private supervisedFetch;
20
+ private wrapWithTracing;
14
21
  }
15
22
  //# sourceMappingURL=FetchBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FetchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/src/connection/internal/FetchBuilder.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAG5D;;;;GAIG;AACH,qBAAa,YAAY;;IACrB,WAAW,EAAE,kBAAkB,EAAE,CAAC;gBAKtB,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU;IAM7C,GAAG,CAAC,EAAE,EAAE,kBAAkB;IAI1B,KAAK,IAAI,SAAS;CAWrB"}
1
+ {"version":3,"file":"FetchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/src/connection/internal/FetchBuilder.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,YAAY;;IACrB,WAAW,EAAE,kBAAkB,EAAE,CAAC;gBAMtB,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe;IAelD,GAAG,CAAC,EAAE,EAAE,kBAAkB;IAI1B,KAAK,IAAI,SAAS;IAYlB,oBAAoB,IAAI,SAAS;IAOjC,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,eAAe;CAyF1B"}
@@ -11,6 +11,29 @@
11
11
  * As of the Change Date, in accordance with the Business Source License,
12
12
  * use of this software will be governed by the Apache License, Version 2.0.
13
13
  */
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
14
37
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
15
38
  if (kind === "m") throw new TypeError("Private method is not writable");
16
39
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -22,10 +45,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
22
45
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
23
46
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
24
47
  };
25
- var _FetchBuilder_base, _FetchBuilder_cnx;
48
+ var _FetchBuilder_base, _FetchBuilder_cnx, _FetchBuilder_tracer;
26
49
  Object.defineProperty(exports, "__esModule", { value: true });
27
50
  exports.FetchBuilder = void 0;
51
+ const api_1 = __importStar(require("@opentelemetry/api"));
28
52
  const helpers_js_1 = require("../../dsl/http/versori/helpers.js");
53
+ const supervisor_js_1 = require("../../internal/supervisor.js");
29
54
  /**
30
55
  * FetchBuilder is used to build a fetch function which can be composed by multiple middlewares for
31
56
  * modifying the request/response and makes the implementation of {@link ConnectionFetchFactory}
@@ -41,9 +66,18 @@ class FetchBuilder {
41
66
  });
42
67
  _FetchBuilder_base.set(this, void 0);
43
68
  _FetchBuilder_cnx.set(this, void 0);
69
+ _FetchBuilder_tracer.set(this, void 0);
44
70
  __classPrivateFieldSet(this, _FetchBuilder_base, fetch, "f");
45
71
  __classPrivateFieldSet(this, _FetchBuilder_cnx, cnx, "f");
46
- this.middlewares = [changeRequestbaseURLMiddleware(cnx)];
72
+ __classPrivateFieldSet(this, _FetchBuilder_tracer, api_1.default.trace.getTracer('fetch-builder', '1.0.0'), "f");
73
+ const traceMiddleware = this.wrapWithTracing.bind(this);
74
+ if (cnx.baseUrl) {
75
+ this.middlewares = [changeRequestbaseURLMiddleware(cnx), traceMiddleware];
76
+ }
77
+ else {
78
+ this.middlewares = [traceMiddleware];
79
+ }
80
+ this.supervisedFetch = this.supervisedFetch.bind(this);
47
81
  }
48
82
  use(fn) {
49
83
  this.middlewares.push(fn);
@@ -57,9 +91,102 @@ class FetchBuilder {
57
91
  }
58
92
  return fetch;
59
93
  }
94
+ buildSupervisedFetch() {
95
+ return this.supervisedFetch();
96
+ }
97
+ // during testing the user can choose to use a real connection or AI mock.
98
+ // so in supervised mode this function is used instead of the normal build() function.
99
+ // and it will make the decision on using mock or real at runtime at the cost of performance
100
+ supervisedFetch() {
101
+ return (input, init) => {
102
+ let fetch = (input, init) => {
103
+ return (0, supervisor_js_1.mockAPIRequest)(input, __classPrivateFieldGet(this, _FetchBuilder_cnx, "f"), init);
104
+ };
105
+ for (let i = this.middlewares.length - 1; i >= 0; i--) {
106
+ // apply middlewares in reverse order so that the actual middleware executes in the
107
+ // order they were added
108
+ fetch = this.middlewares[i](fetch);
109
+ }
110
+ return fetch(input, init);
111
+ };
112
+ }
113
+ wrapWithTracing(fetch) {
114
+ const connectionId = __classPrivateFieldGet(this, _FetchBuilder_cnx, "f")?.id || '';
115
+ const connectionName = __classPrivateFieldGet(this, _FetchBuilder_cnx, "f")?.name || '';
116
+ return (input, init) => {
117
+ const url = getUrl(input);
118
+ return __classPrivateFieldGet(this, _FetchBuilder_tracer, "f").startActiveSpan(`fetch ${connectionName}/${connectionId}`, async (span) => {
119
+ // Set span attributes
120
+ span.setAttribute('http.url', url);
121
+ span.setAttribute('type', 'fetch');
122
+ span.setAttribute('connection.id', connectionId);
123
+ span.setAttribute('connection.name', connectionName);
124
+ span.setAttribute('isConnected', connectionId !== '');
125
+ try {
126
+ const response = await fetch(input, init);
127
+ if (supervisor_js_1.enabled) {
128
+ if (init?.method) {
129
+ span.setAttribute('http.method', init.method);
130
+ }
131
+ else {
132
+ span.setAttribute('http.method', 'GET');
133
+ }
134
+ // when we are in supervisor mode, we need to store the response body in the span attribute
135
+ // this will be shown the end-user in some UI in the future(the future is now)
136
+ const body = await response.clone().arrayBuffer();
137
+ // if response is text/* or json we store the body as a string, otherwise we store it as a base64 string
138
+ const contentType = response.headers.get('Content-Type');
139
+ span.setAttribute('response.content_type', contentType || '');
140
+ span.setAttribute('request.headers', JSON.stringify(init?.headers || {}));
141
+ if (contentType &&
142
+ (contentType.startsWith('text/') ||
143
+ contentType.startsWith('application/json'))) {
144
+ span.setAttribute('response.body', new TextDecoder().decode(body));
145
+ }
146
+ else {
147
+ span.setAttribute('response.body', btoa(String.fromCharCode(...new Uint8Array(body))));
148
+ }
149
+ }
150
+ // Record response status
151
+ span.setAttribute('http.status_code', response.status);
152
+ if (response.status >= 400) {
153
+ span.setStatus({
154
+ code: api_1.SpanStatusCode.ERROR,
155
+ message: `HTTP ${response.status}`,
156
+ });
157
+ }
158
+ else {
159
+ span.setStatus({ code: api_1.SpanStatusCode.OK });
160
+ }
161
+ return response;
162
+ }
163
+ catch (error) {
164
+ // Record exception
165
+ if (error instanceof Error) {
166
+ span.recordException(error);
167
+ span.setStatus({
168
+ code: api_1.SpanStatusCode.ERROR,
169
+ message: error.message,
170
+ });
171
+ }
172
+ else {
173
+ span.recordException(new Error(String(error)));
174
+ span.setStatus({
175
+ code: api_1.SpanStatusCode.ERROR,
176
+ message: String(error),
177
+ });
178
+ }
179
+ throw error;
180
+ }
181
+ finally {
182
+ span.end();
183
+ }
184
+ });
185
+ };
186
+ }
60
187
  }
61
188
  exports.FetchBuilder = FetchBuilder;
62
- _FetchBuilder_base = new WeakMap(), _FetchBuilder_cnx = new WeakMap();
189
+ _FetchBuilder_base = new WeakMap(), _FetchBuilder_cnx = new WeakMap(), _FetchBuilder_tracer = new WeakMap();
63
190
  function changeBaseUrl(pathname, conn) {
64
191
  const connBaseURL = conn.baseUrl;
65
192
  // if the connection has no baseUrl set, but the pathname is a valid URL, return it as is
@@ -103,3 +230,20 @@ function changeRequestbaseURLMiddleware(conn) {
103
230
  };
104
231
  };
105
232
  }
233
+ function getUrl(input) {
234
+ // Extract URL for span naming
235
+ let url;
236
+ if (typeof input === 'string') {
237
+ url = input;
238
+ }
239
+ else if (input instanceof URL) {
240
+ url = input.toString();
241
+ }
242
+ else if (input instanceof Request) {
243
+ url = input.url;
244
+ }
245
+ else {
246
+ url = 'unknown';
247
+ }
248
+ return url;
249
+ }
@@ -12,6 +12,8 @@ export type OnSuccessFn = (ctx: Context<any>) => void;
12
12
  export type OnErrorFn = (ctx: Context<any>) => void;
13
13
  export type ContextOptions = {
14
14
  workflow?: Workflow;
15
+ /** DSL trigger id (webhook, schedule, etc.) for tracing; distinct from queued {@link Workflow}. */
16
+ workflowId?: string;
15
17
  request?: express.Request;
16
18
  onSuccess?: OnSuccessFn;
17
19
  onError?: OnErrorFn;
@@ -53,6 +55,7 @@ export interface Context<D> {
53
55
  readonly data: D;
54
56
  activation: ActivationInterface;
55
57
  workflow?: Workflow;
58
+ workflowId?: string;
56
59
  /**
57
60
  * Opens a key value store for the given scope, defaulting to ':project:' if not provided.
58
61
  * @param scope The scope of the key value store to open, defaulting to ':project:' if not provided.
@@ -108,8 +111,10 @@ export declare class ContextImpl<D, Index = void> implements Context<D> {
108
111
  constructor(log: Logger, kvp: KeyValueProvider, creds: CredentialsProvider, executionId: string, startTime: Date, data: D, activation: ActivationImpl, issues: IssueAPI, queue?: QueueAPI, options?: ContextOptions);
109
112
  get activation(): ActivationImpl;
110
113
  get workflow(): Workflow | undefined;
114
+ get workflowId(): string | undefined;
111
115
  setIndex(idx: number): ContextImpl<D, number>;
112
116
  withData<D2>(data: D2, optionsPatch?: Partial<ContextOptions>): ContextImpl<D2, Index>;
117
+ withLogger(log: Logger): ContextImpl<D, Index>;
113
118
  openKv(scope?: KeyValueScope): KeyValue;
114
119
  request(): express.Request | undefined;
115
120
  workflowClient(): WorkflowInterface;