From e2f28fb92b32d552f0cac61c162f680a2945ff33 Mon Sep 17 00:00:00 2001 From: Michael Bond Date: Sun, 16 Dec 2018 07:44:39 -0500 Subject: [PATCH 1/3] Add type support for NewRelic's AWS Lambda monitoring --- types/newrelic/index.d.ts | 9 +++++++++ types/newrelic/newrelic-tests.ts | 2 ++ 2 files changed, 11 insertions(+) diff --git a/types/newrelic/index.d.ts b/types/newrelic/index.d.ts index a5fd434d99..3600b45d88 100644 --- a/types/newrelic/index.d.ts +++ b/types/newrelic/index.d.ts @@ -2,6 +2,7 @@ // Project: http://github.com/newrelic/node-newrelic // Definitions by: Matt R. Wilson // Brooks Patton +// Michael Bond // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api @@ -321,6 +322,14 @@ export const instrumentMessages: Instrument; export function shutdown(cb?: (error?: Error) => void): void; export function shutdown(options?: { collectPendingData?: boolean, timeout?: number }, cb?: (error?: Error) => void): void; +/** + * Wraps an AWS Lambda function with NewRelic instrumentation and returns the value of the handler + * + * @param handler a callback function whose value is returned from setLambdaHandler + * @returns the value returned by handler + */ +export function setLambdaHandler(handler: (...args: any[]) => T): T; + export interface Instrument { (opts: { moduleName: string, onRequire: () => void, onError?: (err: Error) => void }): void; (moduleName: string, onRequire: () => void, onError?: (err: Error) => void): void; diff --git a/types/newrelic/newrelic-tests.ts b/types/newrelic/newrelic-tests.ts index 29eabfeb21..9f57376a98 100644 --- a/types/newrelic/newrelic-tests.ts +++ b/types/newrelic/newrelic-tests.ts @@ -104,3 +104,5 @@ newrelic.shutdown({ collectPendingData: true, timeout: 3000 }, (err) => { newrelic.shutdown((err) => { const error: Error | undefined = err; }); + +newrelic.setLambdaHandler(() => void 0); // $ExpectType void From f4ffe891795c3c0fd741d665a4423dd5b2e4f221 Mon Sep 17 00:00:00 2001 From: Michael Bond Date: Sun, 16 Dec 2018 07:53:21 -0500 Subject: [PATCH 2/3] Fix test --- types/newrelic/newrelic-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/newrelic/newrelic-tests.ts b/types/newrelic/newrelic-tests.ts index 9f57376a98..9bc909d57c 100644 --- a/types/newrelic/newrelic-tests.ts +++ b/types/newrelic/newrelic-tests.ts @@ -105,4 +105,4 @@ newrelic.shutdown((err) => { const error: Error | undefined = err; }); -newrelic.setLambdaHandler(() => void 0); // $ExpectType void +newrelic.setLambdaHandler(() => void 0); // $ExpectType undefined From 641c9b6a1ae6c42883934297e30e029b92d55593 Mon Sep 17 00:00:00 2001 From: Michael Bond Date: Sun, 16 Dec 2018 19:03:02 -0500 Subject: [PATCH 3/3] Update version per PR Request. --- types/newrelic/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/newrelic/index.d.ts b/types/newrelic/index.d.ts index 3600b45d88..10700022df 100644 --- a/types/newrelic/index.d.ts +++ b/types/newrelic/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for newrelic 3.4 +// Type definitions for newrelic 4.11 // Project: http://github.com/newrelic/node-newrelic // Definitions by: Matt R. Wilson // Brooks Patton