# SpanFilter

**Kind**: interface | **Module**: [Insights](https://docs.interop.io/browser/reference/javascript/insights/index.md)

**Source**: https://docs.interop.io/browser/reference/javascript/insights/spanfilter/index.html

Filter entry that can match a span to control its settings.

## Properties

- **`addContextToTrace`** (`boolean`, optional) default: `true`
  Whether the filtering context will be added as span attributes
  to the span. See 'Filter'.
- **`attributeSettings`** (`{ [x: string]: AttributeSettings }`, optional)
  Controls the publishing of specific attributes, by name. An entry names an attribute by its
  flattened (dot-separated) name, or everything nested under it - `"bounds"` covers
  `"bounds.left"` - and the most specific entry is the one that applies to an attribute. See
  `AttributeSettings` for what an entry does, and `attributeSettingsMode` for whether the
  entries are a block list (the default) or an allow list.

  Applies to everything written on the spans this filter matches - the filtering context,
  the additional attributes, the data added through `addData`, the `otelSpanOptions`
  attributes. Merges by attribute name over the `attributeSettings` of the traces settings,
  this filter's entries having the last word.
- **`attributeSettingsMode`** (`AttributeSettingsMode`, optional)
  How the `attributeSettings` read: `"blocklist"` (the default) publishes everything except
  the attributes with a `"drop"` entry - an `"allow"` entry is the exception to a broader
  `"drop"` (`"bounds"` dropped, `"bounds.width"` allowed); `"allowlist"` publishes only the
  attributes with an `"allow"` or a `"mask"` entry. The most specific level that sets it
  applies - this filter's, then the traces settings'.
- **`autoSetSuccessStatus`** (`boolean`, optional) default: `false`
  Whether the span's status will be set to OK on completion, if
  it's still UNSET. See 'Filter'.
- **`canBeRoot`** (`boolean`, optional) default: `true`
  Whether the span will be able to start a new trace. If false, it will only
  be able to be added to an existing trace.
- **`context`** (`{ [key: string]: string | number | boolean; }`, optional)
  Specifies the filtering context values used for matching spans.
  Spans match only if all the values in this object match
  the context values returned by the context getter callback
  and the filteringContext config property.

  Start strings with "#" for case-insensitive regex match.
- **`countMetric`** (`boolean`, optional) default: `false`
  Whether the span will be counted in the insights_trace_count metric. See TracesSettings.countMetric.
- **`countMetricOnDisabledSpans`** (`boolean`, optional) default: `false`
  Whether the span will be counted in the insights_trace_count metric if disabled. See TracesSettings.countMetric.
- **`disableNesting`** (`boolean`, optional)
  Forces the span to create a new trace.
- **`disablePropagation`** (`boolean`, optional) default: `false`
  Whether the span will not inject its propagation info into data
  transfer objects for span nesting across system boundaries.
- **`durationMetric`** (`boolean`, optional) default: `false`
  Whether the span will be counted in the insights_trace_duration metric. See TracesSettings.durationtMetric.
- **`durationMetricOnDisabledSpans`** (`boolean`, optional) default: `false`
  Whether the span will be counted in the insights_trace_count metric if disabled. See TracesSettings.durationMetric.
- **`enabled`** (`boolean`, optional) default: `true`
  Whether the span will be created or will be a no-op. See 'Filter'.
- **`forceChildTracing`** (`boolean`, optional) default: `false`
  If true, any child spans (including nested spans across sytem boundaries)
  will be forced to be traced, even if their span filter configuration
  is set to not enabled.
- **`forceStatus`** (`SpanStatusCode`, optional)
  If set, will force the span to have this status code, regardless of anything set explicitly
  or any errors caught automatically.
- **`injectOTELHeaders`** (`false | "same-origin" | "all-origins"`, optional) default: `false`
  For spans instrumenting HTTP requests, controls automatic injection of the trace
  context headers with the current span's context. The headers are produced by the
  globally registered propagator (W3C trace context - `traceparent`/`tracestate` -
  by default; replaceable via the traces settings' `propagator`, e.g. with B3 or a
  composite propagator including baggage).

  `"same-origin"` injects into same-origin requests only: adding a custom header
  to a cross-origin request triggers a CORS preflight, and a server that does not
  allow the header would fail the request itself. (The legacy value `true` is
  treated as `"same-origin"` at runtime.)

  `"all-origins"` injects into every request this filter matches, including
  cross-origin ones - use it in filters whose `context.url` matches origins
  known to accept the headers (e.g. via Access-Control-Allow-Headers).

  Applies to the fetch/XHR instrumentation and to the platform's Electron
  net.request instrumentation. Note the main process has no origin, so
  `"same-origin"` never matches there - opt platform backends in with
  `"all-origins"` filters scoped by `context.url` (there is no CORS preflight
  risk for main-process requests).
- **`level`** (`"OFF" | "LOWEST" | "DIAGNOSTIC" | "DEBUG" | "INFO" | "WARN" | "HIGHEST"`, optional) default: `INFO`
  Default span attribute verbosity level. See 'Filter'.
- **`linkToParent`** (`boolean`, optional) default: `false`
  If `true`, the span is linked to its parent instead of being parented to
  it: it starts a trace of its own, and carries an OTEL span link to the
  span that would have been its parent (the link has the attribute
  `linkToParent: true`, to tell it from other links). The connection is
  kept, without the span becoming part of the parent's trace - for a parent
  that is long-lived or unrelated in meaning, such as the application
  startup span that every span created during the startup window is nested
  under by default.

  Applies wherever the parent comes from: an explicit propagation info, the
  current tracing state, or the default propagation info. The span's own
  children are nested under it as usual, in its new trace. Without a parent
  there is nothing to link, and the span is an ordinary root; the same goes
  for `disableNesting`, which leaves the span without a parent.

  The parent still counts as a parent for `canBeRoot` (a span that cannot
  be a root is still created) and for the parent's `forceChildTracing`.
  Sampling is decided for the new trace on its own - the parent's sampling
  decision is not inherited.
- **`log`** (`boolean | TracesAsLogsOptions`, optional) default: `false`
  "Traces as logs": whether the span is also published as a log entry, using the `traceLogger`
  passed to the builder instance when building the Traces module. `true` logs the span when it
  is enabled; `false` turns the logging off altogether; a `TracesAsLogsOptions` object says
  what is logged in more detail.

  The places the option can be set in - a matching filter, the span's own options, the
  `defaults` - are combined option by option: `defaults: { log: { includeResourceAttributes: true } }`
  with `log: true` in a filter logs that filter's spans with their resource attributes.
- **`maxAttributeDepth`** (`number`, optional) default: `5`
  How deep addData method should recurse into objects when adding
  attributes to spans.
- **`minDurationMs`** (`number`, optional) default: `0`
  If specified, spans whose duration is lower than this will not be sampled.
- **`otelSpanOptions`** (`SpanOptions`, optional)
  OTEL span options
- **`overrideDefaultFilters`** (`boolean`, optional) default: `false`
  If `true`, this filter rule will be matched before any default filters provided
  by io.Connect. The default filters are usually meant to reduce verbosity by not
  tracing some internal operations by default, but you can use this property to
  force them to be traced.
  If `false`, default filters will be matched before this filtering rule.
- **`resultMetric`** (`boolean`, optional) default: `false`
  Whether the span will be counted in the insights_trace_result metric. See TracesSettings.resultMetric.
- **`resultMetricOnDisabledSpans`** (`boolean`, optional) default: `false`
  Whether the span will be counted in the insights_trace_result metric if disabled. See TracesSettings.resultMetric.
- **`sample`** (`number | boolean`, optional) default: `true`
  Default sampling setting/probability. See 'SamplingSettings'.
- **`source`** (`string`, optional)
  Specifies the source string used for matching spans.
  Spans match only if their source equals this value, or
  if their source starts with '<source>.' (e.g. my.api.foo
  starts with my.api).

  Start string with "#" for case-insensitive regex match.
- **`stopPropagationIfSpanIsDisabled`** (`boolean`, optional) default: `false`
  If a tracing span is disabled by filter, setting this to "true" will stop the propagation
  of trace nesting info across it.

## Related types

- [AttributeSettings](https://docs.interop.io/browser/reference/javascript/insights/attributesettings/index.md)
- [AttributeSettingsMode](https://docs.interop.io/browser/reference/javascript/insights/attributesettingsmode/index.md)
- [SpanStatusCode](https://docs.interop.io/browser/reference/javascript/insights/spanstatuscode/index.md)
- [TracesAsLogsOptions](https://docs.interop.io/browser/reference/javascript/insights/tracesaslogsoptions/index.md)
