yedra 0.18.3 → 0.19.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.
@@ -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
+ */
@@ -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, SpanKind, 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,19 @@ 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
- this.handle(req, res);
252
- res.on('close', () => {
253
- counter.decrement();
254
- });
252
+ const extractedContext = propagation.extract(context.active(), req.headers);
253
+ context.with(extractedContext, () => trace.getTracer('yedra').startActiveSpan('incoming_request', {
254
+ kind: SpanKind.SERVER,
255
+ }, (span) => {
256
+ this.handle(req, res);
257
+ res.on('close', () => {
258
+ span.setAttribute('http.method', req.method ?? 'UNKNOWN');
259
+ span.setAttribute('http.url', req.url ?? 'UNKNOWN');
260
+ span.setAttribute('http.status_code', res.statusCode);
261
+ span.end();
262
+ counter.decrement();
263
+ });
264
+ }));
255
265
  });
256
266
  const wss = new WebSocketServer({ server });
257
267
  wss.on('connection', async (ws, req) => {
@@ -455,3 +465,9 @@ export class Yedra {
455
465
  return app.listen(port, options);
456
466
  }
457
467
  }
468
+ /**
469
+ * TODO: how do we add OpenTelemetry instrumentation here?
470
+ * We need two things:
471
+ * 1. Start active span for each incoming request, and end after response is sent.
472
+ * 2. Extract context from incoming requests to propagate traces.
473
+ */
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "yedra",
3
- "version": "0.18.3",
3
+ "version": "0.19.1",
4
4
  "repository": "github:0codekit/yedra",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {
7
- "@biomejs/biome": "^2.3.6",
8
- "@types/bun": "^1.3.2",
9
- "@types/node": "^24.10.1",
7
+ "@biomejs/biome": "^2.3.8",
8
+ "@types/bun": "^1.3.4",
9
+ "@types/node": "^25.0.1",
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"