kobp
Version:
Koa Boilerplate with MikroORM
62 lines (61 loc) • 1.56 kB
TypeScript
import { KobpServiceContext } from '..';
export interface TracerConfig {
/**
* By default tracer will always prefers `x-tracerId` explicitly provided in the request header.
* If not provided. It will fallback to use `traceIdMaker()` to create one.
*
* Default to `x-traceId`
*/
requestTraceHeaderKey: string;
/**
* Default to `<timestamp(radix:32)> + '.' + <random(4bytes).hex>.substr(4)`
*/
traceIdMaker: (currentKey: string) => string;
}
/**
* Tracer Usage
*
* Extends this class. And initialize this with beforeFork middlewares
*
* Example:
* ```ts
*
* class CustomTracer extends Tracer {
* ** my own functions **
* }
*
* makeServer(
* ...,
* {
* middlewareBeforeFork: (app) => {
* app.use((ctx, next) => {
* ctx.tracer = new CustomTracer(ctx)
* await next()
* })
* },
* middlewareAfterFork: (app) => {
* app.use(Tracer.attach('tracer'))
* }
* }
* )
* ```
*/
export declare class Tracer {
/**
* Access this parameter to customize the Tracer behavior
*/
static _config: TracerConfig;
/**
* Update tracer's configuration. You should call this only once.
*
* @param config
*/
static config(config: Partial<TracerConfig>): void;
readonly traceId: string;
readonly context: KobpServiceContext;
/**
*
* will be called automatically when the context is created
*/
constructor(ctx: KobpServiceContext);
}