UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

1,579 lines (1,390 loc) 91.2 kB
import { ClientRequest, IncomingMessage, OutgoingMessage, ServerResponse } from "http"; import { LookupFunction } from 'net'; import * as opentracing from "opentracing"; import * as otel from "@opentelemetry/api"; /** * Tracer is the entry-point of the Datadog tracing implementation. */ interface Tracer extends opentracing.Tracer { /** * Add tracer as a named export */ tracer: Tracer; /** * For compatibility with NodeNext + esModuleInterop: false */ default: Tracer; /** * Starts and returns a new Span representing a logical unit of work. * @param {string} name The name of the operation. * @param {tracer.SpanOptions} [options] Options for the newly created span. * @returns {Span} A new Span object. */ startSpan (name: string, options?: tracer.SpanOptions): tracer.Span; /** * Injects the given SpanContext instance for cross-process propagation * within `carrier` * @param {SpanContext} spanContext The SpanContext to inject into the * carrier object. As a convenience, a Span instance may be passed * in instead (in which case its .context() is used for the * inject()). * @param {string} format The format of the carrier. * @param {any} carrier The carrier object. */ inject (spanContext: tracer.SpanContext | tracer.Span, format: string, carrier: any): void; /** * Returns a SpanContext instance extracted from `carrier` in the given * `format`. * @param {string} format The format of the carrier. * @param {any} carrier The carrier object. * @return {SpanContext} * The extracted SpanContext, or null if no such SpanContext could * be found in `carrier` */ extract (format: string, carrier: any): tracer.SpanContext | null; /** * Initializes the tracer. This should be called before importing other libraries. */ init (options?: tracer.TracerOptions): this; /** * Sets the URL for the trace agent. This should only be called _after_ * init() is called, only in cases where the URL needs to be set after * initialization. */ setUrl (url: string): this; /** * Enable and optionally configure a plugin. * @param plugin The name of a built-in plugin. * @param config Configuration options. Can also be `false` to disable the plugin. */ use<P extends keyof Plugins> (plugin: P, config?: Plugins[P] | boolean): this; /** * Returns a reference to the current scope. */ scope (): tracer.Scope; /** * Instruments a function by automatically creating a span activated on its * scope. * * The span will automatically be finished when one of these conditions is * met: * * * The function returns a promise, in which case the span will finish when * the promise is resolved or rejected. * * The function takes a callback as its second parameter, in which case the * span will finish when that callback is called. * * The function doesn't accept a callback and doesn't return a promise, in * which case the span will finish at the end of the function execution. */ trace<T> (name: string, fn: (span: tracer.Span) => T): T; trace<T> (name: string, fn: (span: tracer.Span, done: (error?: Error) => void) => T): T; trace<T> (name: string, options: tracer.TraceOptions & tracer.SpanOptions, fn: (span?: tracer.Span, done?: (error?: Error) => void) => T): T; /** * Wrap a function to automatically create a span activated on its * scope when it's called. * * The span will automatically be finished when one of these conditions is * met: * * * The function returns a promise, in which case the span will finish when * the promise is resolved or rejected. * * The function takes a callback as its last parameter, in which case the * span will finish when that callback is called. * * The function doesn't accept a callback and doesn't return a promise, in * which case the span will finish at the end of the function execution. */ wrap<T = (...args: any[]) => any> (name: string, fn: T): T; wrap<T = (...args: any[]) => any> (name: string, options: tracer.TraceOptions & tracer.SpanOptions, fn: T): T; wrap<T = (...args: any[]) => any> (name: string, options: (...args: any[]) => tracer.TraceOptions & tracer.SpanOptions, fn: T): T; /** * Returns an HTML string containing <meta> tags that should be included in * the <head> of a document to enable correlating the current trace with the * RUM view. Otherwise, it is not possible to associate the trace used to * generate the initial HTML document with a given RUM view. The resulting * HTML document should not be cached as the meta tags are time-sensitive * and are associated with a specific user. * * Note that this feature is currently not supported by the backend and * using it will have no effect. */ getRumData (): string; /** * Links an authenticated user to the current trace. * @param {User} user Properties of the authenticated user. Accepts custom fields. * @returns {Tracer} The Tracer instance for chaining. */ setUser (user: tracer.User): Tracer; appsec: tracer.Appsec; TracerProvider: tracer.opentelemetry.TracerProvider; dogstatsd: tracer.DogStatsD; /** * LLM Observability SDK */ llmobs: tracer.llmobs.LLMObs; /** * @experimental * Provide same functionality as OpenTelemetry Baggage: * https://opentelemetry.io/docs/concepts/signals/baggage/ * * Since the equivalent of OTel Context is implicit in dd-trace-js, * these APIs act on the currently active baggage * * Work with storage('baggage'), therefore do not follow the same continuity as other APIs */ setBaggageItem (key: string, value: string): Record<string, string>; getBaggageItem (key: string): string | undefined; getAllBaggageItems (): Record<string, string>; removeBaggageItem (key: string): Record<string, string>; removeAllBaggageItems (): Record<string, string>; } // left out of the namespace, so it // is doesn't need to be exported for Tracer /** @hidden */ interface Plugins { "aerospike": tracer.plugins.aerospike; "amqp10": tracer.plugins.amqp10; "amqplib": tracer.plugins.amqplib; "apollo": tracer.plugins.apollo; "avsc": tracer.plugins.avsc; "aws-sdk": tracer.plugins.aws_sdk; "azure-functions": tracer.plugins.azure_functions; "azure-service-bus": tracer.plugins.azure_service_bus; "bunyan": tracer.plugins.bunyan; "cassandra-driver": tracer.plugins.cassandra_driver; "child_process": tracer.plugins.child_process; "confluentinc-kafka-javascript": tracer.plugins.confluentinc_kafka_javascript; "connect": tracer.plugins.connect; "couchbase": tracer.plugins.couchbase; "cucumber": tracer.plugins.cucumber; "cypress": tracer.plugins.cypress; "dns": tracer.plugins.dns; "elasticsearch": tracer.plugins.elasticsearch; "express": tracer.plugins.express; "fastify": tracer.plugins.fastify; "fetch": tracer.plugins.fetch; "generic-pool": tracer.plugins.generic_pool; "google-cloud-pubsub": tracer.plugins.google_cloud_pubsub; "google-cloud-vertexai": tracer.plugins.google_cloud_vertexai; "graphql": tracer.plugins.graphql; "grpc": tracer.plugins.grpc; "hapi": tracer.plugins.hapi; "hono": tracer.plugins.hono; "http": tracer.plugins.http; "http2": tracer.plugins.http2; "ioredis": tracer.plugins.ioredis; "iovalkey": tracer.plugins.iovalkey; "jest": tracer.plugins.jest; "kafkajs": tracer.plugins.kafkajs "knex": tracer.plugins.knex; "koa": tracer.plugins.koa; "langchain": tracer.plugins.langchain; "mariadb": tracer.plugins.mariadb; "memcached": tracer.plugins.memcached; "microgateway-core": tracer.plugins.microgateway_core; "mocha": tracer.plugins.mocha; "moleculer": tracer.plugins.moleculer; "mongodb-core": tracer.plugins.mongodb_core; "mongoose": tracer.plugins.mongoose; "mysql": tracer.plugins.mysql; "mysql2": tracer.plugins.mysql2; "net": tracer.plugins.net; "next": tracer.plugins.next; "openai": tracer.plugins.openai; "opensearch": tracer.plugins.opensearch; "oracledb": tracer.plugins.oracledb; "playwright": tracer.plugins.playwright; "pg": tracer.plugins.pg; "pino": tracer.plugins.pino; "prisma": tracer.plugins.prisma; "protobufjs": tracer.plugins.protobufjs; "redis": tracer.plugins.redis; "restify": tracer.plugins.restify; "rhea": tracer.plugins.rhea; "router": tracer.plugins.router; "selenium": tracer.plugins.selenium; "sharedb": tracer.plugins.sharedb; "tedious": tracer.plugins.tedious; "undici": tracer.plugins.undici; "vitest": tracer.plugins.vitest; "winston": tracer.plugins.winston; } declare namespace tracer { export type SpanOptions = opentracing.SpanOptions; export { Tracer }; export interface TraceOptions extends Analyzable { /** * The resource you are tracing. The resource name must not be longer than * 5000 characters. */ resource?: string, /** * The service you are tracing. The service name must not be longer than * 100 characters. */ service?: string, /** * The type of request. */ type?: string /** * An array of span links */ links?: Array<{ context: SpanContext, attributes?: Object }> } /** * Span represents a logical unit of work as part of a broader Trace. * Examples of span might include remote procedure calls or a in-process * function calls to sub-components. A Trace has a single, top-level "root" * Span that in turn may have zero or more child Spans, which in turn may * have children. */ export interface Span extends opentracing.Span { context (): SpanContext; /** * Causally links another span to the current span * @param {SpanContext} context The context of the span to link to. * @param {Object} attributes An optional key value pair of arbitrary values. * @returns {void} */ addLink (context: SpanContext, attributes?: Object): void; } /** * SpanContext represents Span state that must propagate to descendant Spans * and across process boundaries. * * SpanContext is logically divided into two pieces: the user-level "Baggage" * (see setBaggageItem and getBaggageItem) that propagates across Span * boundaries and any Tracer-implementation-specific fields that are needed to * identify or otherwise contextualize the associated Span instance (e.g., a * <trace_id, span_id, sampled> tuple). */ export interface SpanContext extends opentracing.SpanContext { /** * Returns the string representation of the internal trace ID. */ toTraceId (): string; /** * Returns the string representation of the internal span ID. */ toSpanId (): string; /** * Returns the string representation used for DBM integration. */ toTraceparent (): string; } /** * Sampling rule to configure on the priority sampler. */ export interface SamplingRule { /** * Sampling rate for this rule. */ sampleRate: number /** * Service on which to apply this rule. The rule will apply to all services if not provided. */ service?: string | RegExp /** * Operation name on which to apply this rule. The rule will apply to all operation names if not provided. */ name?: string | RegExp } /** * Span sampling rules to ingest single spans where the enclosing trace is dropped */ export interface SpanSamplingRule { /** * Sampling rate for this rule. Will default to 1.0 (always) if not provided. */ sampleRate?: number /** * Maximum number of spans matching a span sampling rule to be allowed per second. */ maxPerSecond?: number /** * Service name or pattern on which to apply this rule. The rule will apply to all services if not provided. */ service?: string /** * Operation name or pattern on which to apply this rule. The rule will apply to all operation names if not provided. */ name?: string } /** * Selection and priority order of context propagation injection and extraction mechanisms. */ export interface PropagationStyle { /** * Selection of context propagation injection mechanisms. */ inject: string[], /** * Selection and priority order of context propagation extraction mechanisms. */ extract: string[] } /** * List of options available to the tracer. */ export interface TracerOptions { /** * Used to disable APM Tracing when using standalone products * @default true */ apmTracingEnabled?: boolean /** * Whether to enable trace ID injection in log records to be able to correlate * traces with logs. * @default false */ logInjection?: boolean, /** * Whether to enable startup logs. * @default true */ startupLogs?: boolean, /** * The service name to be used for this program. If not set, the service name * will attempted to be inferred from package.json */ service?: string; /** * Provide service name mappings for each plugin. */ serviceMapping?: { [key: string]: string }; /** * The url of the trace agent that the tracer will submit to. * Takes priority over hostname and port, if set. */ url?: string; /** * The address of the trace agent that the tracer will submit to. * @default 'localhost' */ hostname?: string; /** * The port of the trace agent that the tracer will submit to. * @default 8126 */ port?: number | string; /** * Whether to enable profiling. */ profiling?: boolean /** * Options specific for the Dogstatsd agent. */ dogstatsd?: { /** * The hostname of the Dogstatsd agent that the metrics will submitted to. */ hostname?: string /** * The port of the Dogstatsd agent that the metrics will submitted to. * @default 8125 */ port?: number }; /** * Set an application’s environment e.g. prod, pre-prod, stage. */ env?: string; /** * The version number of the application. If not set, the version * will attempted to be inferred from package.json. */ version?: string; /** * Controls the ingestion sample rate (between 0 and 1) between the agent and the backend. */ sampleRate?: number; /** * Global rate limit that is applied on the global sample rate and all rules, * and controls the ingestion rate limit between the agent and the backend. * Defaults to deferring the decision to the agent. */ rateLimit?: number, /** * Sampling rules to apply to priority sampling. Each rule is a JSON, * consisting of `service` and `name`, which are regexes to match against * a trace's `service` and `name`, and a corresponding `sampleRate`. If not * specified, will defer to global sampling rate for all spans. * @default [] */ samplingRules?: SamplingRule[] /** * Span sampling rules that take effect when the enclosing trace is dropped, to ingest single spans * @default [] */ spanSamplingRules?: SpanSamplingRule[] /** * Interval in milliseconds at which the tracer will submit traces to the agent. * @default 2000 */ flushInterval?: number; /** * Number of spans before partially exporting a trace. This prevents keeping all the spans in memory for very large traces. * @default 1000 */ flushMinSpans?: number; /** * Whether to enable runtime metrics, or an object specifying whether to enable specific metric types. * @default false */ runtimeMetrics?: boolean | { enabled?: boolean, gc?: boolean, eventLoop?: boolean } /** * Custom function for DNS lookups when sending requests to the agent. * @default dns.lookup() */ lookup?: LookupFunction /** * Protocol version to use for requests to the agent. The version configured must be supported by the agent version installed or all traces will be dropped. * @default 0.4 */ protocolVersion?: string /** * Deprecated in favor of the global versions of the variables provided under this option * * @deprecated * @hidden */ ingestion?: { /** * Controls the ingestion sample rate (between 0 and 1) between the agent and the backend. */ sampleRate?: number /** * Controls the ingestion rate limit between the agent and the backend. Defaults to deferring the decision to the agent. */ rateLimit?: number }; /** * Experimental features can be enabled individually using key / value pairs. * @default {} */ experimental?: { b3?: boolean traceparent?: boolean /** * Whether to add an auto-generated `runtime-id` tag to metrics. * @default false */ runtimeId?: boolean /** * Whether to write traces to log output or agentless, rather than send to an agent * @default false */ exporter?: 'log' | 'agent' | 'datadog' /** * Whether to enable the experimental `getRumData` method. * @default false */ enableGetRumData?: boolean /** * Configuration of the IAST. Can be a boolean as an alias to `iast.enabled`. */ iast?: boolean | IastOptions appsec?: { /** * Configuration of Standalone ASM mode * Deprecated in favor of `apmTracingEnabled`. * * @deprecated */ standalone?: { /** * Whether to enable Standalone ASM. * @default false */ enabled?: boolean } } }; /** * Whether to load all built-in plugins. * @default true */ plugins?: boolean; /** * Custom logger to be used by the tracer (if debug = true), * should support error(), warn(), info(), and debug() methods * see https://datadog.github.io/dd-trace-js/#custom-logging */ logger?: { error: (err: Error | string) => void; warn: (message: string) => void; info: (message: string) => void; debug: (message: string) => void; }; /** * Global tags that should be assigned to every span. */ tags?: { [key: string]: any }; /** * Specifies which scope implementation to use. The default is to use the best * implementation for the runtime. Only change this if you know what you are * doing. */ scope?: 'async_hooks' | 'async_local_storage' | 'async_resource' | 'sync' | 'noop' /** * Whether to report the hostname of the service host. This is used when the agent is deployed on a different host and cannot determine the hostname automatically. * @default false */ reportHostname?: boolean /** * A string representing the minimum tracer log level to use when debug logging is enabled * @default 'debug' */ logLevel?: 'error' | 'debug' /** * If false, require a parent in order to trace. * @default true * @deprecated since version 4.0 */ orphanable?: boolean /** * Enables DBM to APM link using tag injection. * @default 'disabled' */ dbmPropagationMode?: 'disabled' | 'service' | 'full' /** * Configuration of the AppSec protection. Can be a boolean as an alias to `appsec.enabled`. */ appsec?: boolean | { /** * Whether to enable AppSec. * @default false */ enabled?: boolean, /** * Specifies a path to a custom rules file. */ rules?: string, /** * Controls the maximum amount of traces sampled by AppSec attacks, per second. * @default 100 */ rateLimit?: number, /** * Controls the maximum amount of time in microseconds the WAF is allowed to run synchronously for. * @default 5000 */ wafTimeout?: number, /** * Specifies a regex that will redact sensitive data by its key in attack reports. */ obfuscatorKeyRegex?: string, /** * Specifies a regex that will redact sensitive data by its value in attack reports. */ obfuscatorValueRegex?: string, /** * Specifies a path to a custom blocking template html file. */ blockedTemplateHtml?: string, /** * Specifies a path to a custom blocking template json file. */ blockedTemplateJson?: string, /** * Specifies a path to a custom blocking template json file for graphql requests */ blockedTemplateGraphql?: string, /** * Controls the automated user event tracking configuration */ eventTracking?: { /** * Controls the automated user tracking mode for user IDs and logins collections. Possible values: * * 'anonymous': will hash user IDs and user logins before collecting them * * 'anon': alias for 'anonymous' * * 'safe': deprecated alias for 'anonymous' * * * 'identification': will collect user IDs and logins without redaction * * 'ident': alias for 'identification' * * 'extended': deprecated alias for 'identification' * * * 'disabled': will not collect user IDs and logins * * Unknown values will be considered as 'disabled' * @default 'identification' */ mode?: 'anonymous' | 'anon' | 'safe' | 'identification' | 'ident' | 'extended' | 'disabled' }, /** * Configuration for Api Security */ apiSecurity?: { /** Whether to enable Api Security. * @default true */ enabled?: boolean, /** Whether to enable endpoint collection for API Security. * @default true */ endpointCollectionEnabled?: boolean, /** Maximum number of endpoints that can be serialized per message. * @default 300 */ endpointCollectionMessageLimit?: number, }, /** * Configuration for RASP */ rasp?: { /** Whether to enable RASP. * @default false */ enabled?: boolean, /** Whether to enable request body collection on RASP event * @default false */ bodyCollection?: boolean }, /** * Configuration for stack trace reporting */ stackTrace?: { /** Whether to enable stack trace reporting. * @default true */ enabled?: boolean, /** Specifies the maximum number of stack traces to be reported. * @default 2 */ maxStackTraces?: number, /** Specifies the maximum depth of a stack trace to be reported. * @default 32 */ maxDepth?: number, }, /** * Configuration for extended headers collection tied to security events */ extendedHeadersCollection?: { /** Whether to enable extended headers collection * @default false */ enabled: boolean, /** Whether to redact collected headers * @default true */ redaction: boolean, /** Specifies the maximum number of headers collected. * @default 50 */ maxHeaders: number, } } /** * Configuration for Code Origin for Spans. */ codeOriginForSpans?: { /** * Whether to enable Code Origin for Spans. * @default true */ enabled?: boolean } /** * Configuration of the IAST. Can be a boolean as an alias to `iast.enabled`. */ iast?: boolean | IastOptions /** * Configuration of ASM Remote Configuration */ remoteConfig?: { /** * Specifies the remote configuration polling interval in seconds * @default 5 */ pollInterval?: number, } /** * Whether to enable client IP collection from relevant IP headers * @default false */ clientIpEnabled?: boolean /** * Custom header name to source the http.client_ip tag from. */ clientIpHeader?: string, /** * The selection and priority order of context propagation injection and extraction mechanisms. */ propagationStyle?: string[] | PropagationStyle /** * Cloud payload report as tags */ cloudPayloadTagging?: { /** * Additional JSONPath queries to replace with `redacted` in request payloads * Undefined or invalid JSONPath queries disable the feature for requests. */ request?: string, /** * Additional JSONPath queries to replace with `redacted` in response payloads * Undefined or invalid JSONPath queries disable the feature for responses. */ response?: string, /** * Maximum depth of payload traversal for tags */ maxDepth?: number } /** * Configuration enabling LLM Observability. Enablement is superseded by the DD_LLMOBS_ENABLED environment variable. */ llmobs?: llmobs.LLMObsEnableOptions } /** * User object that can be passed to `tracer.setUser()`. */ export interface User { /** * Unique identifier of the user. * Mandatory. */ id: string, /** * Email of the user. */ email?: string, /** * User-friendly name of the user. */ name?: string, /** * Session ID of the user. */ session_id?: string, /** * Role the user is making the request under. */ role?: string, /** * Scopes or granted authorizations the user currently possesses. * The value could come from the scope associated with an OAuth2 * Access Token or an attribute value in a SAML 2 Assertion. */ scope?: string, /** * Custom fields to attach to the user (RBAC, Oauth, etc…). */ [key: string]: string | undefined } export interface DogStatsD { /** * Increments a metric by the specified value, optionally specifying tags. * @param stat The dot-separated metric name. * @param value The amount to increment the stat by. * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags. */ increment(stat: string, value?: number, tags?: Record<string, string|number> | string[]): void /** * Decrements a metric by the specified value, optionally specifying tags. * @param stat The dot-separated metric name. * @param value The amount to decrement the stat by. * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags. */ decrement(stat: string, value?: number, tags?: Record<string, string|number> | string[]): void /** * Sets a distribution value, optionally specifying tags. * @param stat The dot-separated metric name. * @param value The amount to increment the stat by. * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags. */ distribution(stat: string, value?: number, tags?: Record<string, string|number> | string[]): void /** * Sets a gauge value, optionally specifying tags. * @param stat The dot-separated metric name. * @param value The amount to increment the stat by. * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags. */ gauge(stat: string, value?: number, tags?: Record<string, string|number> | string[]): void /** * Sets a histogram value, optionally specifying tags. * @param stat The dot-separated metric name. * @param value The amount to increment the stat by. * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags. */ histogram(stat: string, value?: number, tags?: Record<string, string|number> | string[]): void /** * Forces any unsent metrics to be sent * * @beta This method is experimental and could be removed in future versions. */ flush(): void } export interface EventTrackingV2 { /** * Links a successful login event to the current trace. Will link the passed user to the current trace with Appsec.setUser() internally. * @param {string} login The login key (username, email...) used by the user to authenticate. * @param {User} user Properties of the authenticated user. Accepts custom fields. Can be null. * @param {any} metadata Custom fields to link to the login success event. */ trackUserLoginSuccess(login: string, user?: User | null, metadata?: any): void; /** * Links a successful login event to the current trace. Will link the passed user to the current trace with Appsec.setUser() internally. * @param {string} login The login key (username, email...) used by the user to authenticate. * @param {string} userId Identifier of the authenticated user. * @param {any} metadata Custom fields to link to the login success event. */ trackUserLoginSuccess(login: string, userId: string, metadata?: any): void; /** * Links a failed login event to the current trace. * @param {string} login The login key (username, email...) used by the user to authenticate. * @param {boolean} exists If the user exists. * @param {any} metadata Custom fields to link to the login failure event. */ trackUserLoginFailure(login: string, exists: boolean, metadata?: any): void; /** * Links a failed login event to the current trace. * @param {string} login The login key (username, email...) used by the user to authenticate. * @param {any} metadata Custom fields to link to the login failure event. */ trackUserLoginFailure(login: string, metadata?: any): void; } export interface Appsec { /** * Links a successful login event to the current trace. Will link the passed user to the current trace with Appsec.setUser() internally. * @param {User} user Properties of the authenticated user. Accepts custom fields. * @param {[key: string]: string} metadata Custom fields to link to the login success event. * * @beta This method is in beta and could change in future versions. * * @deprecated In favor of eventTrackingV2.trackUserLoginSuccess */ trackUserLoginSuccessEvent(user: User, metadata?: { [key: string]: string }): void /** * Links a failed login event to the current trace. * @param {string} userId The user id of the attempted login. * @param {boolean} exists If the user id exists. * @param {[key: string]: string} metadata Custom fields to link to the login failure event. * * @beta This method is in beta and could change in future versions. * * @deprecated In favor of eventTrackingV2.trackUserLoginFailure */ trackUserLoginFailureEvent(userId: string, exists: boolean, metadata?: { [key: string]: string }): void /** * Links a custom event to the current trace. * @param {string} eventName The name of the event. * @param {[key: string]: string} metadata Custom fields to link to the event. * * @beta This method is in beta and could change in future versions. */ trackCustomEvent(eventName: string, metadata?: { [key: string]: string }): void /** * Checks if the passed user should be blocked according to AppSec rules. * If no user is linked to the current trace, will link the passed user to it. * @param {User} user Properties of the authenticated user. Accepts custom fields. * @return {boolean} Indicates whether the user should be blocked. * * @beta This method is in beta and could change in the future */ isUserBlocked(user: User): boolean /** * Sends a "blocked" template response based on the request accept header and ends the response. * **You should stop processing the request after calling this function!** * @param {IncomingMessage} req Can be passed to force which request to act on. Optional. * @param {OutgoingMessage} res Can be passed to force which response to act on. Optional. * @return {boolean} Indicates if the action was successful. * * @beta This method is in beta and could change in the future */ blockRequest(req?: IncomingMessage, res?: OutgoingMessage): boolean /** * Links an authenticated user to the current trace. * @param {User} user Properties of the authenticated user. Accepts custom fields. * * @beta This method is in beta and could change in the future */ setUser(user: User): void eventTrackingV2: EventTrackingV2 } /** @hidden */ type anyObject = { [key: string]: any; }; /** @hidden */ interface TransportRequestParams { method: string; path: string; body?: anyObject; bulkBody?: anyObject; querystring?: anyObject; } /** * The Datadog Scope Manager. This is used for context propagation. */ export interface Scope { /** * Get the current active span or null if there is none. * * @returns {Span} The active span. */ active (): Span | null; /** * Activate a span in the scope of a function. * * @param {Span} span The span to activate. * @param {Function} fn Function that will have the span activated on its scope. * @returns The return value of the provided function. */ activate<T> (span: Span, fn: ((...args: any[]) => T)): T; /** * Binds a target to the provided span, or the active span if omitted. * * @param {Function|Promise} fn Target that will have the span activated on its scope. * @param {Span} [span=scope.active()] The span to activate. * @returns The bound target. */ bind<T extends (...args: any[]) => void> (fn: T, span?: Span | null): T; bind<V, T extends (...args: any[]) => V> (fn: T, span?: Span | null): T; bind<T> (fn: Promise<T>, span?: Span | null): Promise<T>; } /** @hidden */ interface Analyzable { /** * Whether to measure the span. Can also be set to a key-value pair with span * names as keys and booleans as values for more granular control. */ measured?: boolean | { [key: string]: boolean }; } export namespace plugins { /** @hidden */ interface Integration { /** * The service name to be used for this plugin. */ service?: string | any; /** Whether to enable the plugin. * @default true */ enabled?: boolean; } /** @hidden */ interface Instrumentation extends Integration, Analyzable {} /** @hidden */ interface Http extends Instrumentation { /** * List of URLs/paths that should be instrumented. * * Note that when used for an http client the entry represents a full * outbound URL (`https://example.org/api/foo`) but when used as a * server the entry represents an inbound path (`/api/foo`). * * @default /^.*$/ */ allowlist?: string | RegExp | ((urlOrPath: string) => boolean) | (string | RegExp | ((urlOrPath: string) => boolean))[]; /** * Deprecated in favor of `allowlist`. * * @deprecated * @hidden */ whitelist?: string | RegExp | ((urlOrPath: string) => boolean) | (string | RegExp | ((urlOrPath: string) => boolean))[]; /** * List of URLs/paths that should not be instrumented. Takes precedence over * allowlist if a URL matches an entry in both. * * Note that when used for an http client the entry represents a full * outbound URL (`https://example.org/api/foo`) but when used as a * server the entry represents an inbound path (`/api/foo`). * * @default [] */ blocklist?: string | RegExp | ((urlOrPath: string) => boolean) | (string | RegExp | ((urlOrPath: string) => boolean))[]; /** * Deprecated in favor of `blocklist`. * * @deprecated * @hidden */ blacklist?: string | RegExp | ((urlOrPath: string) => boolean) | (string | RegExp | ((urlOrPath: string) => boolean))[]; /** * An array of headers to include in the span metadata. * * @default [] */ headers?: string[]; /** * Callback function to determine if there was an error. It should take a * status code as its only parameter and return `true` for success or `false` * for errors. * * @default code => code < 500 */ validateStatus?: (code: number) => boolean; /** * Enable injection of tracing headers into requests signed with AWS IAM headers. * Disable this if you get AWS signature errors (HTTP 403). * * @default false */ enablePropagationWithAmazonHeaders?: boolean; } /** @hidden */ interface HttpServer extends Http { /** * Callback function to determine if there was an error. It should take a * status code as its only parameter and return `true` for success or `false` * for errors. * * @default code => code < 500 */ validateStatus?: (code: number) => boolean; /** * Hooks to run before spans are finished. */ hooks?: { /** * Hook to execute just before the request span finishes. */ request?: (span?: Span, req?: IncomingMessage, res?: ServerResponse) => any; }; /** * Whether to enable instrumentation of <plugin>.middleware spans * * @default true */ middleware?: boolean; } /** @hidden */ interface HttpClient extends Http { /** * Use the remote endpoint host as the service name instead of the default. * * @default false */ splitByDomain?: boolean; /** * Callback function to determine if there was an error. It should take a * status code as its only parameter and return `true` for success or `false` * for errors. * * @default code => code < 400 || code >= 500 */ validateStatus?: (code: number) => boolean; /** * Hooks to run before spans are finished. */ hooks?: { /** * Hook to execute just before the request span finishes. */ request?: (span?: Span, req?: ClientRequest, res?: IncomingMessage) => any; }; /** * List of urls to which propagation headers should not be injected */ propagationBlocklist?: string | RegExp | ((url: string) => boolean) | (string | RegExp | ((url: string) => boolean))[]; } /** @hidden */ interface Http2Client extends Http { /** * Use the remote endpoint host as the service name instead of the default. * * @default false */ splitByDomain?: boolean; /** * Callback function to determine if there was an error. It should take a * status code as its only parameter and return `true` for success or `false` * for errors. * * @default code => code < 400 || code >= 500 */ validateStatus?: (code: number) => boolean; } /** @hidden */ interface Http2Server extends Http { /** * Callback function to determine if there was an error. It should take a * status code as its only parameter and return `true` for success or `false` * for errors. * * @default code => code < 500 */ validateStatus?: (code: number) => boolean; } /** @hidden */ interface Grpc extends Instrumentation { /** * An array of metadata entries to record. Can also be a callback that returns * the key/value pairs to record. For example, using * `variables => variables` would record all variables. */ metadata?: string[] | ((variables: { [key: string]: any }) => { [key: string]: any }); } /** @hidden */ interface Moleculer extends Instrumentation { /** * Whether to include context meta as tags. * * @default false */ meta?: boolean; } /** @hidden */ interface Prisma extends Instrumentation {} /** @hidden */ interface PrismaClient extends Prisma {} /** @hidden */ interface PrismaEngine extends Prisma {} /** * This plugin automatically instruments the * [aerospike](https://github.com/aerospike/aerospike-client-nodejs) for module versions >= v3.16.2. */ interface aerospike extends Instrumentation {} /** * This plugin automatically instruments the * [amqp10](https://github.com/noodlefrenzy/node-amqp10) module. */ interface amqp10 extends Instrumentation {} /** * This plugin automatically instruments the * [amqplib](https://github.com/squaremo/amqp.node) module. */ interface amqplib extends Instrumentation {} /** * Currently this plugin automatically instruments * [@apollo/gateway](https://github.com/apollographql/federation) for module versions >= v2.3.0. * This module uses graphql operations to service requests & thus generates graphql spans. * We recommend disabling the graphql plugin if you only want to trace @apollo/gateway */ interface apollo extends Instrumentation { /** * Whether to include the source of the operation within the query as a tag * on every span. This may contain sensitive information and should only be * enabled if sensitive data is always sent as variables and not in the * query text. * * @default false */ source?: boolean; /** * Whether to enable signature calculation for the resource name. This can * be disabled if your apollo/gateway operations always have a name. Note that when * disabled all queries will need to be named for this to work properly. * * @default true */ signature?: boolean; } /** * This plugin automatically patches the [avsc](https://github.com/mtth/avsc) module * to collect avro message schemas when Datastreams Monitoring is enabled. */ interface avsc extends Integration {} /** * This plugin automatically instruments the * [aws-sdk](https://github.com/aws/aws-sdk-js) module. */ interface aws_sdk extends Instrumentation { /** * Whether to add a suffix to the service name so that each AWS service has its own service name. * @default true */ splitByAwsService?: boolean; /** * Whether to inject all messages during batch AWS SQS, Kinesis, and SNS send operations. Normal * behavior is to inject the first message in batch send operations. * @default false */ batchPropagationEnabled?: boolean; /** * Hooks to run before spans are finished. */ hooks?: { /** * Hook to execute just before the aws span finishes. */ request?: (span?: Span, response?: anyObject) => any; }; /** * Configuration for individual services to enable/disable them. Message * queue services can also configure the producer and consumer individually * by passing an object with a `producer` and `consumer` properties. The * list of valid service keys is in the service-specific section of * https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html */ [key: string]: boolean | Object | undefined; } /** * This plugin automatically instruments the * @azure/functions module. */ interface azure_functions extends Instrumentation {} /** * This plugin automatically instruments the * @azure/service-bus module */ interface azure_service_bus extends Integration {} /** * This plugin patches the [bunyan](https://github.com/trentm/node-bunyan) * to automatically inject trace identifiers in log records when the * [logInjection](interfaces/traceroptions.html#logInjection) option is enabled * on the tracer. */ interface bunyan extends Integration {} /** * This plugin automatically instruments the * [cassandra-driver](https://github.com/datastax/nodejs-driver) module. */ interface cassandra_driver extends Instrumentation {} /** * This plugin automatically instruments the * [child_process](https://nodejs.org/api/child_process.html) module. */ interface child_process extends Instrumentation {} /** * This plugin automatically instruments the * [confluentinc-kafka-javascript](https://github.com/confluentinc/confluent-kafka-js) module. */ interface confluentinc_kafka_javascript extends Instrumentation {} /** * This plugin automatically instruments the * [connect](https://github.com/senchalabs/connect) module. */ interface connect extends HttpServer {} /** * This plugin automatically instruments the * [couchbase](https://www.npmjs.com/package/couchbase) module. */ interface couchbase extends Instrumentation {} /** * This plugin automatically instruments the * [cucumber](https://www.npmjs.com/package/@cucumber/cucumber) module. */ interface cucumber extends Integration {} /** * This plugin automatically instruments the * [cypress](https://github.com/cypress-io/cypress) module. */ interface cypress extends Integration {} /** * This plugin automatically instruments the * [dns](https://nodejs.org/api/dns.html) module. */ interface dns extends Instrumentation {} /** * This plugin automatically instruments the * [elasticsearch](https://github.com/elastic/elasticsearch-js) module. */ interface elasticsearch extends Instrumentation { /** * Hooks to run before spans are finished. */ hooks?: { /** * Hook to execute just before the query span finishes. */ query?: (span?: Span, params?: TransportRequestParams) => any; }; } /** * This plugin automatically instruments the * [express](http://expressjs.com/) module. */ interface express extends HttpServer {} /** * This plugin automatically instruments the * [fastify](https://www.fastify.io/) module. */ interface fastify extends HttpServer {} /** * This plugin automatically instruments the * [fetch](https://nodejs.org/api/globals.html#fetch) global. */ interface fetch extends HttpClient {} /** * This plugin patches the [generic-pool](https://github.com/coopernurse/node-pool) * module to bind the callbacks the the caller context. */ interface generic_pool extends Integration {} /** * This plugin automatically instruments the * [@google-cloud/pubsub](https://github.com/googleapis/nodejs-pubsub) module. */ interface google_cloud_pubsub extends Integration {} /** * This plugin automatically instruments the * [@google-cloud/vertexai](https://github.com/googleapis/nodejs-vertexai) module. */ interface google_cloud_vertexai extends Integration {} /** @hidden */ interface ExecutionArgs { schema: any, document: any, rootValue?: any, contextValue?: any, variableValues?: any, operationName?: string, fieldResolver?: any, typeResolver?: any, } /** * This plugin automatically instruments the * [graphql](https://github.com/graphql/graphql-js) module. * * The `graphql` integration uses the operation name as the span resource name. * If no operation name is set, the resource name will always be just `query`, * `mutation` or `subscription`. * * For example: * * ```graphql * # good, the resource name will be `query HelloWorld` * query HelloWorld { * hello * world * } * * # bad, the resource name will be `query` * { * hello * world * } * ``` */ interface graphql extends Instrumentation { /** * The maximum depth of fields/resolvers to instrument. Set to `0` to only * instrument the operation or to `-1` to instrument all fields/resolvers. * * @default -1 */ depth?: number; /** * Whether to include the source of the operation within the query as a tag * on every span. This may contain sensitive information and should only be * enabled if sensitive data is always sent as variables and not in the * query text. * * @default false */ source?: boolean; /** * An array of variable names to record. Can also be a callback that returns * the key/value pairs to record. For example, using * `variables => variables` would record all variables. */ variables?: string[] | ((variables: { [key: string]: any }) => { [key: string]: any }); /** * Whether to collapse list items into a single element. (i.e. single * `users.*.name` span instead of `users.0.name`, `users.1.name`, etc) * * @default true */ collapse?: boolean; /** * Whether to enable signat