@develit-io/backend-sdk 12.7.0 → 12.7.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.
- package/dist/sentry.mjs +44 -1
- package/package.json +1 -1
package/dist/sentry.mjs
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/cloudflare';
|
|
2
2
|
import { i as isInternalError, U as UNKNOWN_ERROR_CODE, s as setErrorReporter } from './shared/backend-sdk.e9CWR7-E.mjs';
|
|
3
3
|
|
|
4
|
+
const isNonRetryableError = (error) => error instanceof Error && error.name === "NonRetryableError";
|
|
5
|
+
const isFinalAttempt = ({ attempt, config }) => typeof config?.retries?.limit !== "number" || attempt > config.retries.limit;
|
|
6
|
+
const captureNonRetryable = (callback) => async (ctx) => {
|
|
7
|
+
try {
|
|
8
|
+
return await callback(ctx);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (isNonRetryableError(error) && !isFinalAttempt(ctx)) {
|
|
11
|
+
Sentry.captureException(error, {
|
|
12
|
+
mechanism: { handled: true, type: "auto.faas.cloudflare.workflow" }
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const reportNonRetryableStepErrors = (step) => new Proxy(step, {
|
|
19
|
+
get(target, prop, receiver) {
|
|
20
|
+
if (prop !== "do") return Reflect.get(target, prop, receiver);
|
|
21
|
+
return (name, configOrCallback, callbackOrRollback, ...rest) => typeof configOrCallback === "function" ? Reflect.apply(target.do, target, [
|
|
22
|
+
name,
|
|
23
|
+
captureNonRetryable(configOrCallback),
|
|
24
|
+
callbackOrRollback,
|
|
25
|
+
...rest
|
|
26
|
+
]) : Reflect.apply(target.do, target, [
|
|
27
|
+
name,
|
|
28
|
+
configOrCallback,
|
|
29
|
+
callbackOrRollback && captureNonRetryable(callbackOrRollback),
|
|
30
|
+
...rest
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
4
35
|
const sentryOptions = (env) => ({
|
|
5
36
|
dsn: env.SENTRY_DSN,
|
|
6
37
|
environment: env.ENVIRONMENT,
|
|
@@ -44,6 +75,18 @@ const instrumentDurableObject = (DurableObject) => {
|
|
|
44
75
|
setErrorReporter(reportServiceErrorToSentry);
|
|
45
76
|
return Sentry.instrumentDurableObjectWithSentry(sentryOptions, DurableObject);
|
|
46
77
|
};
|
|
47
|
-
const
|
|
78
|
+
const withNonRetryableStepReporting = (Workflow) => {
|
|
79
|
+
const Base = Workflow;
|
|
80
|
+
class NonRetryableStepReportingWorkflow extends Base {
|
|
81
|
+
run(...[event, step]) {
|
|
82
|
+
return super.run(event, reportNonRetryableStepErrors(step));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return NonRetryableStepReportingWorkflow;
|
|
86
|
+
};
|
|
87
|
+
const instrumentWorkflow = (Workflow) => Sentry.instrumentWorkflowWithSentry(
|
|
88
|
+
sentryOptions,
|
|
89
|
+
withNonRetryableStepReporting(Workflow)
|
|
90
|
+
);
|
|
48
91
|
|
|
49
92
|
export { instrumentDurableObject, instrumentService, instrumentWorkflow, reportServiceErrorToSentry, sentryOptions };
|