autotel-adapters 2.1.1 → 3.0.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.
Files changed (58) hide show
  1. package/README.md +26 -0
  2. package/dist/cloudflare.cjs +3 -9
  3. package/dist/cloudflare.d.cts +1 -1
  4. package/dist/cloudflare.d.ts +1 -1
  5. package/dist/cloudflare.js +3 -9
  6. package/dist/core.cjs +4 -2
  7. package/dist/core.d.cts +1 -1
  8. package/dist/core.d.ts +1 -1
  9. package/dist/core.js +4 -2
  10. package/dist/elysia.cjs +4 -2
  11. package/dist/elysia.d.cts +3 -1
  12. package/dist/elysia.d.ts +3 -1
  13. package/dist/elysia.js +4 -2
  14. package/dist/express.cjs +16 -4
  15. package/dist/express.d.cts +1 -1
  16. package/dist/express.d.ts +1 -1
  17. package/dist/express.js +16 -4
  18. package/dist/fastify.cjs +6 -4
  19. package/dist/fastify.d.cts +1 -1
  20. package/dist/fastify.d.ts +1 -1
  21. package/dist/fastify.js +6 -4
  22. package/dist/hono.cjs +42 -3
  23. package/dist/hono.d.cts +1 -1
  24. package/dist/hono.d.ts +1 -1
  25. package/dist/hono.js +42 -3
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.d.cts +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/{integration-CQMpu5E4.d.ts → integration-B6OoKr7O.d.ts} +23 -3
  31. package/dist/{integration-D9g_qI5y.d.cts → integration-CwqWnPKn.d.cts} +23 -3
  32. package/dist/{integration-jKj-jgtX.js → integration-D_ABolGu.js} +64 -16
  33. package/dist/{integration-rv0DU916.cjs → integration-Danzss1R.cjs} +74 -14
  34. package/dist/nestjs.cjs +13 -15
  35. package/dist/nestjs.d.cts +9 -1
  36. package/dist/nestjs.d.ts +9 -1
  37. package/dist/nestjs.js +13 -15
  38. package/dist/next.cjs +3 -9
  39. package/dist/next.d.cts +1 -1
  40. package/dist/next.d.ts +1 -1
  41. package/dist/next.js +3 -9
  42. package/dist/nitro.cjs +9 -3
  43. package/dist/nitro.d.cts +9 -2
  44. package/dist/nitro.d.ts +9 -2
  45. package/dist/nitro.js +9 -3
  46. package/dist/sveltekit.cjs +4 -2
  47. package/dist/sveltekit.d.cts +1 -1
  48. package/dist/sveltekit.d.ts +1 -1
  49. package/dist/sveltekit.js +4 -2
  50. package/dist/tanstack.cjs +2 -1
  51. package/dist/tanstack.d.cts +2 -0
  52. package/dist/tanstack.d.ts +2 -0
  53. package/dist/tanstack.js +2 -1
  54. package/dist/toolkit/index.cjs +1 -1
  55. package/dist/toolkit/index.d.cts +1 -1
  56. package/dist/toolkit/index.d.ts +1 -1
  57. package/dist/toolkit/index.js +1 -1
  58. package/package.json +2 -2
package/README.md CHANGED
@@ -27,6 +27,27 @@ Use `defineFrameworkIntegration()` from `autotel-adapters/toolkit` to wire a new
27
27
 
28
28
  Toolkit options include route `include` / `exclude`, per-route `service`, serverless `waitUntil`, streaming `finishResponse`, and request-level `keep` callbacks.
29
29
 
30
+ The request handle also exposes `markOutcome({ status, error })`, which records the status code and error on the span without emitting the snapshot, and `finishResponse(response, { error })` for an error the framework caught on the way to the response.
31
+
32
+ ## Span names and attributes
33
+
34
+ Request spans follow the OpenTelemetry HTTP conventions:
35
+
36
+ - `http.route` holds the matched route template (`/users/:id`), and the span is named `{METHOD} {route}`, or `{METHOD}` when no route matched.
37
+ - `url.path` holds the raw request path.
38
+ - A 5xx response ends the span with status ERROR. A 4xx leaves the status unset.
39
+
40
+ Next.js and Cloudflare Workers have no matched route to read, so they set only `url.path`. Pass `http.route` through `enrichRequest` and a name through `spanName`:
41
+
42
+ ```ts
43
+ export const GET = withAutotel(handler, {
44
+ spanName: 'GET /api/orders/[id]',
45
+ enrichRequest: () => ({ 'http.route': '/api/orders/[id]' }),
46
+ });
47
+ ```
48
+
49
+ Hono reads the last matched route after routing and records the error it caught on `c.error` for a 5xx. NestJS records `Controller.handler` as `code.function.name`.
50
+
30
51
  ## When to use `withAutotel` vs `useLogger` alone
