@arcote.tech/arc-otel 0.7.6 → 0.7.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.
@@ -1,4 +1,5 @@
1
1
  import { ArcTelemetry, type TelemetryConfig } from "./telemetry";
2
+ export { wrapDbAdapter } from "./wrap-db-adapter";
2
3
  export interface ServerInitResult {
3
4
  telemetry: ArcTelemetry;
4
5
  /** Flush + shut down all exporters. Call on SIGTERM/SIGINT. Resolves when done. */
@@ -1 +1 @@
1
- {"version":3,"file":"init-server.d.ts","sourceRoot":"","sources":["../src/init-server.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAUjE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,YAAY,CAAC;IACxB,mFAAmF;IACnF,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,gBAAgB,CA2F7E"}
1
+ {"version":3,"file":"init-server.d.ts","sourceRoot":"","sources":["../src/init-server.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAKjE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAUlD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,YAAY,CAAC;IACxB,mFAAmF;IACnF,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,gBAAgB,CA8F7E"}
@@ -267,10 +267,76 @@ function noopSpan() {
267
267
  });
268
268
  }
269
269
 
270
+ // src/wrap-db-adapter.ts
271
+ function wrapDbAdapter(adapter, telemetry, dbSystem) {
272
+ if (!telemetry || !telemetry.active)
273
+ return adapter;
274
+ const wrapRead = (tx) => ({
275
+ find: async (store, options) => telemetry.startSpan(`db.find ${store}`, async (span) => {
276
+ const start = Date.now();
277
+ try {
278
+ const rows = await tx.find(store, options);
279
+ span.setAttribute("db.response.row_count", rows.length);
280
+ return rows;
281
+ } finally {
282
+ telemetry.measureSince("arc.db.find_ms", start, {
283
+ "db.system": dbSystem,
284
+ "db.collection.name": store
285
+ });
286
+ }
287
+ }, {
288
+ kind: 3,
289
+ attributes: {
290
+ "db.system": dbSystem,
291
+ "db.operation.name": "find",
292
+ "db.collection.name": store
293
+ }
294
+ })
295
+ });
296
+ const wrapReadWrite = (tx) => ({
297
+ ...wrapRead(tx),
298
+ set: async (store, data) => telemetry.startSpan(`db.set ${store}`, () => tx.set(store, data), {
299
+ kind: 3,
300
+ attributes: {
301
+ "db.system": dbSystem,
302
+ "db.operation.name": "set",
303
+ "db.collection.name": store
304
+ }
305
+ }),
306
+ remove: async (store, id) => telemetry.startSpan(`db.remove ${store}`, () => tx.remove(store, id), {
307
+ kind: 3,
308
+ attributes: {
309
+ "db.system": dbSystem,
310
+ "db.operation.name": "remove",
311
+ "db.collection.name": store
312
+ }
313
+ }),
314
+ commit: async () => telemetry.startSpan("db.commit", () => tx.commit(), {
315
+ kind: 3,
316
+ attributes: {
317
+ "db.system": dbSystem,
318
+ "db.operation.name": "commit"
319
+ }
320
+ })
321
+ });
322
+ return new Proxy(adapter, {
323
+ get(target, prop) {
324
+ const orig = target[prop];
325
+ if (prop === "readTransaction") {
326
+ return (...args) => wrapRead(orig.apply(target, args));
327
+ }
328
+ if (prop === "readWriteTransaction") {
329
+ return (...args) => wrapReadWrite(orig.apply(target, args));
330
+ }
331
+ return typeof orig === "function" ? orig.bind(target) : orig;
332
+ }
333
+ });
334
+ }
335
+
270
336
  // src/init-server.ts
271
337
  function initServerTelemetry(config) {
272
338
  const telemetry = new ArcTelemetry({ ...config, environment: "server" });
273
- if (!telemetry.active && !config.enabled) {
339
+ if (!telemetry.config.enabled) {
274
340
  return { telemetry, shutdown: async () => {} };
275
341
  }
276
342
  const endpoint = config.endpoint ?? process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://localhost:4318";
@@ -335,5 +401,6 @@ function initServerTelemetry(config) {
335
401
  return { telemetry, shutdown };
336
402
  }
337
403
  export {
404
+ wrapDbAdapter,
338
405
  initServerTelemetry
339
406
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-otel",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
4
4
  "description": "OpenTelemetry instrumentation primitives for the Arc framework — server + browser SDK init, span helpers, PII-safe attribute sanitization, W3C Trace Context propagation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,7 +43,7 @@
43
43
  "@opentelemetry/semantic-conventions": "^1.27.0"
44
44
  },
45
45
  "peerDependencies": {
46
- "@arcote.tech/arc": "^0.7.6"
46
+ "@arcote.tech/arc": "^0.7.8"
47
47
  },
48
48
  "devDependencies": {
49
49
  "typescript": "^5.0.0"