@opentelemetry/instrumentation-fastify 0.44.0 → 0.44.2

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/README.md CHANGED
@@ -3,9 +3,13 @@
3
3
  [![NPM Published Version][npm-img]][npm-url]
4
4
  [![Apache License][license-image]][license-image]
5
5
 
6
- This module provides automatic instrumentation for the [`fastify`](https://www.fastify.io/) module, which may be loaded using the [`@opentelemetry/sdk-trace-node`](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node) package and is included in the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle.
6
+ > [!IMPORTANT]
7
+ > This component is **deprecated** in favor of the official instrumentation package [`@fastify/otel`](https://www.npmjs.com/package/@fastify/otel), maintained by the Fastify authors.
8
+ > Please see [here](https://github.com/fastify/otel?tab=readme-ov-file#usage) for instructions on how to use `@fastify/otel`.
9
+ >
10
+ > We will stop publishing new versions of `@opentelemetry/instrumentation-fastify` on June 30, 2025.
7
11
 
8
- If total installation size is not constrained, it is recommended to use the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle with [@opentelemetry/sdk-node](`https://www.npmjs.com/package/@opentelemetry/sdk-node`) for the most seamless instrumentation experience.
12
+ This module provides automatic instrumentation for the [`fastify`](https://www.fastify.dev/) module, which may be loaded using the [`@opentelemetry/sdk-trace-node`](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node) package.
9
13
 
10
14
  Compatible with OpenTelemetry JS API and SDK `1.0+`.
11
15
 
@@ -1,7 +1,11 @@
1
1
  import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
2
  import type { FastifyInstrumentationConfig } from './types';
3
3
  export declare const ANONYMOUS_NAME = "anonymous";
4
- /** Fastify instrumentation for OpenTelemetry */
4
+ /**
5
+ * Fastify instrumentation for OpenTelemetry
6
+ * @deprecated This instrumentation is deprecated in favor of the official instrumentation package `@fastify/otel`,
7
+ * which is maintained by the fastify authors.
8
+ */
5
9
  export declare class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumentationConfig> {
6
10
  constructor(config?: FastifyInstrumentationConfig);
7
11
  init(): InstrumentationNodeModuleDefinition[];
@@ -26,7 +26,11 @@ const utils_1 = require("./utils");
26
26
  /** @knipignore */
27
27
  const version_1 = require("./version");
28
28
  exports.ANONYMOUS_NAME = 'anonymous';
29
- /** Fastify instrumentation for OpenTelemetry */
29
+ /**
30
+ * Fastify instrumentation for OpenTelemetry
31
+ * @deprecated This instrumentation is deprecated in favor of the official instrumentation package `@fastify/otel`,
32
+ * which is maintained by the fastify authors.
33
+ */
30
34
  class FastifyInstrumentation extends instrumentation_1.InstrumentationBase {
31
35
  constructor(config = {}) {
32
36
  super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, config);
@@ -127,6 +131,9 @@ class FastifyInstrumentation extends instrumentation_1.InstrumentationBase {
127
131
  instrumentation._wrap(app, 'addHook', instrumentation._wrapAddHook());
128
132
  return app;
129
133
  }
134
+ if (moduleExports.errorCodes !== undefined) {
135
+ fastify.errorCodes = moduleExports.errorCodes;
136
+ }
130
137
  fastify.fastify = fastify;
131
138
  fastify.default = fastify;
132
139
  return fastify;
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAAgF;AAChF,8CAA8D;AAC9D,oEAIwC;AACxC,8EAA0E;AAO1E,2CAA+C;AAC/C,2DAIgC;AAGhC,mCAIiB;AACjB,kBAAkB;AAClB,uCAA0D;AAE7C,QAAA,cAAc,GAAG,WAAW,CAAC;AAE1C,gDAAgD;AAChD,MAAa,sBAAuB,SAAQ,qCAAiD;IAC3F,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE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AAG,WAAW,CAAC;aAC3D;YACD,MAAM,IAAI,GAAG,IAAA,iBAAS,EACpB,KAAK,EACL,eAAe,CAAC,MAAM,EACtB,QAAQ,EACR,cAAc,CACf,CAAC;YAEF,MAAM,EAAE,WAAW,EAAE,GAAG,eAAe,CAAC,SAAS,EAAE,CAAC;YACpD,IAAI,WAAW,EAAE;gBACf,IAAA,wCAAsB,EACpB,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EACpC,CAAC,CAAC,EAAE;oBACF,IAAI,CAAC,EAAE;wBACL,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC,CAAC;qBACvD;gBACH,CAAC,EACD,IAAI,CACL,CAAC;aACH;YAED,OAAO,aAAO,CAAC,IAAI,CAAC,WAAK,CAAC,OAAO,CAAC,aAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE;gBAC9D,IAAI,EAAE,CAAC;YACT,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;CACF;AArPD,wDAqPC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, Attributes, SpanStatusCode, trace } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\nimport type {\n HookHandlerDoneFunction,\n FastifyInstance,\n FastifyRequest,\n FastifyReply,\n} from 'fastify';\nimport { hooksNamesToWrap } from './constants';\nimport {\n AttributeNames,\n FastifyNames,\n FastifyTypes,\n} from './enums/AttributeNames';\nimport type { HandlerOriginal, PluginFastifyReply } from './internal-types';\nimport type { FastifyInstrumentationConfig } from './types';\nimport {\n endSpan,\n safeExecuteInTheMiddleMaybePromise,\n startSpan,\n} from './utils';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nexport const ANONYMOUS_NAME = 'anonymous';\n\n/** Fastify instrumentation for OpenTelemetry */\nexport class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumentationConfig> {\n constructor(config: FastifyInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n init() {\n return [\n new InstrumentationNodeModuleDefinition(\n 'fastify',\n ['>=3.0.0 <6'],\n moduleExports => {\n return this._patchConstructor(moduleExports);\n }\n ),\n ];\n }\n\n private _hookOnRequest() {\n const instrumentation = this;\n return function onRequest(\n request: FastifyRequest,\n reply: FastifyReply,\n done: HookHandlerDoneFunction\n ) {\n if (!instrumentation.isEnabled()) {\n return done();\n }\n instrumentation._wrap(reply, 'send', instrumentation._patchSend());\n\n const anyRequest = request as any;\n\n const rpcMetadata = getRPCMetadata(context.active());\n const routeName = anyRequest.routeOptions\n ? anyRequest.routeOptions.url // since fastify@4.10.0\n : request.routerPath;\n if (routeName && rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = routeName;\n }\n done();\n };\n }\n\n private _wrapHandler(\n pluginName: string,\n hookName: string,\n original: (...args: unknown[]) => Promise<unknown>,\n syncFunctionWithDone: boolean\n ): () => Promise<unknown> {\n const instrumentation = this;\n this._diag.debug('Patching fastify route.handler function');\n\n return function (this: any, ...args: unknown[]): Promise<unknown> {\n if (!instrumentation.isEnabled()) {\n return original.apply(this, args);\n }\n\n const name = original.name || pluginName || ANONYMOUS_NAME;\n const spanName = `${FastifyNames.MIDDLEWARE} - ${name}`;\n\n const reply = args[1] as PluginFastifyReply;\n\n const span = startSpan(reply, instrumentation.tracer, spanName, {\n [AttributeNames.FASTIFY_TYPE]: FastifyTypes.MIDDLEWARE,\n [AttributeNames.PLUGIN_NAME]: pluginName,\n [AttributeNames.HOOK_NAME]: hookName,\n });\n\n const origDone =\n syncFunctionWithDone &&\n (args[args.length - 1] as HookHandlerDoneFunction);\n if (origDone) {\n args[args.length - 1] = function (\n ...doneArgs: Parameters<HookHandlerDoneFunction>\n ) {\n endSpan(reply);\n origDone.apply(this, doneArgs);\n };\n }\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddleMaybePromise(\n () => {\n return original.apply(this, args);\n },\n err => {\n if (err instanceof Error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n });\n span.recordException(err);\n }\n // async hooks should end the span as soon as the promise is resolved\n if (!syncFunctionWithDone) {\n endSpan(reply);\n }\n }\n );\n });\n };\n }\n\n private _wrapAddHook(): (\n original: FastifyInstance['addHook']\n ) => () => FastifyInstance {\n const instrumentation = this;\n this._diag.debug('Patching fastify server.addHook function');\n\n return function (\n original: FastifyInstance['addHook']\n ): () => FastifyInstance {\n return function wrappedAddHook(this: any, ...args: any) {\n const name = args[0] as string;\n const handler = args[1] as HandlerOriginal;\n const pluginName = this.pluginName;\n if (!hooksNamesToWrap.has(name)) {\n return original.apply(this, args);\n }\n\n const syncFunctionWithDone =\n typeof args[args.length - 1] === 'function' &&\n handler.constructor.name !== 'AsyncFunction';\n\n return original.apply(this, [\n name,\n instrumentation._wrapHandler(\n pluginName,\n name,\n handler,\n syncFunctionWithDone\n ),\n ] as never);\n };\n };\n }\n\n private _patchConstructor(moduleExports: {\n fastify: () => FastifyInstance;\n }): () => FastifyInstance {\n const instrumentation = this;\n\n function fastify(this: FastifyInstance, ...args: any) {\n const app: FastifyInstance = moduleExports.fastify.apply(this, args);\n app.addHook('onRequest', instrumentation._hookOnRequest());\n app.addHook('preHandler', instrumentation._hookPreHandler());\n\n instrumentation._wrap(app, 'addHook', instrumentation._wrapAddHook());\n\n return app;\n }\n\n fastify.fastify = fastify;\n fastify.default = fastify;\n return fastify;\n }\n\n private _patchSend() {\n const instrumentation = this;\n this._diag.debug('Patching fastify reply.send function');\n\n return function patchSend(\n original: () => FastifyReply\n ): () => FastifyReply {\n return function send(this: FastifyReply, ...args: any) {\n const maybeError: any = args[0];\n\n if (!instrumentation.isEnabled()) {\n return original.apply(this, args);\n }\n\n return safeExecuteInTheMiddle<FastifyReply>(\n () => {\n return original.apply(this, args);\n },\n err => {\n if (!err && maybeError instanceof Error) {\n err = maybeError;\n }\n endSpan(this, err);\n }\n );\n };\n };\n }\n\n private _hookPreHandler() {\n const instrumentation = this;\n this._diag.debug('Patching fastify preHandler function');\n\n return function preHandler(\n this: any,\n request: FastifyRequest,\n reply: FastifyReply,\n done: HookHandlerDoneFunction\n ) {\n if (!instrumentation.isEnabled()) {\n return done();\n }\n const anyRequest = request as any;\n\n const handler =\n anyRequest.routeOptions?.handler || anyRequest.context?.handler;\n\n const handlerName = handler?.name.startsWith('bound ')\n ? handler.name.substring(6)\n : handler?.name;\n const spanName = `${FastifyNames.REQUEST_HANDLER} - ${\n handlerName || this.pluginName || ANONYMOUS_NAME\n }`;\n\n const spanAttributes: Attributes = {\n [AttributeNames.PLUGIN_NAME]: this.pluginName,\n [AttributeNames.FASTIFY_TYPE]: FastifyTypes.REQUEST_HANDLER,\n [SEMATTRS_HTTP_ROUTE]: anyRequest.routeOptions\n ? anyRequest.routeOptions.url // since fastify@4.10.0\n : request.routerPath,\n };\n if (handlerName) {\n spanAttributes[AttributeNames.FASTIFY_NAME] = handlerName;\n }\n const span = startSpan(\n reply,\n instrumentation.tracer,\n spanName,\n spanAttributes\n );\n\n const { requestHook } = instrumentation.getConfig();\n if (requestHook) {\n safeExecuteInTheMiddle(\n () => requestHook(span, { request }),\n e => {\n if (e) {\n instrumentation._diag.error('request hook failed', e);\n }\n },\n true\n );\n }\n\n return context.with(trace.setSpan(context.active(), span), () => {\n done();\n });\n };\n }\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAAgF;AAChF,8CAA8D;AAC9D,oEAIwC;AACxC,8EAA0E;AAQ1E,2CAA+C;AAC/C,2DAIgC;AAGhC,mCAIiB;AACjB,kBAAkB;AAClB,uCAA0D;AAE7C,QAAA,cAAc,GAAG,WAAW,CAAC;AAE1C;;;;GAIG;AACH,MAAa,sBAAuB,SAAQ,qCAAiD;IAC3F,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI;QACF,OAAO;YACL,IAAI,qDAAmC,CACrC,SAAS,EACT,CAAC,YAAY,CAAC,EACd,aAAa,CAAC,EAAE;gBACd,OAAO,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;YAC/C,CAAC,CACF;SACF,CAAC;IACJ,CAAC;IAEO,cAAc;QACpB,MAAM,eAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,SAAS,SAAS,CACvB,OAAuB,EACvB,KAAmB,EACnB,IAA6B;YAE7B,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,EAAE;gBAChC,OAAO,IAAI,EAAE,CAAC;aACf;YACD,eAAe,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC;YAEnE,MAAM,UAAU,GAAG,OAAc,CAAC;YAElC,MAAM,WAAW,GAAG,IAAA,qBAAc,EAAC,aAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACrD,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY;gBACvC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,uBAAuB;gBACrD,CAAC,CAAC,OAAO,CA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,CAAC;CACF;AAzPD,wDAyPC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, Attributes, SpanStatusCode, trace } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\nimport type {\n HookHandlerDoneFunction,\n FastifyInstance,\n FastifyRequest,\n FastifyReply,\n FastifyErrorCodes,\n} from 'fastify';\nimport { hooksNamesToWrap } from './constants';\nimport {\n AttributeNames,\n FastifyNames,\n FastifyTypes,\n} from './enums/AttributeNames';\nimport type { HandlerOriginal, PluginFastifyReply } from './internal-types';\nimport type { FastifyInstrumentationConfig } from './types';\nimport {\n endSpan,\n safeExecuteInTheMiddleMaybePromise,\n startSpan,\n} from './utils';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nexport const ANONYMOUS_NAME = 'anonymous';\n\n/**\n * Fastify instrumentation for OpenTelemetry\n * @deprecated This instrumentation is deprecated in favor of the official instrumentation package `@fastify/otel`,\n * which is maintained by the fastify authors.\n */\nexport class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumentationConfig> {\n constructor(config: FastifyInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n init() {\n return [\n new InstrumentationNodeModuleDefinition(\n 'fastify',\n ['>=3.0.0 <6'],\n moduleExports => {\n return this._patchConstructor(moduleExports);\n }\n ),\n ];\n }\n\n private _hookOnRequest() {\n const instrumentation = this;\n return function onRequest(\n request: FastifyRequest,\n reply: FastifyReply,\n done: HookHandlerDoneFunction\n ) {\n if (!instrumentation.isEnabled()) {\n return done();\n }\n instrumentation._wrap(reply, 'send', instrumentation._patchSend());\n\n const anyRequest = request as any;\n\n const rpcMetadata = getRPCMetadata(context.active());\n const routeName = anyRequest.routeOptions\n ? anyRequest.routeOptions.url // since fastify@4.10.0\n : request.routerPath;\n if (routeName && rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = routeName;\n }\n done();\n };\n }\n\n private _wrapHandler(\n pluginName: string,\n hookName: string,\n original: (...args: unknown[]) => Promise<unknown>,\n syncFunctionWithDone: boolean\n ): () => Promise<unknown> {\n const instrumentation = this;\n this._diag.debug('Patching fastify route.handler function');\n\n return function (this: any, ...args: unknown[]): Promise<unknown> {\n if (!instrumentation.isEnabled()) {\n return original.apply(this, args);\n }\n\n const name = original.name || pluginName || ANONYMOUS_NAME;\n const spanName = `${FastifyNames.MIDDLEWARE} - ${name}`;\n\n const reply = args[1] as PluginFastifyReply;\n\n const span = startSpan(reply, instrumentation.tracer, spanName, {\n [AttributeNames.FASTIFY_TYPE]: FastifyTypes.MIDDLEWARE,\n [AttributeNames.PLUGIN_NAME]: pluginName,\n [AttributeNames.HOOK_NAME]: hookName,\n });\n\n const origDone =\n syncFunctionWithDone &&\n (args[args.length - 1] as HookHandlerDoneFunction);\n if (origDone) {\n args[args.length - 1] = function (\n ...doneArgs: Parameters<HookHandlerDoneFunction>\n ) {\n endSpan(reply);\n origDone.apply(this, doneArgs);\n };\n }\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddleMaybePromise(\n () => {\n return original.apply(this, args);\n },\n err => {\n if (err instanceof Error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n });\n span.recordException(err);\n }\n // async hooks should end the span as soon as the promise is resolved\n if (!syncFunctionWithDone) {\n endSpan(reply);\n }\n }\n );\n });\n };\n }\n\n private _wrapAddHook(): (\n original: FastifyInstance['addHook']\n ) => () => FastifyInstance {\n const instrumentation = this;\n this._diag.debug('Patching fastify server.addHook function');\n\n return function (\n original: FastifyInstance['addHook']\n ): () => FastifyInstance {\n return function wrappedAddHook(this: any, ...args: any) {\n const name = args[0] as string;\n const handler = args[1] as HandlerOriginal;\n const pluginName = this.pluginName;\n if (!hooksNamesToWrap.has(name)) {\n return original.apply(this, args);\n }\n\n const syncFunctionWithDone =\n typeof args[args.length - 1] === 'function' &&\n handler.constructor.name !== 'AsyncFunction';\n\n return original.apply(this, [\n name,\n instrumentation._wrapHandler(\n pluginName,\n name,\n handler,\n syncFunctionWithDone\n ),\n ] as never);\n };\n };\n }\n\n private _patchConstructor(moduleExports: {\n fastify: () => FastifyInstance;\n errorCodes: FastifyErrorCodes | undefined;\n }): () => FastifyInstance {\n const instrumentation = this;\n\n function fastify(this: FastifyInstance, ...args: any) {\n const app: FastifyInstance = moduleExports.fastify.apply(this, args);\n app.addHook('onRequest', instrumentation._hookOnRequest());\n app.addHook('preHandler', instrumentation._hookPreHandler());\n\n instrumentation._wrap(app, 'addHook', instrumentation._wrapAddHook());\n\n return app;\n }\n\n if (moduleExports.errorCodes !== undefined) {\n fastify.errorCodes = moduleExports.errorCodes;\n }\n fastify.fastify = fastify;\n fastify.default = fastify;\n return fastify;\n }\n\n private _patchSend() {\n const instrumentation = this;\n this._diag.debug('Patching fastify reply.send function');\n\n return function patchSend(\n original: () => FastifyReply\n ): () => FastifyReply {\n return function send(this: FastifyReply, ...args: any) {\n const maybeError: any = args[0];\n\n if (!instrumentation.isEnabled()) {\n return original.apply(this, args);\n }\n\n return safeExecuteInTheMiddle<FastifyReply>(\n () => {\n return original.apply(this, args);\n },\n err => {\n if (!err && maybeError instanceof Error) {\n err = maybeError;\n }\n endSpan(this, err);\n }\n );\n };\n };\n }\n\n private _hookPreHandler() {\n const instrumentation = this;\n this._diag.debug('Patching fastify preHandler function');\n\n return function preHandler(\n this: any,\n request: FastifyRequest,\n reply: FastifyReply,\n done: HookHandlerDoneFunction\n ) {\n if (!instrumentation.isEnabled()) {\n return done();\n }\n const anyRequest = request as any;\n\n const handler =\n anyRequest.routeOptions?.handler || anyRequest.context?.handler;\n\n const handlerName = handler?.name.startsWith('bound ')\n ? handler.name.substring(6)\n : handler?.name;\n const spanName = `${FastifyNames.REQUEST_HANDLER} - ${\n handlerName || this.pluginName || ANONYMOUS_NAME\n }`;\n\n const spanAttributes: Attributes = {\n [AttributeNames.PLUGIN_NAME]: this.pluginName,\n [AttributeNames.FASTIFY_TYPE]: FastifyTypes.REQUEST_HANDLER,\n [SEMATTRS_HTTP_ROUTE]: anyRequest.routeOptions\n ? anyRequest.routeOptions.url // since fastify@4.10.0\n : request.routerPath,\n };\n if (handlerName) {\n spanAttributes[AttributeNames.FASTIFY_NAME] = handlerName;\n }\n const span = startSpan(\n reply,\n instrumentation.tracer,\n spanName,\n spanAttributes\n );\n\n const { requestHook } = instrumentation.getConfig();\n if (requestHook) {\n safeExecuteInTheMiddle(\n () => requestHook(span, { request }),\n e => {\n if (e) {\n instrumentation._diag.error('request hook failed', e);\n }\n },\n true\n );\n }\n\n return context.with(trace.setSpan(context.active(), span), () => {\n done();\n });\n };\n }\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.44.0";
1
+ export declare const PACKAGE_VERSION = "0.44.2";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-fastify";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -17,6 +17,6 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.PACKAGE_VERSION = '0.44.0';
20
+ exports.PACKAGE_VERSION = '0.44.2';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-fastify';
22
22
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.44.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-fastify';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.44.2';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-fastify';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-fastify",
3
- "version": "0.44.0",
3
+ "version": "0.44.2",
4
4
  "description": "OpenTelemetry instrumentation for `fastify` http web application framework",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -46,8 +46,8 @@
46
46
  "@fastify/express": "^3.0.0",
47
47
  "@opentelemetry/api": "^1.3.0",
48
48
  "@opentelemetry/context-async-hooks": "^1.8.0",
49
- "@opentelemetry/contrib-test-utils": "^0.45.0",
50
- "@opentelemetry/instrumentation-http": "^0.57.0",
49
+ "@opentelemetry/contrib-test-utils": "^0.45.1",
50
+ "@opentelemetry/instrumentation-http": "^0.57.1",
51
51
  "@opentelemetry/sdk-trace-base": "^1.8.0",
52
52
  "@opentelemetry/sdk-trace-node": "^1.8.0",
53
53
  "@types/express": "4.17.21",
@@ -63,9 +63,9 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@opentelemetry/core": "^1.8.0",
66
- "@opentelemetry/instrumentation": "^0.57.0",
66
+ "@opentelemetry/instrumentation": "^0.57.1",
67
67
  "@opentelemetry/semantic-conventions": "^1.27.0"
68
68
  },
69
69
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify#readme",
70
- "gitHead": "3ef5205e5353010184c69ff7b9f0f4830f0932de"
70
+ "gitHead": "1eb77007669bae87fe5664d68ba6533b95275d52"
71
71
  }