Added type definitions for elastic-apm-node

This commit is contained in:
Shahaed Hasan
2018-09-26 17:42:19 -05:00
parent 38b2363a66
commit b6a82b105b
5 changed files with 154 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import {
Agent,
start
} from 'elastic-apm-node';
const agent: Agent = start({
serviceName: '',
secretToken: '',
serverUrl: ''
});
const started: boolean = agent.isStarted();
function testCallbacks() {
const testError: Error = new Error("Test Error");
agent.captureError(testError, {error: "test"}, (err: Error) => err = testError);
agent.captureError(testError, {error: "test"});
agent.captureError(testError);
agent.addFilter((payload: any) => {
return payload;
});
agent.handleUncaughtExceptions((err: Error) => err = testError);
agent.flush((test: any) => test);
}
const customContext: boolean = agent.setCustomContext({
id: "test id",
username: "test user",
email: "testEmail@test.com"
});
const userContext: boolean = agent.setUserContext({
id: "test id",
username: "test user",
email: "testEmail@test.com"
});
const transactionName: any = agent.setTransactionName("new name");
const tags: any = agent.setTag("name", "value");
const addedTags: any = agent.addTags({name: "value"});
const startSpan: any = agent.startSpan();
const secondStartSpan: any = agent.startSpan("name", 13);
const transaction = agent.startTransaction();

75
types/elastic-apm-node/index.d.ts vendored Normal file
View File

@@ -0,0 +1,75 @@
// Type definitions for Elastic APM Node.js Agent 1.x
// Project: https://www.elastic.co/solutions/apm
// Definitions by: Shahaed Hasan <https://github.com/shahaed>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
export = a;
declare const a: a.Agent;
declare namespace a {
interface Agent {
currentTransaction: any;
logger: any;
start(opts?: AgentOptions): Agent;
isStarted(): boolean;
addFilter(filter: (payload: any) => any): void;
setUserContext(context: Context): boolean;
setCustomContext(context: any): boolean;
setTag(name: string, value: string): any;
addTags(tags: any): any;
captureError(error: Error | string | object, options?: object, callback?: (err?: any) => any): void;
startTransaction(name?: string, type?: string): any;
endTransaction(result?: any): any;
setTransactionName(name: string): any;
startSpan(name?: string, type?: any): any;
handleUncaughtExceptions(callback?: (err: Error) => any): any;
flush(callback?: any): any;
lambda(type: any, handler?: any): any;
}
interface AgentOptions {
serviceName?: string;
secretToken?: string;
serverUrl?: string;
verifyServerCert?: boolean;
serviceVersion?: string;
active?: boolean;
instrument?: boolean;
asyncHooks?: boolean;
ignoreUrls?: Array<RegExp | string>;
ignoreUserAgents?: Array<RegExp | string>;
captureBody?: string;
errorOnAbortedRequests?: boolean;
abortedErrorThreshold?: number;
transactionSampleRate?: number;
hostname?: string;
frameworkName?: string;
frameworkVersion?: string;
logLevel?: string;
logger?: any;
captureExceptions?: boolean;
captureErrorLogStackTraces?: string;
captureSpanStackTraces?: boolean;
sourceLinesErrorAppFrames?: number;
sourceLinesErrorLibraryFrames?: number;
sourceLinesSpanAppFrames?: number;
sourceLinesSpanLibraryFrames?: number;
errorMessageMaxLength?: number;
stackTraceLimit?: number;
transactionMaxSpans?: number;
flushInterval?: number;
serverTimeout?: number;
maxQueueSize?: number;
filterHttpHeaders?: boolean;
disableInstrumentations?: string;
}
interface Context {
id?: string;
username?: string;
email?: string;
}
}

2
types/elastic-apm-node/start.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
import * as agent from './';
export = agent;

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"elastic-apm-node-tests.ts",
"start.d.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}