@devopsplaybook.io/otel-utils-fastify 1.0.6 → 1.0.8
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.
|
@@ -29,8 +29,10 @@ function StandardTracerFastifyRegisterHooks(fastify, standardTracer, standardLog
|
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
fastify.addHook("onResponse", async (req, reply) => {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const span = OTelRequestSpan(req);
|
|
33
|
+
if (!span) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
34
36
|
if (reply.statusCode > 299) {
|
|
35
37
|
span.status.code = api_1.SpanStatusCode.ERROR;
|
|
36
38
|
}
|
|
@@ -41,11 +43,13 @@ function StandardTracerFastifyRegisterHooks(fastify, standardTracer, standardLog
|
|
|
41
43
|
span.end();
|
|
42
44
|
});
|
|
43
45
|
fastify.addHook("onError", async (req, reply, error) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const span = OTelRequestSpan(req);
|
|
47
|
+
if (!span) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
46
50
|
span.status.code = api_1.SpanStatusCode.ERROR;
|
|
47
51
|
span.recordException(error);
|
|
48
|
-
logger.error(error);
|
|
52
|
+
logger.error(error.message, error, span);
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
55
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devopsplaybook.io/otel-utils-fastify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Utility to simplify integration with Open Telemetry for Fastify API Server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Open",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"fastify": "^5.6.0",
|
|
23
|
-
"@devopsplaybook.io/otel-utils": "^1.0.
|
|
23
|
+
"@devopsplaybook.io/otel-utils": "^1.0.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@eslint/js": "^9.35.0",
|
|
27
27
|
"@types/node": "^24.3.1",
|
|
28
28
|
"@types/sqlite3": "^5.1.0",
|
|
29
29
|
"ts-node": "^10.9.2",
|
|
30
|
-
"typescript-eslint": "^8.
|
|
30
|
+
"typescript-eslint": "^8.43.0",
|
|
31
31
|
"typescript": "^5.9.2"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
@@ -52,8 +52,10 @@ export function StandardTracerFastifyRegisterHooks(
|
|
|
52
52
|
fastify.addHook(
|
|
53
53
|
"onResponse",
|
|
54
54
|
async (req: FastifyRequest, reply: FastifyReply) => {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const span = OTelRequestSpan(req);
|
|
56
|
+
if (!span) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
57
59
|
if (reply.statusCode > 299) {
|
|
58
60
|
span.status.code = SpanStatusCode.ERROR;
|
|
59
61
|
} else {
|
|
@@ -67,11 +69,13 @@ export function StandardTracerFastifyRegisterHooks(
|
|
|
67
69
|
fastify.addHook(
|
|
68
70
|
"onError",
|
|
69
71
|
async (req: FastifyRequest, reply: FastifyReply, error) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const span = OTelRequestSpan(req);
|
|
73
|
+
if (!span) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
72
76
|
span.status.code = SpanStatusCode.ERROR;
|
|
73
77
|
span.recordException(error);
|
|
74
|
-
logger.error(error);
|
|
78
|
+
logger.error(error.message, error, span);
|
|
75
79
|
}
|
|
76
80
|
);
|
|
77
81
|
}
|