Skip to content

Commit

Permalink
Removed deprecated properties usage
Browse files Browse the repository at this point in the history
  • Loading branch information
seidelmartin committed Sep 12, 2023
1 parent b10224b commit aa826a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
"@opentelemetry/sdk-trace-node": "^1.8.0",
"@types/express": "4.17.17",
"@types/mocha": "7.0.2",
"@types/node": "18.6.5",
"fastify": "4.18.0",
"@types/node": "18.15.3",
"fastify": "4.23.0",
"mocha": "7.2.0",
"nyc": "15.1.0",
"rimraf": "5.0.1",
"ts-mocha": "10.0.0",
"typescript": "4.4.4"
"typescript": "5.2.2"
},
"dependencies": {
"@opentelemetry/core": "^1.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ export class FastifyInstrumentation extends InstrumentationBase {
}
instrumentation._wrap(reply, 'send', instrumentation._patchSend());

const anyRequest = (request as any);

const rpcMetadata = getRPCMetadata(context.active());
const routeName = request.routerPath;
const routeName = anyRequest.routeOptions?.config?.url || request.routerPath;
if (routeName && rpcMetadata?.type === RPCType.HTTP) {
rpcMetadata.route = routeName;
}
Expand Down Expand Up @@ -177,22 +179,22 @@ export class FastifyInstrumentation extends InstrumentationBase {
const handler = args[1] as HandlerOriginal;
const pluginName = this.pluginName;
if (applicationHookNames.includes(name)) {
return original.apply(this, [name as any, handler]);
return original.apply(this, [name, handler] as never);
}

const syncFunctionWithDone =
typeof args[args.length - 1] === 'function' &&
handler.constructor.name !== 'AsyncFunction';

return original.apply(this, [
name as any,
name,
instrumentation._wrapHandler(
pluginName,
name,
handler,
syncFunctionWithDone
),
]);
] as never);
};
};
}
Expand Down Expand Up @@ -260,16 +262,19 @@ export class FastifyInstrumentation extends InstrumentationBase {
if (!instrumentation.isEnabled()) {
return done();
}
const requestContext = (request as any).context || {};
const handlerName = (requestContext.handler?.name || '').substr(6);
const anyRequest = (request as any);

const handler = anyRequest.routeOptions?.handler || anyRequest.context?.handler || {};

const handlerName = handler?.name.substr(6);
const spanName = `${FastifyNames.REQUEST_HANDLER} - ${
handlerName || ANONYMOUS_NAME
}`;

const spanAttributes: SpanAttributes = {
[AttributeNames.PLUGIN_NAME]: this.pluginName,
[AttributeNames.FASTIFY_TYPE]: FastifyTypes.REQUEST_HANDLER,
[SemanticAttributes.HTTP_ROUTE]: request.routerPath,
[SemanticAttributes.HTTP_ROUTE]: anyRequest.routeOptions?.config?.url || request.routerPath,
};
if (handlerName) {
spanAttributes[AttributeNames.FASTIFY_NAME] = handlerName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('fastify', () => {
async function subsystem(fastify: FastifyInstance) {
fastify.addHook(
'onRequest',
async (
(
req: FastifyRequest,
res: FastifyReply,
next: HookHandlerDoneFunction
Expand Down

0 comments on commit aa826a0

Please sign in to comment.