Skip to main content

RegisterMethodHooks

Allows you to register hooks for a specific method of an instrumented class. These hooks allow extra telemetry actions to be performed on the method.

They can then be passed to the TelemetryPlugin via the TelemetryPluginOptions.

Example

Typescript
const productServiceHooks = registerMethodHooks(ProductService, {    findOne: {        // This will be called before the method is executed        pre: ({ args: [ctx, productId], span }) => {            span.setAttribute('productId', productId);        },        // This will be called after the method is executed        post: ({ result, span }) => {            span.setAttribute('found', !!result);        },    },});
Signature
function registerMethodHooks<T>(target: Type<T>, hooks: MethodHooksForType<T>): MethodHookConfig<T>

Parameters

target

parameterType<T>

hooks

parameterMethodHooksForType<T>
Was this chapter helpful?
Report Issue
Edited Feb 2, 2026·Edit this page