@lokalise/fastify-extras
Version:
Opinionated set of fastify plugins, commonly used in Lokalise
51 lines (50 loc) • 2.6 kB
TypeScript
import type { TransactionObservabilityManager } from '@lokalise/node-core';
import type { FastifyPluginCallback } from 'fastify';
import type { getTransaction as GetTransaction, setControllerName as SetControllerName, setUserID as SetUserID, shutdown as Shutdown, startBackgroundTransaction as startBackgroundTransactionType } from 'newrelic';
interface Newrelic {
startBackgroundTransaction: typeof startBackgroundTransactionType;
shutdown: typeof Shutdown;
getTransaction: typeof GetTransaction;
addCustomAttribute(key: string, value: string | number | boolean): void;
addCustomAttributes(atts: {
[key: string]: string | number | boolean;
}): void;
setUserID: typeof SetUserID;
setControllerName: typeof SetControllerName;
}
declare module 'fastify' {
interface FastifyInstance {
newrelicTransactionManager: NewRelicTransactionManager;
}
}
export interface NewRelicTransactionManagerOptions {
isEnabled: boolean;
}
export declare class NewRelicTransactionManager implements TransactionObservabilityManager {
readonly newrelic?: Newrelic;
private readonly isEnabled;
private readonly transactionMap;
private constructor();
static create(isNewRelicEnabled: boolean): Promise<NewRelicTransactionManager>;
static createDisabled(): NewRelicTransactionManager;
addCustomAttribute(attrName: string, attrValue: string | number | boolean): void;
addCustomAttributes(_uniqueTransactionKey: string, atts: {
[p: string]: string | number | boolean;
}): void;
setUserID(userId: string): void;
setControllerName(name: string, action: string): void;
/**
* @param transactionName - used for grouping similar transactions together
* @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions
*/
start(transactionName: string, uniqueTransactionKey: string): void;
/**
* @param transactionName - used for grouping similar transactions together
* @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions *
* @param transactionGroup - group is used for grouping related transactions with different names
*/
startWithGroup(transactionName: string, uniqueTransactionKey: string, transactionGroup: string): void;
stop(uniqueTransactionKey: string): void;
}
export declare const newrelicTransactionManagerPlugin: FastifyPluginCallback<NewRelicTransactionManagerOptions>;
export {};