@monocle.sh/adonisjs-agent 1.0.0-beta.14 → 1.0.0-beta.15
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/helpers.d.mts +1 -1
- package/dist/helpers.mjs +5 -11
- package/package.json +1 -1
package/dist/helpers.d.mts
CHANGED
|
@@ -17,7 +17,7 @@ declare function handleError(span: Span, error: Error): Promise<never>;
|
|
|
17
17
|
* the error location).
|
|
18
18
|
*
|
|
19
19
|
* Preserves sync/async semantics: if the callback is synchronous, the return
|
|
20
|
-
* type is `T`. If the callback returns a Promise
|
|
20
|
+
* type is `T`. If the callback returns a Promise, the return type
|
|
21
21
|
* is async-compatible.
|
|
22
22
|
*
|
|
23
23
|
* Automatically handles:
|
package/dist/helpers.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import { trace } from "@opentelemetry/api";
|
|
|
3
3
|
import { extractTraceContext, getCurrentSpan, injectTraceContext, otelLoggingPreset, recordEvent, setAttributes } from "@adonisjs/otel/helpers";
|
|
4
4
|
|
|
5
5
|
//#region src/helpers.ts
|
|
6
|
-
function
|
|
6
|
+
function isNativePromise(value) {
|
|
7
7
|
if (!value) return false;
|
|
8
8
|
if (typeof value !== "object" && typeof value !== "function") return false;
|
|
9
|
-
return
|
|
9
|
+
return value instanceof Promise || Object.prototype.toString.call(value) === "[object Promise]";
|
|
10
10
|
}
|
|
11
11
|
async function reportErrorAndEndSpan(span, error, endTime) {
|
|
12
12
|
const reporter = new ExceptionReporter();
|
|
@@ -16,13 +16,7 @@ async function reportErrorAndEndSpan(span, error, endTime) {
|
|
|
16
16
|
error,
|
|
17
17
|
shouldReport: true
|
|
18
18
|
});
|
|
19
|
-
} catch {
|
|
20
|
-
reporter.reportSync({
|
|
21
|
-
span,
|
|
22
|
-
error,
|
|
23
|
-
shouldReport: true
|
|
24
|
-
});
|
|
25
|
-
} finally {
|
|
19
|
+
} catch {} finally {
|
|
26
20
|
span.end(endTime);
|
|
27
21
|
}
|
|
28
22
|
}
|
|
@@ -44,7 +38,7 @@ async function handleError(span, error) {
|
|
|
44
38
|
* the error location).
|
|
45
39
|
*
|
|
46
40
|
* Preserves sync/async semantics: if the callback is synchronous, the return
|
|
47
|
-
* type is `T`. If the callback returns a Promise
|
|
41
|
+
* type is `T`. If the callback returns a Promise, the return type
|
|
48
42
|
* is async-compatible.
|
|
49
43
|
*
|
|
50
44
|
* Automatically handles:
|
|
@@ -75,7 +69,7 @@ function record(name, callback) {
|
|
|
75
69
|
return trace.getTracer("@monocle.sh/agent").startActiveSpan(name, (span) => {
|
|
76
70
|
try {
|
|
77
71
|
const result = callback(span);
|
|
78
|
-
if (
|
|
72
|
+
if (isNativePromise(result)) return Promise.resolve(result).then((value) => {
|
|
79
73
|
span.end();
|
|
80
74
|
return value;
|
|
81
75
|
}).catch((error) => handleError(span, error));
|