Interface FetchInstrumentationConfig

Configuration for the "fetch" instrumentation.

Some of this configuration can be overriden on a per-fetch call basis by using the opentelemetry property in the RequestInit object (requires Next 14.1.1 or above). This property can include:

  • ignore: boolean - whether to ignore the fetch call from tracing. Overrides ignoreUrls.
  • propagateContext: boolean: overrides propagateContextUrls for this call.
  • spanName: string: overrides the computed span name for this call.
  • attributes: Attributes: overrides the computed attributes for this call.
interface FetchInstrumentationConfig {
    attributesFromRequestHeaders?: Record<string, string>;
    attributesFromResponseHeaders?: Record<string, string>;
    dontPropagateContextUrls?: (string | RegExp)[];
    enabled?: boolean;
    ignoreUrls?: (string | RegExp)[];
    propagateContextUrls?: (string | RegExp)[];
    resourceNameTemplate?: string;
}

Hierarchy

  • InstrumentationConfig
    • FetchInstrumentationConfig

Properties

attributesFromRequestHeaders?: Record<string, string>

A map of attributes that should be created from the request headers. The keys of the map are attribute names and the values are request header names. If a resonse header doesn't exist, no attribute will be created for it.

Example: fetch: { attributesFromRequestHeaders: { "attr1": "X-Attr" } }

attributesFromResponseHeaders?: Record<string, string>

A map of attributes that should be created from the response headers. The keys of the map are attribute names and the values are response header names. If a resonse header doesn't exist, no attribute will be created for it.

Example: fetch: { attributesFromResponseHeaders: { "attr1": "X-Attr" } }

dontPropagateContextUrls?: (string | RegExp)[]

A set of URL matchers (string prefix or regex) for which the tracing context should not be propagated (see propagators). This allows you to exclude a subset of URLs allowed by the propagateContextUrls. Can be overriden by the opentelemetry.propagateContext property in the RequestInit object.

enabled?: boolean

Whether to enable the plugin.

Default

true
ignoreUrls?: (string | RegExp)[]

A set of URL matchers (string prefix or regex) that should be ignored from tracing. By default all URLs are traced. Can be overriden by the opentelemetry.ignore property in the RequestInit object.

Example: fetch: { ignoreUrls: [/example.com/] }.

propagateContextUrls?: (string | RegExp)[]

A set of URL matchers (string prefix or regex) for which the tracing context should be propagated (see propagators). By default the context is propagated only for the deployment URLs, all other URLs should be enabled explicitly. Can be overriden by the opentelemetry.propagateContext property in the RequestInit object.

Example: fetch: { propagateContextUrls: [ /my.api/ ] }.

resourceNameTemplate?: string

A string for the "resource.name" attribute that can include attribute expressions in {}. Can be overriden by the opentelemetry.attributes property in the RequestInit object.

Example: fetch: { resourceNameTemplate: "{http.host}" }.