31
52
 
32
53
  Each adapter exports two patterns. Choose based on whether you already have
@@ -118,6 +139,11 @@ workspace package's dependency in a monorepo. `withAutotelConfig` fails the
118
139
  build instead. `autotel-adapters/next-config` has no runtime dependency, so
119
140
  `next.config.ts` can import it.
120
141
 
142
+ Hono inside Next follows the same rule: keep `autotel-adapters` and `hono` on
143
+ the same side of that line. Bundle both with the app, or list both in
144
+ `serverExternalPackages`. When they resolve different copies, the Hono adapter
145
+ names the route through the request instead and warns once.
146
+
121
147
  ## Nitro
122
148
 
123
149
  ```ts
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_integration = require("./integration-rv0DU916.cjs");
2
+ const require_integration = require("./integration-Danzss1R.cjs");
3
3
  const require_core = require("./core.cjs");
4
4
  let autotel = require("autotel");
5
5
 
@@ -7,17 +7,11 @@ let autotel = require("autotel");
7
7
  const requestLoggers = /* @__PURE__ */ new WeakMap();
8
8
  function enrichFromRequest(request) {
9
9
  if (!request) return void 0;
10
- let route = "/";
11
- if (request.url) try {
12
- route = new URL(request.url).pathname;
13
- } catch {
14
- route = request.url;
15
- }
16
10
  const requestId = require_core.getHeader(request.headers, "x-request-id") ?? require_core.getHeader(request.headers, "cf-ray");
17
11
  return {
18
12
  "http.request.method": request.method,
19
13
  "url.full": request.url,
20
- "http.route": route,
14
+ "url.path": resolvePath(request),
21
15
  "http.request.id": requestId,
22
16
  "cloudflare.country": request.cf?.country,
23
17
  "cloudflare.colo": request.cf?.colo,
@@ -63,7 +57,7 @@ function createIntegration() {
63
57
  const integration = createIntegration();
64
58
  function resolveSpanName(request, env, options) {
65
59
  if (typeof options?.spanName === "function") return options.spanName(request, env);
66
- return options?.spanName ?? `cloudflare.${request.method ?? "request"}`;
60
+ return options?.spanName;
67
61
  }
68
62
  function withAutotelFetch(handler, options) {
69
63
  return async (request, env, executionContext) => {
@@ -1,4 +1,4 @@
1
- import { n as FrameworkHandlerOptions } from "./integration-D9g_qI5y.cjs";
1
+ import { n as FrameworkHandlerOptions } from "./integration-CwqWnPKn.cjs";
2
2
  import "./core.cjs";
3
3
  import { RequestLogger, RequestLoggerOptions, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/cloudflare.d.ts
@@ -1,4 +1,4 @@
1
- import { n as FrameworkHandlerOptions } from "./integration-CQMpu5E4.js";
1
+ import { n as FrameworkHandlerOptions } from "./integration-B6OoKr7O.js";
2
2
  import "./core.js";
3
3
  import { RequestLogger, RequestLoggerOptions, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/cloudflare.d.ts
@@ -1,4 +1,4 @@
1
- import { a as runWithIntegratedHandle, i as defineFrameworkIntegration, n as buildTracedOptions, t as applyLoggerEnrichment } from "./integration-jKj-jgtX.js";
1
+ import { a as defineFrameworkIntegration, n as buildTracedOptions, o as runWithIntegratedHandle, t as applyLoggerEnrichment } from "./integration-D_ABolGu.js";
2
2
  import { createUseLogger, getHeader } from "./core.js";
3
3
  import { createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
 
@@ -6,17 +6,11 @@ import { createDrainPipeline, createStructuredError, parseError } from "autotel"
6
6
  const requestLoggers = /* @__PURE__ */ new WeakMap();
7
7
  function enrichFromRequest(request) {
8
8
  if (!request) return void 0;
9
- let route = "/";
10
- if (request.url) try {
11
- route = new URL(request.url).pathname;
12
- } catch {
13
- route = request.url;
14
- }
15
9
  const requestId = getHeader(request.headers, "x-request-id") ?? getHeader(request.headers, "cf-ray");
16
10
  return {
17
11
  "http.request.method": request.method,
18
12
  "url.full": request.url,
19
- "http.route": route,
13
+ "url.path": resolvePath(request),
20
14
  "http.request.id": requestId,
21
15
  "cloudflare.country": request.cf?.country,
22
16
  "cloudflare.colo": request.cf?.colo,
@@ -62,7 +56,7 @@ function createIntegration() {
62
56
  const integration = createIntegration();
63
57
  function resolveSpanName(request, env, options) {
64
58
  if (typeof options?.spanName === "function") return options.spanName(request, env);
65
- return options?.spanName ?? `cloudflare.${request.method ?? "request"}`;
59
+ return options?.spanName;
66
60
  }
67
61
  function withAutotelFetch(handler, options) {
68
62
  return async (request, env, executionContext) => {
package/dist/core.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_integration = require("./integration-rv0DU916.cjs");
2
+ const require_integration = require("./integration-Danzss1R.cjs");
3
3
  let autotel = require("autotel");
4
4
  let autotel_edge = require("autotel-edge");
5
5
 
@@ -38,7 +38,9 @@ function createRequestRunner(storage) {
38
38
  log.error(error instanceof Error ? error : new Error(String(error)));
39
39
  throw error;
40
40
  } finally {
41
- if (options?.autoEmit !== false) log.emitNow(options?.finalize?.());
41
+ const finalized = options?.finalize?.();
42
+ require_integration.markServerError(ctx, finalized?.["http.response.status_code"]);
43
+ if (options?.autoEmit !== false) log.emitNow(finalized);
42
44
  }
43
45
  });
44
46
  };
package/dist/core.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-D9g_qI5y.cjs";
1
+ import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-CwqWnPKn.cjs";
2
2
  import { DrainPipelineOptions, ParsedError, PipelineDrainFn, RequestLogSnapshot, RequestLogger, RequestLoggerOptions, StructuredError, StructuredErrorInput } from "autotel";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  //#region src/core.d.ts
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-CQMpu5E4.js";
1
+ import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-B6OoKr7O.js";
2
2
  import { DrainPipelineOptions, ParsedError, PipelineDrainFn, RequestLogSnapshot, RequestLogger, RequestLoggerOptions, StructuredError, StructuredErrorInput } from "autotel";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  //#region src/core.d.ts
package/dist/core.js CHANGED
@@ -1,4 +1,4 @@
1
- import { d as mergeRequestLoggerOptions, f as shouldInstrumentPath, o as toRouteAdapterOptions } from "./integration-jKj-jgtX.js";
1
+ import { d as markServerError, m as shouldInstrumentPath, p as mergeRequestLoggerOptions, s as toRouteAdapterOptions } from "./integration-D_ABolGu.js";
2
2
  import { getRequestLogger, trace } from "autotel";
3
3
 
4
4
  //#region src/core.ts
@@ -36,7 +36,9 @@ function createRequestRunner(storage) {
36
36
  log.error(error instanceof Error ? error : new Error(String(error)));
37
37
  throw error;
38
38
  } finally {
39
- if (options?.autoEmit !== false) log.emitNow(options?.finalize?.());
39
+ const finalized = options?.finalize?.();
40
+ markServerError(ctx, finalized?.["http.response.status_code"]);
41
+ if (options?.autoEmit !== false) log.emitNow(finalized);
40
42
  }
41
43
  });
42
44
  };
package/dist/elysia.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_integration = require("./integration-rv0DU916.cjs");
2
+ const require_integration = require("./integration-Danzss1R.cjs");
3
3
  const require_toolkit_storage = require("./toolkit/storage.cjs");
4
4
  const require_core = require("./core.cjs");
5
5
  let autotel = require("autotel");
@@ -12,7 +12,8 @@ function enrichFromContext(ctx) {
12
12
  return {
13
13
  "http.request.method": ctx.request.method,
14
14
  "url.full": ctx.request.url,
15
- "http.route": ctx.path,
15
+ "url.path": ctx.path,
16
+ "http.route": ctx.route,
16
17
  "http.request.id": requestId
17
18
  };
18
19
  }
@@ -22,6 +23,7 @@ const integration = require_integration.defineFrameworkIntegration({
22
23
  extractRequest: (ctx) => ({
23
24
  method: ctx.request.method,
24
25
  path: ctx.path,
26
+ route: ctx.route,
25
27
  headers: ctx.request.headers,
26
28
  requestId: require_core.getHeader(ctx.request.headers, "x-request-id")
27
29
  }),
package/dist/elysia.d.cts CHANGED
@@ -1,10 +1,12 @@
1
- import { n as FrameworkHandlerOptions } from "./integration-D9g_qI5y.cjs";
1
+ import { n as FrameworkHandlerOptions } from "./integration-CwqWnPKn.cjs";
2
2
  import "./core.cjs";
3
3
  import { RequestLogger, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/elysia.d.ts
5
5
  export interface ElysiaContextLike {
6
6
  request: Request;
7
7
  path: string;
8
+ /** Matched route template (`/users/:id`). */
9
+ route?: string;
8
10
  }
9
11
  export interface ElysiaWithAutotelOptions extends FrameworkHandlerOptions {
10
12
  enrichRequest?: (ctx: ElysiaContextLike) => Record<string, unknown> | undefined;
package/dist/elysia.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { n as FrameworkHandlerOptions } from "./integration-CQMpu5E4.js";
1
+ import { n as FrameworkHandlerOptions } from "./integration-B6OoKr7O.js";
2
2
  import "./core.js";
3
3
  import { RequestLogger, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/elysia.d.ts
5
5
  export interface ElysiaContextLike {
6
6
  request: Request;
7
7
  path: string;
8
+ /** Matched route template (`/users/:id`). */
9
+ route?: string;
8
10
  }
9
11
  export interface ElysiaWithAutotelOptions extends FrameworkHandlerOptions {
10
12
  enrichRequest?: (ctx: ElysiaContextLike) => Record<string, unknown> | undefined;
package/dist/elysia.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as runWithIntegratedHandle, i as defineFrameworkIntegration, t as applyLoggerEnrichment } from "./integration-jKj-jgtX.js";
1
+ import { a as defineFrameworkIntegration, o as runWithIntegratedHandle, t as applyLoggerEnrichment } from "./integration-D_ABolGu.js";
2
2
  import { createLoggerStorage } from "./toolkit/storage.js";
3
3
  import { getHeader } from "./core.js";
4
4
  import { createDrainPipeline, createStructuredError, parseError } from "autotel";
@@ -11,7 +11,8 @@ function enrichFromContext(ctx) {
11
11
  return {
12
12
  "http.request.method": ctx.request.method,
13
13
  "url.full": ctx.request.url,
14
- "http.route": ctx.path,
14
+ "url.path": ctx.path,
15
+ "http.route": ctx.route,
15
16
  "http.request.id": requestId
16
17
  };
17
18
  }
@@ -21,6 +22,7 @@ const integration = defineFrameworkIntegration({
21
22
  extractRequest: (ctx) => ({
22
23
  method: ctx.request.method,
23
24
  path: ctx.path,
25
+ route: ctx.route,
24
26
  headers: ctx.request.headers,
25
27
  requestId: getHeader(ctx.request.headers, "x-request-id")
26
28
  }),
package/dist/express.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_integration = require("./integration-rv0DU916.cjs");
2
+ const require_integration = require("./integration-Danzss1R.cjs");
3
3
  const require_core = require("./core.cjs");
4
4
  let autotel = require("autotel");
5
5
  let node_async_hooks = require("node:async_hooks");
@@ -12,15 +12,27 @@ function headerValue(headers, name) {
12
12
  if (Array.isArray(value)) return value[0];
13
13
  return typeof value === "string" ? value : void 0;
14
14
  }
15
+ /**
16
+ * `req.route` is set once Express has matched a route. Its path is relative to
17
+ * the router it was registered on, and that is all `http.route` gets: the
18
+ * mount point is only available as `req.baseUrl`, the concrete path, so a
19
+ * router mounted at `/orgs/:orgId` would put the tenant id in the grouping key.
20
+ * Routes in two routers with the same relative path share a key; recording
21
+ * mount templates (by patching `Router.use`) would separate them.
22
+ */
23
+ function routeTemplate(request) {
24
+ const path = request.route?.path;
25
+ return typeof path === "string" ? path : void 0;
26
+ }
15
27
  function enrichFromRequest(request) {
16
28
  if (!request) return void 0;
17
29
  const url = request.originalUrl ?? request.url;
18
- const route = request.route?.path ?? request.path ?? url;
19
30
  const requestId = headerValue(request.headers, "x-request-id");
20
31
  return {
21
32
  "http.request.method": request.method,
22
33
  "url.full": url,
23
- "http.route": route,
34
+ "url.path": url?.split("?")[0],
35
+ "http.route": routeTemplate(request),
24
36
  "http.request.id": requestId
25
37
  };
26
38
  }
@@ -41,7 +53,7 @@ const runRequest = require_core.createRequestRunner(expressLoggerStorage);
41
53
  */
42
54
  function withAutotel(handler, options) {
43
55
  return async (req, res, next) => {
44
- const spanName = typeof options?.spanName === "function" ? options.spanName(req) : options?.spanName ?? `express.${req.method ?? "request"}`;
56
+ const spanName = typeof options?.spanName === "function" ? options.spanName(req) : options?.spanName ?? require_integration.defaultSpanName(req.method, routeTemplate(req));
45
57
  const route = req.route?.path ?? req.path ?? req.originalUrl ?? req.url ?? "/";
46
58
  try {
47
59
  return await runRequest(spanName, (log) => {
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions } from "./integration-D9g_qI5y.cjs";
1
+ import { _ as RouteAdapterOptions } from "./integration-CwqWnPKn.cjs";
2
2
  import "./core.cjs";
3
3
  import { RequestLogger, RequestLoggerOptions, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/express.d.ts
package/dist/express.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions } from "./integration-CQMpu5E4.js";
1
+ import { _ as RouteAdapterOptions } from "./integration-B6OoKr7O.js";
2
2
  import "./core.js";
3
3
  import { RequestLogger, RequestLoggerOptions, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/express.d.ts
package/dist/express.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as toRouteAdapterOptions } from "./integration-jKj-jgtX.js";
1
+ import { i as defaultSpanName, s as toRouteAdapterOptions } from "./integration-D_ABolGu.js";
2
2
  import { createRequestRunner, createUseLogger } from "./core.js";
3
3
  import { createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -11,15 +11,27 @@ function headerValue(headers, name) {
11
11
  if (Array.isArray(value)) return value[0];
12
12
  return typeof value === "string" ? value : void 0;
13
13
  }
14
+ /**
15
+ * `req.route` is set once Express has matched a route. Its path is relative to
16
+ * the router it was registered on, and that is all `http.route` gets: the
17
+ * mount point is only available as `req.baseUrl`, the concrete path, so a
18
+ * router mounted at `/orgs/:orgId` would put the tenant id in the grouping key.
19
+ * Routes in two routers with the same relative path share a key; recording
20
+ * mount templates (by patching `Router.use`) would separate them.
21
+ */
22
+ function routeTemplate(request) {
23
+ const path = request.route?.path;
24
+ return typeof path === "string" ? path : void 0;
25
+ }
14
26
  function enrichFromRequest(request) {
15
27
  if (!request) return void 0;
16
28
  const url = request.originalUrl ?? request.url;
17
- const route = request.route?.path ?? request.path ?? url;
18
29
  const requestId = headerValue(request.headers, "x-request-id");
19
30
  return {
20
31
  "http.request.method": request.method,
21
32
  "url.full": url,
22
- "http.route": route,
33
+ "url.path": url?.split("?")[0],
34
+ "http.route": routeTemplate(request),
23
35
  "http.request.id": requestId
24
36
  };
25
37
  }
@@ -40,7 +52,7 @@ const runRequest = createRequestRunner(expressLoggerStorage);
40
52
  */
41
53
  function withAutotel(handler, options) {
42
54
  return async (req, res, next) => {
43
- const spanName = typeof options?.spanName === "function" ? options.spanName(req) : options?.spanName ?? `express.${req.method ?? "request"}`;
55
+ const spanName = typeof options?.spanName === "function" ? options.spanName(req) : options?.spanName ?? defaultSpanName(req.method, routeTemplate(req));
44
56
  const route = req.route?.path ?? req.path ?? req.originalUrl ?? req.url ?? "/";
45
57
  try {
46
58
  return await runRequest(spanName, (log) => {
package/dist/fastify.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_integration = require("./integration-rv0DU916.cjs");
2
+ const require_integration = require("./integration-Danzss1R.cjs");
3
3
  const require_core = require("./core.cjs");
4
4
  let autotel = require("autotel");
5
5
  let node_async_hooks = require("node:async_hooks");
@@ -12,14 +12,16 @@ function headerValue(headers, name) {
12
12
  if (Array.isArray(value)) return value[0];
13
13
  return typeof value === "string" ? value : void 0;
14
14
  }
15
+ function routeTemplate(request) {
16
+ return request.routeOptions?.url ?? request.routerPath;
17
+ }
15
18
  function enrichFromRequest(request) {
16
19
  if (!request) return void 0;
17
- const route = request.routeOptions?.url ?? request.routerPath ?? request.url;
18
20
  const requestId = request.id ?? headerValue(request.headers, "x-request-id");
19
21
  return {
20
22
  "http.request.method": request.method,
21
23
  "url.full": request.url,
22
- "http.route": route,
24
+ "http.route": routeTemplate(request),
23
25
  "http.request.id": requestId
24
26
  };
25
27
  }
@@ -41,7 +43,7 @@ const runRequest = require_core.createRequestRunner(fastifyLoggerStorage);
41
43
  */
42
44
  function withAutotel(handler, options) {
43
45
  return (request, reply) => {
44
- const spanName = typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? `fastify.${request.method ?? "request"}`;
46
+ const spanName = typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? require_integration.defaultSpanName(request.method, routeTemplate(request));
45
47
  const route = request.routeOptions?.url ?? request.routerPath ?? request.url ?? "/";
46
48
  return runRequest(spanName, (log) => {
47
49
  const auto = enrichFromRequest(request);
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions } from "./integration-D9g_qI5y.cjs";
1
+ import { _ as RouteAdapterOptions } from "./integration-CwqWnPKn.cjs";
2
2
  import "./core.cjs";
3
3
  import { RequestLogger, RequestLoggerOptions, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/fastify.d.ts
package/dist/fastify.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions } from "./integration-CQMpu5E4.js";
1
+ import { _ as RouteAdapterOptions } from "./integration-B6OoKr7O.js";
2
2
  import "./core.js";
3
3
  import { RequestLogger, RequestLoggerOptions, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  //#region src/fastify.d.ts
package/dist/fastify.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as toRouteAdapterOptions } from "./integration-jKj-jgtX.js";
1
+ import { i as defaultSpanName, s as toRouteAdapterOptions } from "./integration-D_ABolGu.js";
2
2
  import { createRequestRunner, createUseLogger } from "./core.js";
3
3
  import { createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -11,14 +11,16 @@ function headerValue(headers, name) {
11
11
  if (Array.isArray(value)) return value[0];
12
12
  return typeof value === "string" ? value : void 0;
13
13
  }
14
+ function routeTemplate(request) {
15
+ return request.routeOptions?.url ?? request.routerPath;
16
+ }
14
17
  function enrichFromRequest(request) {
15
18
  if (!request) return void 0;
16
- const route = request.routeOptions?.url ?? request.routerPath ?? request.url;
17
19
  const requestId = request.id ?? headerValue(request.headers, "x-request-id");
18
20
  return {
19
21
  "http.request.method": request.method,
20
22
  "url.full": request.url,
21
- "http.route": route,
23
+ "http.route": routeTemplate(request),
22
24
  "http.request.id": requestId
23
25
  };
24
26
  }
@@ -40,7 +42,7 @@ const runRequest = createRequestRunner(fastifyLoggerStorage);
40
42
  */
41
43
  function withAutotel(handler, options) {
42
44
  return (request, reply) => {
43
- const spanName = typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? `fastify.${request.method ?? "request"}`;
45
+ const spanName = typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? defaultSpanName(request.method, routeTemplate(request));
44
46
  const route = request.routeOptions?.url ?? request.routerPath ?? request.url ?? "/";
45
47
  return runRequest(spanName, (log) => {
46
48
  const auto = enrichFromRequest(request);
package/dist/hono.cjs CHANGED
@@ -1,8 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_integration = require("./integration-rv0DU916.cjs");
2
+ const require_integration = require("./integration-Danzss1R.cjs");
3
3
  const require_toolkit_storage = require("./toolkit/storage.cjs");
4
4
  const require_core = require("./core.cjs");
5
5
  let autotel = require("autotel");
6
+ let hono_route = require("hono/route");
6
7
 
7
8
  //#region src/hono.ts
8
9
  const { storage: honoLoggerStorage, useLogger: storageUseLogger } = require_toolkit_storage.createLoggerStorage("middleware context. Register autotelMiddleware() before your routes.");
@@ -14,7 +15,7 @@ function enrichFromContext(c) {
14
15
  return {
15
16
  "http.request.method": c.req.method,
16
17
  "url.full": c.req.url,
17
- "http.route": c.req.path
18
+ "url.path": c.req.path
18
19
  };
19
20
  }
20
21
  const integration = require_integration.defineFrameworkIntegration({
@@ -43,16 +44,54 @@ function autotelMiddleware(options = {}) {
43
44
  return;
44
45
  }
45
46
  require_integration.applyLoggerEnrichment(handle.logger, enrichFromContext(c), options.enrichRequest?.(c));
47
+ const matchedRoute = () => {
48
+ const routes = routesOf(c);
49
+ const ran = c.req.routeIndex;
50
+ const path = (routes?.slice(ran + 1).findLast((route) => !route.path.endsWith("*")) ?? routes?.[ran] ?? routes?.at(-1))?.path;
51
+ return !path || path === "*" ? "/*" : path;
52
+ };
46
53
  try {
47
54
  await handle.runWith(() => next());
48
- if (options.autoEmit !== false) c.res = await handle.finishResponse(c.res);
55
+ handle.setRoute(matchedRoute());
56
+ const error = c.res.status >= 500 ? c.error : void 0;
57
+ if (options.autoEmit === false) handle.markOutcome({
58
+ status: c.res.status,
59
+ error
60
+ });
61
+ else c.res = await handle.finishResponse(c.res, { error });
49
62
  } catch (error) {
63
+ handle.setRoute(matchedRoute());
50
64
  if (options.autoEmit !== false) await handle.finish({ error: error instanceof Error ? error : new Error(String(error)) });
51
65
  throw error;
52
66
  }
53
67
  });
54
68
  };
55
69
  }
70
+ let warnedOtherHono = false;
71
+ /**
72
+ * The routes the request matched. `hono/route` reads them through a symbol
73
+ * private to the copy of Hono this module loaded, so when the app runs another
74
+ * copy (a bundled app beside an externalised adapter) it finds nothing. The
75
+ * request's own getter is the app's copy answering, so it is the fallback.
76
+ * Naming a span is best effort: a lookup that fails names it `/*` and never
77
+ * fails the request.
78
+ */
79
+ function routesOf(c) {
80
+ try {
81
+ return (0, hono_route.matchedRoutes)(c);
82
+ } catch {
83
+ if (!warnedOtherHono) {
84
+ warnedOtherHono = true;
85
+ console.warn("[autotel-adapters/hono] Could not read the matched route through hono/route, most likely because the app and autotel-adapters loaded different copies of Hono. Bundle autotel-adapters with the app, or externalise hono too.");
86
+ }
87
+ }
88
+ try {
89
+ const routes = c.req.matchedRoutes;
90
+ return Array.isArray(routes) ? routes : void 0;
91
+ } catch {
92
+ return;
93
+ }
94
+ }
56
95
  /** Alias for {@link useLogger} inside autotelMiddleware. */
