🤖 Merge PR #65487 Add newrelic obfuscateSql, setErrorGroupCallback & update noticeError by @wrumsby

* Add newrelic.obfuscateSql, newrelic.setErrorGroupCallback and add optional expected param to newrelic.noticeError

* refactor: update code to follow project linting rules
This commit is contained in:
Walter Rumsby
2023-05-19 11:24:59 +12:00
committed by GitHub
parent f956ee1360
commit b8c4a2cd14
2 changed files with 37 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for newrelic 9.13
// Type definitions for newrelic 9.14
// Project: https://github.com/newrelic/node-newrelic
// Definitions by: Matt R. Wilson <https://github.com/mastermatt>
// Brooks Patton <https://github.com/brookspatton>
@@ -97,6 +97,13 @@ export function addCustomSpanAttribute(key: string, value: string | number | boo
*/
export function addCustomSpanAttributes(atts: { [key: string]: string | number | boolean }): void;
/**
* Send errors to New Relic that you've already handled yourself.
*
* NOTE: Errors that are recorded using this method do _not_ obey the `ignore_status_codes` configuration.
*/
export function noticeError(error: Error, expected?: boolean): void;
/**
* Send errors to New Relic that you've already handled yourself.
*
@@ -104,7 +111,22 @@ export function addCustomSpanAttributes(atts: { [key: string]: string | number |
*
* Optional. Any custom attributes to be displayed in the New Relic UI.
*/
export function noticeError(error: Error, customAttributes?: { [key: string]: string | number | boolean }): void;
export function noticeError(error: Error, customAttributes?: { [key: string]: string | number | boolean }, expected?: boolean): void;
/**
* This method lets you define a custom callback to generate error group names, which will be used by
* errors inbox to group similar errors together via the error.group.name agent attribute.
*
* Calling this function multiple times will replace previously defined versions of this callback function.
*/
export function setErrorGroupCallback(callback: (metadata: {
customAttributes: { [key: string]: string | number | boolean };
'request.uri': string;
'http.statusCode': string;
'http.method': string;
error?: Error;
'error.expected': boolean;
}) => string): void;
/**
* Sends an application log message to New Relic. The agent already
@@ -400,6 +422,11 @@ export function getTraceMetadata(): TraceMetadata;
*/
export function setLambdaHandler<T extends (...args: any[]) => any>(handler: T): T;
/**
* Obfuscates SQL for a given database engine.
*/
export function obfuscateSql(sql: string, dialect?: 'mysql' | 'postgres' | 'cassandra' | 'oracle'): string;
export interface Instrument {
(opts: { moduleName: string; onRequire: () => void; onError?: ((err: Error) => void) | undefined }): void;
(moduleName: string, onRequire: () => void, onError?: (err: Error) => void): void;

View File

@@ -30,6 +30,12 @@ newrelic.noticeError(Error('Oh no!')); // $ExpectType void
newrelic.noticeError(Error('Oh no!'), { foo: 'bar' }); // $ExpectType void
newrelic.noticeError(Error('Oh no!'), { foo: 42 }); // $ExpectType void
newrelic.noticeError(Error('Oh no!'), { foo: true }); // $ExpectType void
newrelic.noticeError(Error('Oh no!'), true); // $ExpectType void
newrelic.noticeError(Error('Oh no!'), false); // $ExpectType void
newrelic.noticeError(Error('Oh no!'), { foo: 'bar' }, true); // $ExpectType void
newrelic.noticeError(Error('Oh no!'), { foo: 42 }, false); // $ExpectType void
newrelic.setErrorGroupCallback((errMetadata) => errMetadata['error.expected'] ? 'Expected Error' : 'Unexpected Error'); // $ExpectType void
newrelic.recordLogEvent({ message: '' }); // $ExpectType void
newrelic.recordLogEvent({ message: '', timestamp: 1 }); // $ExpectType void
@@ -136,3 +142,5 @@ newrelic.setLambdaHandler(() => void 0); // $ExpectType () => undefined
newrelic.setLambdaHandler((event: unknown, context: unknown) => ({ statusCode: 200, body: "Hello!" })); // $ExpectType (event: unknown, context: unknown) => { statusCode: number; body: string; }
// @ts-expect-error
newrelic.setLambdaHandler({some: "object"});
newrelic.obfuscateSql('SELECT * FROM USERS', 'postgres'); // $ExpectType string