autotel-adapters 0.3.15 → 0.3.17

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/fastify.cjs CHANGED
@@ -40,7 +40,8 @@ const runRequest = require_core.createRequestRunner(fastifyLoggerStorage);
40
40
  */
41
41
  function withAutotel(handler, options) {
42
42
  return (request, reply) => {
43
- return runRequest(typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? `fastify.${request.method ?? "request"}`, (log) => {
43
+ const spanName = typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? `fastify.${request.method ?? "request"}`;
44
+ return runRequest(spanName, (log) => {
44
45
  const auto = enrichFromRequest(request);
45
46
  if (auto && Object.keys(auto).length > 0) log.set(auto);
46
47
  const custom = options?.enrich?.(request);
@@ -1 +1 @@
1
- {"version":3,"file":"fastify.cjs","names":["AsyncLocalStorage","createUseLogger","createRequestRunner","createAdapterToolkit"],"sources":["../src/fastify.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport {\n createDrainPipeline,\n createStructuredError,\n parseError,\n type DrainPipelineOptions,\n type ParsedError,\n type PipelineDrainFn,\n type RequestLogger,\n type RequestLoggerOptions,\n type StructuredError,\n type StructuredErrorInput,\n} from 'autotel';\nimport {\n createAdapterToolkit,\n createRequestRunner,\n createUseLogger,\n} from './core';\n\nexport interface FastifyRequestLike {\n method?: string;\n url?: string;\n routeOptions?: { url?: string };\n routerPath?: string;\n id?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\nexport interface FastifyReplyLike {\n statusCode?: number;\n}\n\nexport interface FastifyWithAutotelOptions {\n spanName?: string | ((request: FastifyRequestLike) => string);\n requestLoggerOptions?: RequestLoggerOptions;\n enrich?: (request: FastifyRequestLike) => Record<string, unknown> | undefined;\n /** Emit one wide event automatically when the handler settles. Default `true`. */\n autoEmit?: boolean;\n}\n\nconst fastifyLoggerStorage = new AsyncLocalStorage<RequestLogger>();\n\nfunction headerValue(\n headers: FastifyRequestLike['headers'],\n name: string,\n): string | undefined {\n if (!headers) return undefined;\n const value = headers[name] ?? headers[name.toLowerCase()];\n if (Array.isArray(value)) return value[0];\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction enrichFromRequest(\n request?: FastifyRequestLike,\n): Record<string, unknown> | undefined {\n if (!request) return undefined;\n\n const route = request.routeOptions?.url ?? request.routerPath ?? request.url;\n const requestId = request.id ?? headerValue(request.headers, 'x-request-id');\n\n return {\n ...(request.method ? { 'http.request.method': request.method } : {}),\n ...(request.url ? { 'url.full': request.url } : {}),\n ...(route ? { 'http.route': route } : {}),\n ...(requestId ? { 'http.request.id': requestId } : {}),\n };\n}\n\nconst baseUseLogger = createUseLogger<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport function useLogger(\n request?: FastifyRequestLike,\n requestLoggerOptions?: RequestLoggerOptions,\n): RequestLogger {\n const stored = fastifyLoggerStorage.getStore();\n if (stored) return stored;\n return baseUseLogger(request, requestLoggerOptions);\n}\n\nconst runRequest = createRequestRunner(fastifyLoggerStorage);\n\n/**\n * Wrap a Fastify route handler. Each request opens a span, gets a\n * request-scoped logger (via `useLogger(request)`), and emits one wide event\n * when the handler settles. Thrown errors are recorded, then rethrown for\n * Fastify's error handling.\n */\nexport function withAutotel<\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n>(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n options?: FastifyWithAutotelOptions,\n): (request: TReq, reply: TRes) => Promise<TReturn> {\n return (request: TReq, reply: TRes): Promise<TReturn> => {\n const spanName =\n typeof options?.spanName === 'function'\n ? options.spanName(request)\n : (options?.spanName ?? `fastify.${request.method ?? 'request'}`);\n\n return runRequest<TReturn>(\n spanName,\n (log) => {\n const auto = enrichFromRequest(request);\n if (auto && Object.keys(auto).length > 0) log.set(auto);\n const custom = options?.enrich?.(request);\n if (custom && Object.keys(custom).length > 0) log.set(custom);\n },\n () => handler(request, reply),\n {\n requestLoggerOptions: options?.requestLoggerOptions,\n autoEmit: options?.autoEmit,\n finalize: () =>\n reply.statusCode\n ? { 'http.response.status_code': reply.statusCode }\n : undefined,\n },\n );\n };\n}\n\nexport function createFastifyAdapter(options?: FastifyWithAutotelOptions) {\n return {\n withAutotel: <\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n >(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n ) => withAutotel(handler, options),\n useLogger,\n parseError: (error: unknown): ParsedError => parseError(error),\n createStructuredError: (input: StructuredErrorInput): StructuredError =>\n createStructuredError(input),\n createDrainPipeline: <T = unknown>(\n drainOptions?: DrainPipelineOptions<T>,\n ): ((batchDrain: (batch: T[]) => void | Promise<void>) => PipelineDrainFn<T>) =>\n createDrainPipeline(drainOptions),\n };\n}\n\nexport const fastifyToolkit = createAdapterToolkit<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport { parseError, createDrainPipeline, createStructuredError };\n"],"mappings":";;;;;;AAwCA,MAAM,uBAAuB,IAAIA,mCAAiC;AAElE,SAAS,YACP,SACA,MACoB;CACpB,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,QAAQ,QAAQ,SAAS,QAAQ,KAAK,YAAY;CACxD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM;CACvC,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,kBACP,SACqC;CACrC,IAAI,CAAC,SAAS,OAAO;CAErB,MAAM,QAAQ,QAAQ,cAAc,OAAO,QAAQ,cAAc,QAAQ;CACzE,MAAM,YAAY,QAAQ,MAAM,YAAY,QAAQ,SAAS,cAAc;CAE3E,OAAO;EACL,GAAI,QAAQ,SAAS,EAAE,uBAAuB,QAAQ,OAAO,IAAI,CAAC;EAClE,GAAI,QAAQ,MAAM,EAAE,YAAY,QAAQ,IAAI,IAAI,CAAC;EACjD,GAAI,QAAQ,EAAE,cAAc,MAAM,IAAI,CAAC;EACvC,GAAI,YAAY,EAAE,mBAAmB,UAAU,IAAI,CAAC;CACtD;AACF;AAEA,MAAM,gBAAgBC,6BAAoC;CACxD,aAAa;CACb,QAAQ;AACV,CAAC;AAED,SAAgB,UACd,SACA,sBACe;CACf,MAAM,SAAS,qBAAqB,SAAS;CAC7C,IAAI,QAAQ,OAAO;CACnB,OAAO,cAAc,SAAS,oBAAoB;AACpD;AAEA,MAAM,aAAaC,iCAAoB,oBAAoB;;;;;;;AAQ3D,SAAgB,YAKd,SACA,SACkD;CAClD,QAAQ,SAAe,UAAkC;EAMvD,OAAO,WAJL,OAAO,SAAS,aAAa,aACzB,QAAQ,SAAS,OAAO,IACvB,SAAS,YAAY,WAAW,QAAQ,UAAU,cAItD,QAAQ;GACP,MAAM,OAAO,kBAAkB,OAAO;GACtC,IAAI,QAAQ,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,IAAI,IAAI;GACtD,MAAM,SAAS,SAAS,SAAS,OAAO;GACxC,IAAI,UAAU,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,GAAG,IAAI,IAAI,MAAM;EAC9D,SACM,QAAQ,SAAS,KAAK,GAC5B;GACE,sBAAsB,SAAS;GAC/B,UAAU,SAAS;GACnB,gBACE,MAAM,aACF,EAAE,6BAA6B,MAAM,WAAW,IAChD;EACR,CACF;CACF;AACF;AAEA,SAAgB,qBAAqB,SAAqC;CACxE,OAAO;EACL,cAKE,YACG,YAAY,SAAS,OAAO;EACjC;EACA,aAAa,kCAA2C,KAAK;EAC7D,wBAAwB,6CACA,KAAK;EAC7B,sBACE,kDAEoB,YAAY;CACpC;AACF;AAEA,MAAa,iBAAiBC,kCAAyC;CACrE,aAAa;CACb,QAAQ;AACV,CAAC"}
1
+ {"version":3,"file":"fastify.cjs","names":["AsyncLocalStorage","createUseLogger","createRequestRunner","createAdapterToolkit"],"sources":["../src/fastify.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport {\n createDrainPipeline,\n createStructuredError,\n parseError,\n type DrainPipelineOptions,\n type ParsedError,\n type PipelineDrainFn,\n type RequestLogger,\n type RequestLoggerOptions,\n type StructuredError,\n type StructuredErrorInput,\n} from 'autotel';\nimport {\n createAdapterToolkit,\n createRequestRunner,\n createUseLogger,\n} from './core';\n\nexport interface FastifyRequestLike {\n method?: string;\n url?: string;\n routeOptions?: { url?: string };\n routerPath?: string;\n id?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\nexport interface FastifyReplyLike {\n statusCode?: number;\n}\n\nexport interface FastifyWithAutotelOptions {\n spanName?: string | ((request: FastifyRequestLike) => string);\n requestLoggerOptions?: RequestLoggerOptions;\n enrich?: (request: FastifyRequestLike) => Record<string, unknown> | undefined;\n /** Emit one wide event automatically when the handler settles. Default `true`. */\n autoEmit?: boolean;\n}\n\nconst fastifyLoggerStorage = new AsyncLocalStorage<RequestLogger>();\n\nfunction headerValue(\n headers: FastifyRequestLike['headers'],\n name: string,\n): string | undefined {\n if (!headers) return undefined;\n const value = headers[name] ?? headers[name.toLowerCase()];\n if (Array.isArray(value)) return value[0];\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction enrichFromRequest(\n request?: FastifyRequestLike,\n): Record<string, unknown> | undefined {\n if (!request) return undefined;\n\n const route = request.routeOptions?.url ?? request.routerPath ?? request.url;\n const requestId = request.id ?? headerValue(request.headers, 'x-request-id');\n\n return {\n ...(request.method ? { 'http.request.method': request.method } : {}),\n ...(request.url ? { 'url.full': request.url } : {}),\n ...(route ? { 'http.route': route } : {}),\n ...(requestId ? { 'http.request.id': requestId } : {}),\n };\n}\n\nconst baseUseLogger = createUseLogger<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport function useLogger(\n request?: FastifyRequestLike,\n requestLoggerOptions?: RequestLoggerOptions,\n): RequestLogger {\n const stored = fastifyLoggerStorage.getStore();\n if (stored) return stored;\n return baseUseLogger(request, requestLoggerOptions);\n}\n\nconst runRequest = createRequestRunner(fastifyLoggerStorage);\n\n/**\n * Wrap a Fastify route handler. Each request opens a span, gets a\n * request-scoped logger (via `useLogger(request)`), and emits one wide event\n * when the handler settles. Thrown errors are recorded, then rethrown for\n * Fastify's error handling.\n */\nexport function withAutotel<\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n>(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n options?: FastifyWithAutotelOptions,\n): (request: TReq, reply: TRes) => Promise<TReturn> {\n return (request: TReq, reply: TRes): Promise<TReturn> => {\n const spanName =\n typeof options?.spanName === 'function'\n ? options.spanName(request)\n : (options?.spanName ?? `fastify.${request.method ?? 'request'}`);\n\n return runRequest<TReturn>(\n spanName,\n (log) => {\n const auto = enrichFromRequest(request);\n if (auto && Object.keys(auto).length > 0) log.set(auto);\n const custom = options?.enrich?.(request);\n if (custom && Object.keys(custom).length > 0) log.set(custom);\n },\n () => handler(request, reply),\n {\n requestLoggerOptions: options?.requestLoggerOptions,\n autoEmit: options?.autoEmit,\n finalize: () =>\n reply.statusCode\n ? { 'http.response.status_code': reply.statusCode }\n : undefined,\n },\n );\n };\n}\n\nexport function createFastifyAdapter(options?: FastifyWithAutotelOptions) {\n return {\n withAutotel: <\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n >(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n ) => withAutotel(handler, options),\n useLogger,\n parseError: (error: unknown): ParsedError => parseError(error),\n createStructuredError: (input: StructuredErrorInput): StructuredError =>\n createStructuredError(input),\n createDrainPipeline: <T = unknown>(\n drainOptions?: DrainPipelineOptions<T>,\n ): ((batchDrain: (batch: T[]) => void | Promise<void>) => PipelineDrainFn<T>) =>\n createDrainPipeline(drainOptions),\n };\n}\n\nexport const fastifyToolkit = createAdapterToolkit<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport { par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GACtD,MAAM,SAAS,SAAS,SAAS,OAAO;GACxC,IAAI,UAAU,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,GAAG,IAAI,IAAI,MAAM;EAC9D,SACM,QAAQ,SAAS,KAAK,GAC5B;GACE,sBAAsB,SAAS;GAC/B,UAAU,SAAS;GACnB,gBACE,MAAM,aACF,EAAE,6BAA6B,MAAM,WAAW,IAChD;EACR,CACF;CACF;AACF;AAEA,SAAgB,qBAAqB,SAAqC;CACxE,OAAO;EACL,cAKE,YACG,YAAY,SAAS,OAAO;EACjC;EACA,aAAa,kCAA2C,KAAK;EAC7D,wBAAwB,6CACA,KAAK;EAC7B,sBACE,kDAEoB,YAAY;CACpC;AACF;AAEA,MAAa,iBAAiBC,kCAAyC;CACrE,aAAa;CACb,QAAQ;AACV,CAAC"}
package/dist/fastify.js CHANGED
@@ -39,7 +39,8 @@ const runRequest = createRequestRunner(fastifyLoggerStorage);
39
39
  */
40
40
  function withAutotel(handler, options) {
41
41
  return (request, reply) => {
42
- return runRequest(typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? `fastify.${request.method ?? "request"}`, (log) => {
42
+ const spanName = typeof options?.spanName === "function" ? options.spanName(request) : options?.spanName ?? `fastify.${request.method ?? "request"}`;
43
+ return runRequest(spanName, (log) => {
43
44
  const auto = enrichFromRequest(request);
44
45
  if (auto && Object.keys(auto).length > 0) log.set(auto);
45
46
  const custom = options?.enrich?.(request);
@@ -1 +1 @@
1
- {"version":3,"file":"fastify.js","names":[],"sources":["../src/fastify.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport {\n createDrainPipeline,\n createStructuredError,\n parseError,\n type DrainPipelineOptions,\n type ParsedError,\n type PipelineDrainFn,\n type RequestLogger,\n type RequestLoggerOptions,\n type StructuredError,\n type StructuredErrorInput,\n} from 'autotel';\nimport {\n createAdapterToolkit,\n createRequestRunner,\n createUseLogger,\n} from './core';\n\nexport interface FastifyRequestLike {\n method?: string;\n url?: string;\n routeOptions?: { url?: string };\n routerPath?: string;\n id?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\nexport interface FastifyReplyLike {\n statusCode?: number;\n}\n\nexport interface FastifyWithAutotelOptions {\n spanName?: string | ((request: FastifyRequestLike) => string);\n requestLoggerOptions?: RequestLoggerOptions;\n enrich?: (request: FastifyRequestLike) => Record<string, unknown> | undefined;\n /** Emit one wide event automatically when the handler settles. Default `true`. */\n autoEmit?: boolean;\n}\n\nconst fastifyLoggerStorage = new AsyncLocalStorage<RequestLogger>();\n\nfunction headerValue(\n headers: FastifyRequestLike['headers'],\n name: string,\n): string | undefined {\n if (!headers) return undefined;\n const value = headers[name] ?? headers[name.toLowerCase()];\n if (Array.isArray(value)) return value[0];\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction enrichFromRequest(\n request?: FastifyRequestLike,\n): Record<string, unknown> | undefined {\n if (!request) return undefined;\n\n const route = request.routeOptions?.url ?? request.routerPath ?? request.url;\n const requestId = request.id ?? headerValue(request.headers, 'x-request-id');\n\n return {\n ...(request.method ? { 'http.request.method': request.method } : {}),\n ...(request.url ? { 'url.full': request.url } : {}),\n ...(route ? { 'http.route': route } : {}),\n ...(requestId ? { 'http.request.id': requestId } : {}),\n };\n}\n\nconst baseUseLogger = createUseLogger<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport function useLogger(\n request?: FastifyRequestLike,\n requestLoggerOptions?: RequestLoggerOptions,\n): RequestLogger {\n const stored = fastifyLoggerStorage.getStore();\n if (stored) return stored;\n return baseUseLogger(request, requestLoggerOptions);\n}\n\nconst runRequest = createRequestRunner(fastifyLoggerStorage);\n\n/**\n * Wrap a Fastify route handler. Each request opens a span, gets a\n * request-scoped logger (via `useLogger(request)`), and emits one wide event\n * when the handler settles. Thrown errors are recorded, then rethrown for\n * Fastify's error handling.\n */\nexport function withAutotel<\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n>(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n options?: FastifyWithAutotelOptions,\n): (request: TReq, reply: TRes) => Promise<TReturn> {\n return (request: TReq, reply: TRes): Promise<TReturn> => {\n const spanName =\n typeof options?.spanName === 'function'\n ? options.spanName(request)\n : (options?.spanName ?? `fastify.${request.method ?? 'request'}`);\n\n return runRequest<TReturn>(\n spanName,\n (log) => {\n const auto = enrichFromRequest(request);\n if (auto && Object.keys(auto).length > 0) log.set(auto);\n const custom = options?.enrich?.(request);\n if (custom && Object.keys(custom).length > 0) log.set(custom);\n },\n () => handler(request, reply),\n {\n requestLoggerOptions: options?.requestLoggerOptions,\n autoEmit: options?.autoEmit,\n finalize: () =>\n reply.statusCode\n ? { 'http.response.status_code': reply.statusCode }\n : undefined,\n },\n );\n };\n}\n\nexport function createFastifyAdapter(options?: FastifyWithAutotelOptions) {\n return {\n withAutotel: <\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n >(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n ) => withAutotel(handler, options),\n useLogger,\n parseError: (error: unknown): ParsedError => parseError(error),\n createStructuredError: (input: StructuredErrorInput): StructuredError =>\n createStructuredError(input),\n createDrainPipeline: <T = unknown>(\n drainOptions?: DrainPipelineOptions<T>,\n ): ((batchDrain: (batch: T[]) => void | Promise<void>) => PipelineDrainFn<T>) =>\n createDrainPipeline(drainOptions),\n };\n}\n\nexport const fastifyToolkit = createAdapterToolkit<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport { parseError, createDrainPipeline, createStructuredError };\n"],"mappings":";;;;;AAwCA,MAAM,uBAAuB,IAAI,kBAAiC;AAElE,SAAS,YACP,SACA,MACoB;CACpB,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,QAAQ,QAAQ,SAAS,QAAQ,KAAK,YAAY;CACxD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM;CACvC,OAAO,OAAO,UAAU,W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BAAqB,SAAqC;CACxE,OAAO;EACL,cAKE,YACG,YAAY,SAAS,OAAO;EACjC;EACA,aAAa,UAAgC,WAAW,KAAK;EAC7D,wBAAwB,UACtB,sBAAsB,KAAK;EAC7B,sBACE,iBAEA,oBAAoB,YAAY;CACpC;AACF;AAEA,MAAa,iBAAiB,qBAAyC;CACrE,aAAa;CACb,QAAQ;AACV,CAAC"}
1
+ {"version":3,"file":"fastify.js","names":[],"sources":["../src/fastify.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport {\n createDrainPipeline,\n createStructuredError,\n parseError,\n type DrainPipelineOptions,\n type ParsedError,\n type PipelineDrainFn,\n type RequestLogger,\n type RequestLoggerOptions,\n type StructuredError,\n type StructuredErrorInput,\n} from 'autotel';\nimport {\n createAdapterToolkit,\n createRequestRunner,\n createUseLogger,\n} from './core';\n\nexport interface FastifyRequestLike {\n method?: string;\n url?: string;\n routeOptions?: { url?: string };\n routerPath?: string;\n id?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\nexport interface FastifyReplyLike {\n statusCode?: number;\n}\n\nexport interface FastifyWithAutotelOptions {\n spanName?: string | ((request: FastifyRequestLike) => string);\n requestLoggerOptions?: RequestLoggerOptions;\n enrich?: (request: FastifyRequestLike) => Record<string, unknown> | undefined;\n /** Emit one wide event automatically when the handler settles. Default `true`. */\n autoEmit?: boolean;\n}\n\nconst fastifyLoggerStorage = new AsyncLocalStorage<RequestLogger>();\n\nfunction headerValue(\n headers: FastifyRequestLike['headers'],\n name: string,\n): string | undefined {\n if (!headers) return undefined;\n const value = headers[name] ?? headers[name.toLowerCase()];\n if (Array.isArray(value)) return value[0];\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction enrichFromRequest(\n request?: FastifyRequestLike,\n): Record<string, unknown> | undefined {\n if (!request) return undefined;\n\n const route = request.routeOptions?.url ?? request.routerPath ?? request.url;\n const requestId = request.id ?? headerValue(request.headers, 'x-request-id');\n\n return {\n ...(request.method ? { 'http.request.method': request.method } : {}),\n ...(request.url ? { 'url.full': request.url } : {}),\n ...(route ? { 'http.route': route } : {}),\n ...(requestId ? { 'http.request.id': requestId } : {}),\n };\n}\n\nconst baseUseLogger = createUseLogger<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport function useLogger(\n request?: FastifyRequestLike,\n requestLoggerOptions?: RequestLoggerOptions,\n): RequestLogger {\n const stored = fastifyLoggerStorage.getStore();\n if (stored) return stored;\n return baseUseLogger(request, requestLoggerOptions);\n}\n\nconst runRequest = createRequestRunner(fastifyLoggerStorage);\n\n/**\n * Wrap a Fastify route handler. Each request opens a span, gets a\n * request-scoped logger (via `useLogger(request)`), and emits one wide event\n * when the handler settles. Thrown errors are recorded, then rethrown for\n * Fastify's error handling.\n */\nexport function withAutotel<\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n>(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n options?: FastifyWithAutotelOptions,\n): (request: TReq, reply: TRes) => Promise<TReturn> {\n return (request: TReq, reply: TRes): Promise<TReturn> => {\n const spanName =\n typeof options?.spanName === 'function'\n ? options.spanName(request)\n : (options?.spanName ?? `fastify.${request.method ?? 'request'}`);\n\n return runRequest<TReturn>(\n spanName,\n (log) => {\n const auto = enrichFromRequest(request);\n if (auto && Object.keys(auto).length > 0) log.set(auto);\n const custom = options?.enrich?.(request);\n if (custom && Object.keys(custom).length > 0) log.set(custom);\n },\n () => handler(request, reply),\n {\n requestLoggerOptions: options?.requestLoggerOptions,\n autoEmit: options?.autoEmit,\n finalize: () =>\n reply.statusCode\n ? { 'http.response.status_code': reply.statusCode }\n : undefined,\n },\n );\n };\n}\n\nexport function createFastifyAdapter(options?: FastifyWithAutotelOptions) {\n return {\n withAutotel: <\n TReq extends FastifyRequestLike,\n TRes extends FastifyReplyLike,\n TReturn,\n >(\n handler: (request: TReq, reply: TRes) => TReturn | Promise<TReturn>,\n ) => withAutotel(handler, options),\n useLogger,\n parseError: (error: unknown): ParsedError => parseError(error),\n createStructuredError: (input: StructuredErrorInput): StructuredError =>\n createStructuredError(input),\n createDrainPipeline: <T = unknown>(\n drainOptions?: DrainPipelineOptions<T>,\n ): ((batchDrain: (batch: T[]) => void | Promise<void>) => PipelineDrainFn<T>) =>\n createDrainPipeline(drainOptions),\n };\n}\n\nexport const fastifyToolkit = createAdapterToolkit<FastifyRequestLike>({\n adapterName: 'fastify',\n enrich: enrichFromRequest,\n});\n\nexport { parseError, createDrainPipeline, createStructuredError };\n"],"mappings":";;;;;AAwCA,MAAM,uBAAuB,IAAI,kBAAiC;AAElE,SAAS,YACP,SACA,MACoB;CACpB,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,QAAQ,QAAQ,SAAS,QAAQ,KAAK,YAAY;CACxD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM;CACvC,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,kBACP,SACqC;CACrC,IAAI,CAAC,SAAS,OAAO;CAErB,MAAM,QAAQ,QAAQ,cAAc,OAAO,QAAQ,cAAc,QAAQ;CACzE,MAAM,YAAY,QAAQ,MAAM,YAAY,QAAQ,SAAS,cAAc;CAE3E,OAAO;EACL,GAAI,QAAQ,SAAS,EAAE,uBAAuB,QAAQ,OAAO,IAAI,CAAC;EAClE,GAAI,QAAQ,MAAM,EAAE,YAAY,QAAQ,IAAI,IAAI,CAAC;EACjD,GAAI,QAAQ,EAAE,cAAc,MAAM,IAAI,CAAC;EACvC,GAAI,YAAY,EAAE,mBAAmB,UAAU,IAAI,CAAC;CACtD;AACF;AAEA,MAAM,gBAAgB,gBAAoC;CACxD,aAAa;CACb,QAAQ;AACV,CAAC;AAED,SAAgB,UACd,SACA,sBACe;CACf,MAAM,SAAS,qBAAqB,SAAS;CAC7C,IAAI,QAAQ,OAAO;CACnB,OAAO,cAAc,SAAS,oBAAoB;AACpD;AAEA,MAAM,aAAa,oBAAoB,oBAAoB;;;;;;;AAQ3D,SAAgB,YAKd,SACA,SACkD;CAClD,QAAQ,SAAe,UAAkC;EACvD,MAAM,WACJ,OAAO,SAAS,aAAa,aACzB,QAAQ,SAAS,OAAO,IACvB,SAAS,YAAY,WAAW,QAAQ,UAAU;EAEzD,OAAO,WACL,WACC,QAAQ;GACP,MAAM,OAAO,kBAAkB,OAAO;GACtC,IAAI,QAAQ,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,IAAI,IAAI;GACtD,MAAM,SAAS,SAAS,SAAS,OAAO;GACxC,IAAI,UAAU,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,GAAG,IAAI,IAAI,MAAM;EAC9D,SACM,QAAQ,SAAS,KAAK,GAC5B;GACE,sBAAsB,SAAS;GAC/B,UAAU,SAAS;GACnB,gBACE,MAAM,aACF,EAAE,6BAA6B,MAAM,WAAW,IAChD;EACR,CACF;CACF;AACF;AAEA,SAAgB,qBAAqB,SAAqC;CACxE,OAAO;EACL,cAKE,YACG,YAAY,SAAS,OAAO;EACjC;EACA,aAAa,UAAgC,WAAW,KAAK;EAC7D,wBAAwB,UACtB,sBAAsB,KAAK;EAC7B,sBACE,iBAEA,oBAAoB,YAAY;CACpC;AACF;AAEA,MAAa,iBAAiB,qBAAyC;CACrE,aAAa;CACb,QAAQ;AACV,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autotel-adapters",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "Framework adapters and composable DX helpers for autotel",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -60,13 +60,13 @@
60
60
  "skills"
61
61
  ],
62
62
  "dependencies": {
63
- "autotel": "4.2.2"
63
+ "autotel": "4.2.4"
64
64
  },
65
65
  "peerDependencies": {
66
- "hono": ">=4.12.23",
67
- "@tanstack/react-start": "^1.168.25",
68
- "@tanstack/solid-start": "^1.168.25",
69
- "next": ">=16.2.7",
66
+ "hono": ">=4.12.28",
67
+ "@tanstack/react-start": "^1.168.27",
68
+ "@tanstack/solid-start": "^1.168.27",
69
+ "next": ">=16.2.10",
70
70
  "h3": "^2.0.0",
71
71
  "nitropack": "^2.13.4"
72
72
  },
@@ -91,12 +91,12 @@
91
91
  }
92
92
  },
93
93
  "devDependencies": {
94
- "@types/node": "^25.9.2",
95
- "hono": "^4.12.23",
94
+ "@types/node": "^26.1.0",
95
+ "hono": "^4.12.28",
96
96
  "rimraf": "^6.1.3",
97
- "tsdown": "^0.22.2",
97
+ "tsdown": "^0.22.3",
98
98
  "typescript": "^6.0.3",
99
- "vitest": "^4.1.8"
99
+ "vitest": "^4.1.10"
100
100
  },
101
101
  "repository": {
102
102
  "type": "git",