57
96
  const useLoggerFromContext = useLogger;
58
97
 
package/dist/hono.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as FrameworkHandlerOptions } from "./integration-D9g_qI5y.cjs";
1
+ import { n as FrameworkHandlerOptions } from "./integration-CwqWnPKn.cjs";
2
2
  import "./core.cjs";
3
3
  import { RequestLogger, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  import { Context } from "hono";
package/dist/hono.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as FrameworkHandlerOptions } from "./integration-CQMpu5E4.js";
1
+ import { n as FrameworkHandlerOptions } from "./integration-B6OoKr7O.js";
2
2
  import "./core.js";
3
3
  import { RequestLogger, createDrainPipeline, createStructuredError, parseError } from "autotel";
4
4
  import { Context } from "hono";
package/dist/hono.js CHANGED
@@ -1,7 +1,8 @@
1
- import { i as defineFrameworkIntegration, t as applyLoggerEnrichment } from "./integration-jKj-jgtX.js";
1
+ import { a as defineFrameworkIntegration, t as applyLoggerEnrichment } from "./integration-D_ABolGu.js";
2
2
  import { createLoggerStorage } from "./toolkit/storage.js";
3
3
  import { createUseLogger } from "./core.js";
4
4
  import { createDrainPipeline, createStructuredError, parseError } from "autotel";
