diff --git a/types/newrelic/index.d.ts b/types/newrelic/index.d.ts index 83b6e409dc..f6c54f5a4b 100644 --- a/types/newrelic/index.d.ts +++ b/types/newrelic/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for newrelic 2.7 +// Type definitions for newrelic 3.3 // Project: http://github.com/newrelic/node-newrelic // Definitions by: Matt R. Wilson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -147,6 +147,23 @@ declare namespace newrelic { */ getBrowserTimingHeader(): string; + /** + * Instrument a particular method to improve visibility into a transaction, + * or optionally turn it into a metric. + * + * The name defines a name for the segment. This name will be visible in transaction traces and + * as a new metric in the New Relic UI. + * The record flag defines whether the segment should be recorded as a metric. + * The handler is the function you want to track as a segment. + * The optional callback is a function passed to the handler to fire after its work is done. + * + * The agent begins timing the segment when startSegment is called. + * The segment is ended when either the handler finishes executing, or callback is fired, if it is provided. + * If a promise is returned from the handler, the segment's ending will be tied to that promise resolving or rejecting. + */ + startSegment>(name: string, record: boolean, handler: T): T; + startSegment any>(name: string, record: boolean, handler: (cb?: C) => T, callback?: C): T; + /** * Instrument a particular callback to improve visibility into a transaction. * @@ -157,6 +174,9 @@ declare namespace newrelic { * * The agent begins timing the segment when createTracer is called, and ends the segment when the callback * defined by the callback argument finishes executing. + * + * @deprecated + * This method has been deprecated in favor of newrelic.startSegment() */ createTracer any>(name: string, handle: T): T; diff --git a/types/newrelic/newrelic-tests.ts b/types/newrelic/newrelic-tests.ts index 73cd53cc78..3f99152c66 100644 --- a/types/newrelic/newrelic-tests.ts +++ b/types/newrelic/newrelic-tests.ts @@ -29,6 +29,12 @@ newrelic.addIgnoringRule(/^[0-9]+$/); // $ExpectType void newrelic.getBrowserTimingHeader(); // $ExpectType string +newrelic.startSegment('foo', false, () => "bar"); // $ExpectType string +newrelic.startSegment('foo', false, () => "bar", () => "baz"); // $ExpectType string +newrelic.startSegment('foo', false, Promise.all([5, 7])).then(([a, b]: [number, number]) => { + console.log(a, b); +}); + const wrappedFn = newrelic.createTracer("foo", (x: number) => { return x * x; });