diff --git a/types/newrelic/index.d.ts b/types/newrelic/index.d.ts index c010db1f5e..df8b734d70 100644 --- a/types/newrelic/index.d.ts +++ b/types/newrelic/index.d.ts @@ -1,10 +1,11 @@ -// Type definitions for newrelic 5.11 +// Type definitions for newrelic 6.2 // Project: http://github.com/newrelic/node-newrelic // Definitions by: Matt R. Wilson // Brooks Patton // Michael Bond // Kyle Scully // Kenneth Aasan +// Jon Flaishans // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api @@ -308,6 +309,12 @@ export const instrument: Instrument; */ export const instrumentDatastore: Instrument; +/** + * The instrumentLoadedModule method allows you to add stock instrumentation to specific modules + * in situations where it's impossible to have require('newrelic'); as the first line of your app's main module. + */ +export function instrumentLoadedModule(moduleName: string, moduleInstance: any): boolean; + /** * Sets an instrumentation callback for a web framework module. * @@ -334,6 +341,19 @@ export function shutdown( cb?: (error?: Error) => void, ): void; +/** + * Returns key/value pairs which can be used to link traces or entities. + * It will only contain items with meaningful values. For instance, if distributed tracing is disabled, + * trace.id will not be included. + */ +export function getLinkingMetadata(omitSupportability?: boolean): LinkingMetadata; + +/** + * Returns and object containing the current trace ID and span ID. + * This API requires distributed tracing to be enabled or an empty object will be returned. + */ +export function getTraceMetadata(): TraceMetadata; + /** * Wraps an AWS Lambda function with NewRelic instrumentation and returns the value of the handler * @@ -388,3 +408,51 @@ export interface TransactionHandle { */ acceptDistributedTracePayload(payload: DistributedTracePayload): void; } + +export interface LinkingMetadata { + /** + * The current trace ID + */ + 'trace.id'?: string; + + /** + * The current span ID + */ + 'span.id'?: string; + + /** + * The application name specified in the connect request as + * app_name. If multiple application names are specified this will only be + * the first name + */ + 'entity.name': string; + + /** + * The string "SERVICE" + */ + 'entity.type': string; + + /** + * The entity ID returned in the connect reply as entity_guid + */ + 'entity.guid'?: string; + + /** + * The hostname as specified in the connect request as + * utilization.full_hostname. If utilization.full_hostname is null or empty, + * this will be the hostname specified in the connect request as host. + */ + hostname: string; +} + +export interface TraceMetadata { + /** + * The current trace ID + */ + traceId?: string; + + /** + * The current span ID + */ + spanId?: string; +} diff --git a/types/newrelic/newrelic-tests.ts b/types/newrelic/newrelic-tests.ts index b2c7069ba8..efa47f17c6 100644 --- a/types/newrelic/newrelic-tests.ts +++ b/types/newrelic/newrelic-tests.ts @@ -89,6 +89,7 @@ newrelic.recordCustomEvent('my_event', { newrelic.instrument('foo', () => {}); // $ExpectType void newrelic.instrumentDatastore('foo', () => {}, (err: Error) => {}); +newrelic.instrumentLoadedModule('foo', () => {}); // $ExpectType boolean newrelic.instrumentWebframework({ moduleName: 'foo', onRequire: () => {}, @@ -112,4 +113,8 @@ newrelic.shutdown(err => { const error: Error | undefined = err; }); +newrelic.getLinkingMetadata(); +newrelic.getLinkingMetadata(true); +newrelic.getTraceMetadata(); + newrelic.setLambdaHandler(() => void 0); // $ExpectType undefined