5
+ import { matchedRoutes } from "hono/route";
5
6
 
6
7
  //#region src/hono.ts
7
8
  const { storage: honoLoggerStorage, useLogger: storageUseLogger } = createLoggerStorage("middleware context. Register autotelMiddleware() before your routes.");
@@ -13,7 +14,7 @@ function enrichFromContext(c) {
13
14
  return {
14
15
  "http.request.method": c.req.method,
15
16
  "url.full": c.req.url,
16
- "http.route": c.req.path
17
+ "url.path": c.req.path
17
18
  };
18
19
  }
19
20
  const integration = defineFrameworkIntegration({
@@ -42,16 +43,54 @@ function autotelMiddleware(options = {}) {
42
43
  return;
43
44
  }
44
45
  applyLoggerEnrichment(handle.logger, enrichFromContext(c), options.enrichRequest?.(c));
46
+ const matchedRoute = () => {
47
+ const routes = routesOf(c);
48
+ const ran = c.req.routeIndex;
49
+ const path = (routes?.slice(ran + 1).findLast((route) => !route.path.endsWith("*")) ?? routes?.[ran] ?? routes?.at(-1))?.path;
50
+ return !path || path === "*" ? "/*" : path;
51
+ };
45
52
  try {
46
53
  await handle.runWith(() => next());
47
- if (options.autoEmit !== false) c.res = await handle.finishResponse(c.res);
54
+ handle.setRoute(matchedRoute());
55
+ const error = c.res.status >= 500 ? c.error : void 0;
56
+ if (options.autoEmit === false) handle.markOutcome({
57
+ status: c.res.status,
58
+ error
59
+ });
60
+ else c.res = await handle.finishResponse(c.res, { error });
48
61
  } catch (error) {
62
+ handle.setRoute(matchedRoute());
49
63
  if (options.autoEmit !== false) await handle.finish({ error: error instanceof Error ? error : new Error(String(error)) });
50
64
  throw error;
51
65
  }
52
66
  });
