@revai-care/instrumentation-adonisjs-6
Version:
OpenTelemetry instrumentation for Adonisjs server side applications framework
115 lines (114 loc) • 3.92 kB
TypeScript
import { InstrumentationBase, InstrumentationConfig } from '@opentelemetry/instrumentation';
/**
* Attribute name for the HTTP path of the request.
*/
export declare const ATTR_HTTP_PATH = "http.path";
/**
* AdonisJS instrumentation for OpenTelemetry.
*/
export declare class AdonisInstrumentation extends InstrumentationBase<InstrumentationConfig> {
/**
* The component name for AdonisJS.
*/
static readonly COMPONENT = "@adonisjs/core";
/**
* Common attributes to be added to all spans.
*/
static readonly COMMON_ATTRIBUTES: {
component: string;
"adonisjs.version": string;
};
constructor(config?: InstrumentationConfig);
init(): void;
/**
* Applies patches to AdonisJS core modules.
*/
private applyPatch;
/**
* Creates a wrapper for the `Server.prototype.use` method.
*
* @returns The wrapped `use` method.
*/
private createWrapUse;
/**
* Creates a wrapper for the `Router.prototype.named` method.
*
* @returns The wrapped `named` method.
*/
private createWrapRouterNamed;
/**
* Creates a wrapper for the `Router.prototype.route` method.
*
* @returns The wrapped `route` method.
*/
private createWrapRouteHandler;
/**
* Creates a wrapper for the `ExceptionHandler.prototype.report` method.
*
* @returns The wrapped `report` method.
*/
private createWrapReportError;
/**
* Creates a wrapper for request handler methods.
*
* @param nameSpace The namespace of the request handler.
* @param methodName The name of the request handler method.
* @returns The wrapped request handler method.
*/
private createWrapRequestHandler;
/**
* Creates a wrapper for middleware handler methods.
*
* @param nameSpace The namespace of the middleware handler.
* @returns The wrapped middleware handler method.
*/
private createWrapMiddlewareHandler;
/**
* Creates a wrapper for server middleware handler methods.
*
* @param nameSpace The namespace of the middleware handler.
* @returns The wrapped middleware handler method.
*/
private createWrapServerMiddlewareHandler;
/**
* Wraps a request handler function to create a span and handle errors.
*
* @private
* @async
* @param {Tracer} tracer The OpenTelemetry tracer.
* @param {() => Promise<any>} handlerCb The request handler callback function.
* @param {HttpContext} ctx The AdonisJS HTTP context.
* @param {string} spanName The name of the span.
* @param {string} type The type of the handler (e.g., 'handler', 'middleware').
* @param {string} nameSpace The namespace of the handler.
* @param {string} methodName The name of the handler method.
* @returns {ReturnType<typeof handlerCb>} The result of the handler callback.
*/
private wrappedRequestHandler;
/**
* Ensures that a method on an object is wrapped with a given wrapper function.
* If the method is already wrapped, it unwraps it before wrapping again.
*
* @private
* @template T The type of the object.
* @param {T} obj The object containing the method to wrap.
* @param {keyof T} methodName The name of the method to wrap.
* @param {(original: any) => any} wrapper The wrapper function.
*/
private ensureWrapped;
/**
* Generates a span name for a request handler based on the HTTP context.
*
* @private
* @param {HttpContext} ctx The AdonisJS HTTP context.
* @returns {string} The generated span name.
*/
private getRequestHandlerSpanName;
/**
* Retrieves the version of the AdonisJS core package.
*
* @private
* @returns {string} The AdonisJS core version, or 'unknown' if retrieval fails.
*/
private getAdonisVersion;
}