yedra 0.18.2 → 0.19.0
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/routing/app.d.ts +6 -0
- package/dist/routing/app.js +18 -4
- package/dist/routing/websocket.d.ts +1 -1
- package/package.json +5 -4
package/dist/routing/app.d.ts
CHANGED
|
@@ -145,3 +145,9 @@ export declare class Yedra {
|
|
|
145
145
|
}): Promise<Context>;
|
|
146
146
|
}
|
|
147
147
|
export {};
|
|
148
|
+
/**
|
|
149
|
+
* TODO: how do we add OpenTelemetry instrumentation here?
|
|
150
|
+
* We need two things:
|
|
151
|
+
* 1. Start active span for each incoming request, and end after response is sent.
|
|
152
|
+
* 2. Extract context from incoming requests to propagate traces.
|
|
153
|
+
*/
|
package/dist/routing/app.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createServer as createHttpsServer } from 'node:https';
|
|
|
4
4
|
import { extname, join } from 'node:path';
|
|
5
5
|
import { URL } from 'node:url';
|
|
6
6
|
import { isUint8Array } from 'node:util/types';
|
|
7
|
+
import { context, propagation, trace } from '@opentelemetry/api';
|
|
7
8
|
import mime from 'mime';
|
|
8
9
|
import { WebSocketServer } from 'ws';
|
|
9
10
|
import { Counter } from '../util/counter.js';
|
|
@@ -248,10 +249,17 @@ yedra_request_duration_sum{method="${method}",status="${status}"} ${data?.durati
|
|
|
248
249
|
const counter = new Counter();
|
|
249
250
|
server.on('request', (req, res) => {
|
|
250
251
|
counter.increment();
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
const extractedContext = propagation.extract(context.active(), req.headers);
|
|
253
|
+
context.with(extractedContext, () => trace.getTracer('yedra').startActiveSpan('incoming_request', (span) => {
|
|
254
|
+
this.handle(req, res);
|
|
255
|
+
res.on('close', () => {
|
|
256
|
+
span.setAttribute('http.method', req.method ?? 'UNKNOWN');
|
|
257
|
+
span.setAttribute('http.url', req.url ?? 'UNKNOWN');
|
|
258
|
+
span.setAttribute('http.status', res.statusCode);
|
|
259
|
+
span.end();
|
|
260
|
+
counter.decrement();
|
|
261
|
+
});
|
|
262
|
+
}));
|
|
255
263
|
});
|
|
256
264
|
const wss = new WebSocketServer({ server });
|
|
257
265
|
wss.on('connection', async (ws, req) => {
|
|
@@ -455,3 +463,9 @@ export class Yedra {
|
|
|
455
463
|
return app.listen(port, options);
|
|
456
464
|
}
|
|
457
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* TODO: how do we add OpenTelemetry instrumentation here?
|
|
468
|
+
* We need two things:
|
|
469
|
+
* 1. Start active span for each incoming request, and end after response is sent.
|
|
470
|
+
* 2. Extract context from incoming requests to propagate traces.
|
|
471
|
+
*/
|
|
@@ -17,7 +17,7 @@ declare class YedraWebSocket {
|
|
|
17
17
|
* Send binary data over the WebSocket connection;
|
|
18
18
|
* @param message - The message that will be sent.
|
|
19
19
|
*/
|
|
20
|
-
send(message:
|
|
20
|
+
send(message: Uint8Array<ArrayBufferLike> | string): void;
|
|
21
21
|
/**
|
|
22
22
|
* Closes the WebSocket.
|
|
23
23
|
* @param code - The close code. Must be one of:
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yedra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"repository": "github:0codekit/yedra",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@biomejs/biome": "^2.3.
|
|
8
|
-
"@types/bun": "^1.3.
|
|
9
|
-
"@types/node": "^24.10.
|
|
7
|
+
"@biomejs/biome": "^2.3.8",
|
|
8
|
+
"@types/bun": "^1.3.4",
|
|
9
|
+
"@types/node": "^24.10.2",
|
|
10
10
|
"@types/uuid": "^11.0.0",
|
|
11
11
|
"@types/ws": "^8.18.1",
|
|
12
12
|
"typescript": "^5.9.3"
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"type": "module",
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@opentelemetry/api": "^1.9.0",
|
|
37
38
|
"mime": "^4.1.0",
|
|
38
39
|
"uuid": "^13.0.0",
|
|
39
40
|
"ws": "^8.18.3"
|