53
67
  };
54
68
  }
69
+ let warnedOtherHono = false;
70
+ /**
71
+ * The routes the request matched. `hono/route` reads them through a symbol
72
+ * private to the copy of Hono this module loaded, so when the app runs another
73
+ * copy (a bundled app beside an externalised adapter) it finds nothing. The
74
+ * request's own getter is the app's copy answering, so it is the fallback.
75
+ * Naming a span is best effort: a lookup that fails names it `/*` and never
76
+ * fails the request.
77
+ */
78
+ function routesOf(c) {
79
+ try {
80
+ return matchedRoutes(c);
81
+ } catch {
82
+ if (!warnedOtherHono) {
83
+ warnedOtherHono = true;
84
+ console.warn("[autotel-adapters/hono] Could not read the matched route through hono/route, most likely because the app and autotel-adapters loaded different copies of Hono. Bundle autotel-adapters with the app, or externalise hono too.");
85
+ }
86
+ }
87
+ try {
88
+ const routes = c.req.matchedRoutes;
89
+ return Array.isArray(routes) ? routes : void 0;
90
+ } catch {
91
+ return;
92
+ }
93
+ }
55
94
  /** Alias for {@link useLogger} inside autotelMiddleware. */
56
95
  const useLoggerFromContext = useLogger;
57
96
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_integration = require("./integration-rv0DU916.cjs");
2
+ const require_integration = require("./integration-Danzss1R.cjs");
3
3
  const require_core = require("./core.cjs");
4
4
  const require_next = require("./next.cjs");
5
5
  const require_nitro = require("./nitro.cjs");
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-D9g_qI5y.cjs";
1
+ import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-CwqWnPKn.cjs";
2
2
  import { AdapterUseLoggerOptions, BaseAdapterOptions, ConfigField, DrainPipelineOptions, HeadersLike, ParsedError, PipelineDrainFn, RequestLogSnapshot, RequestLogger, RequestLoggerOptions, RequestRunnerOptions, StructuredError, StructuredErrorInput, createRequestRunner, createUseLogger, getHeader, resolveAdapterConfig, shouldProbeRuntime } from "./core.cjs";
3
3
  import { withAutotelFetch } from "./cloudflare.cjs";
4
4
  import { autotel, useLogger, withAutotelHandler } from "./elysia.cjs";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-CQMpu5E4.js";
1
+ import { _ as RouteAdapterOptions, f as toRouteAdapterOptions, n as FrameworkHandlerOptions, o as IntegratedCompletionOptions } from "./integration-B6OoKr7O.js";
2
2
  import { AdapterUseLoggerOptions, BaseAdapterOptions, ConfigField, DrainPipelineOptions, HeadersLike, ParsedError, PipelineDrainFn, RequestLogSnapshot, RequestLogger, RequestLoggerOptions, RequestRunnerOptions, StructuredError, StructuredErrorInput, createRequestRunner, createUseLogger, getHeader, resolveAdapterConfig, shouldProbeRuntime } from "./core.js";
3
3
  import { withAutotelFetch } from "./cloudflare.js";
4
4
  import { autotel, useLogger, withAutotelHandler } from "./elysia.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as toRouteAdapterOptions } from "./integration-jKj-jgtX.js";
1
+ import { s as toRouteAdapterOptions } from "./integration-D_ABolGu.js";
2
2
  import { createRequestRunner, createUseLogger, getHeader, resolveAdapterConfig, shouldProbeRuntime } from "./core.js";
3
3
  import { withAutotel } from "./next.js";
4
4
  import { withAutotelEventHandler } from "./nitro.js";