# TracesManager

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

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

Traces API.

## Properties

- **`clickstreamMarker`** (`MarkerSpanCallback`, optional)
  Optional callback function to programmatically create marker spans in the Clickstream trace.
  Allows applications to mark specific user interaction events beyond automatic click tracking
  (e.g., custom UI interactions, gesture events, programmatic actions).

  The callback receives:
  - source: A descriptive name for the marker (e.g., "user-swiped-left", "custom-button-action")
  - data: Optional span data organized by verbosity level for detailed context

  Returns either PropagationInfo to link the marker span to other traces, or void.

  Works in conjunction with the clickstream setting to track detailed user interaction patterns.
- **`currentTracingState`** (`TracingState | null`, required)
  The tracing state representing the currently active trace and span, if any.
- **`endOpenSpans`** (`(reason?: string) => number`, optional)
  Ends every span that is still open, so that it gets exported: a span is only exported once
  it has ended, and whatever is still open when the process goes away is lost. The spans are
  ended as they stand and marked with an `endedByShutdown` attribute (and
  `endedByShutdownReason`, when a reason is given). Called by waitForFinalExport(); call it
  directly ahead of any other last flush.
- **`flush`** (`(timeoutMs?: number) => Promise<void>`, optional)
  Exports the spans that have ended so far, waiting for up to `timeoutMs`. Unlike
  waitForFinalExport() it leaves the spans that are still open alone - for a flush at a
  point where the application may go on running. Never rejects.
- **`instrumentElectronNet`** (`(netModule: unknown) => void`, optional)
  Instruments Electron's main-process `net` module (net.request and net.fetch)
  with the request spans (source "interopio.api.instrumentation.electronNet" /
  ".fetch") and the same request metrics as the renderer fetch/XHR
  instrumentation. The net module is injected by the caller - io.Connect
  Desktop's bootstrap, guarded by instrumentRequests.platform - because the
  io.Insights packages have no electron dependency. Honors the
  instrumentRequests configuration (ignore/match patterns, ignoreTelemetryURLs,
  errorStatusCodes, spanNames, metric flags); no-op when instrumentRequests is
  disabled.
- **`settings`** (`TracesSettings`, required)
  Traces settings.
- **`started`** (`boolean`, required)
  Whether or not this instance is started.
- **`startupTraceFinished`** (`(reason?: string) => void`, optional)
  Called by the application to signify that its startup has completed
  and no further spans should be nested under the startup trace.

  It also tells io.Connect Desktop, by invoking the platform's "T42.ACS.AppStartupFinished"
  interop method: what the platform's appStartMeasurement "explicit" counts as the
  application having started. The method is invoked with the interop API the library was
  built with - `Builder.withInterop` (`@interopio/core` passes its own), or the interop
  argument of the traces plugin's `newTracesManager` - and with no other: without one,
  nothing is told. Where that API can list the registered methods (`methods`), the method
  is looked for first and invoked only when the platform has registered it; an API without
  `methods` is invoked without the lookup. Best effort - a failing invocation is swallowed,
  and nothing is tried again later - not for the platform's own loader signal, and once per
  page load: a later call that finds the platform told already tells it nothing more.
- **`userJourneyMarker`** (`MarkerSpanCallback`, optional)
  Optional callback function to programmatically create marker spans in the User Journey trace.
  Allows applications to mark significant points in a user's journey through the application
  (e.g., navigation events, key user actions, milestone completions).

  The callback receives:
  - source: A descriptive name for the marker (e.g., "user-navigated-to-dashboard")
  - data: Optional span data organized by verbosity level for detailed context

  Returns either PropagationInfo to link the marker span to other traces, or void.

  Works in conjunction with the userJourney setting to track the user's entire session flow.

## Methods

### setFilterConfig

Allows updating the configured filters.

On the startup span buffer (`BufferingTracesManager`), which has no settings of its own:
gives it the filters the real manager is going to match the spans against. A span that a
filter disables for certain (`enabled: false` - going by the span's source and the
context it was created with) is then not buffered: its callback runs as that of a
disabled span does, and the spans created inside it nest under the nearest buffered
ancestor. Not when something is asked of the span although it is disabled -
`countMetricOnDisabledSpans`, `resultMetricOnDisabledSpans`,
`durationMetricOnDisabledSpans`, `log.onDisabledSpans` or
`stopPropagationIfSpanIsDisabled`, set by a filter that may match the span, by a default
filter of its options or by the options themselves: such a span is buffered, and handled
by the real manager at the replay, like every other span (what the `defaults` of the
traces settings ask is not seen: the buffer does not have them). Only a plain
`enabled: false` is acted on while buffering - every other span is buffered, and every
other filter property applied, by the real manager at the replay.

```ts
(filters: SpanFilter[]) => void
```

**Parameters**

- **`filters`** (`SpanFilter[]`, required)

**Returns**: `void`

### start

Starts publishing data.

```ts
() => Promise<void>
```

**Returns**: `Promise<void>`

### stop

Stops publishing data.

```ts
() => Promise<void>
```

**Returns**: `Promise<void>`

### waitForFinalExport

Waits for any pending data to be published, with the option to specify a timeout.

```ts
(timeoutMs?: number) => Promise<void>
```

**Parameters**

- **`timeoutMs`** (`number`, optional)
  maximum time to wait for export

**Returns**: `Promise<void>`

### withSequenceSpan

Allows creating a span for a named trace.

```ts
<T>(source: string, callback: | IOInsights.WithSpanCallback<T>) => Promise<T>
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create. The name of the trace will be <source>.start, and if one doesn't exist, it will be created.
- **`callback`** (`| IOInsights.WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `Promise<T>`

### withSequenceSpan

Allows creating a span for a named trace.

```ts
<T>(source: string, filteringContext: | IOInsights.FilteringContext | null, callback: | IOInsights.WithSpanCallback<T>) => Promise<T>
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create. The name of the trace will be <source>.start, and if one doesn't exist, it will be created.
- **`filteringContext`** (`| IOInsights.FilteringContext | null`, required)
  Filtering context used to match against the tracing filtering configuration.
- **`callback`** (`| IOInsights.WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `Promise<T>`

### withSequenceSpan

Allows creating a span for a named trace.

```ts
<T>(source: string, filteringContext: | IOInsights.FilteringContext | null, options: | IOInsights.WithSpanOptions | null, callback: | IOInsights.WithSpanCallback<T>) => Promise<T>
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create. The name of the trace will be <source>.start, and if one doesn't exist, it will be created.
- **`filteringContext`** (`| IOInsights.FilteringContext | null`, required)
  Filtering context used to match against the tracing filtering configuration.
- **`options`** (`| IOInsights.WithSpanOptions | null`, required)
  Options to use when creating the span.
- **`callback`** (`| IOInsights.WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `Promise<T>`

### withSequenceSpanEx

Allows creating a span for a named trace.

```ts
<T>(source: string, traceName: | string | null, callback: | IOInsights.WithSpanCallback<T>) => Promise<T>
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create.
- **`traceName`** (`| string | null`, required)
  The name of the trace to nest the span in. If one doesn't exist, it will be created.
- **`callback`** (`| IOInsights.WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `Promise<T>`

### withSequenceSpanEx

Allows creating a span for a named trace.

```ts
<T>(source: string, traceName: | string | null, filteringContext: | IOInsights.FilteringContext | null, callback: | IOInsights.WithSpanCallback<T>) => Promise<T>
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create.
- **`traceName`** (`| string | null`, required)
  The name of the trace to nest the span in. If one doesn't exist, it will be created.
- **`filteringContext`** (`| IOInsights.FilteringContext | null`, required)
  Filtering context used to match against the tracing filtering configuration.
- **`callback`** (`| IOInsights.WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `Promise<T>`

### withSequenceSpanEx

Allows creating a span for a named trace.

```ts
<T>(source: string, traceName: | string | null, filteringContext: | IOInsights.FilteringContext | null, options: | IOInsights.WithSpanOptions | null, callback: | IOInsights.WithSpanCallback<T>) => Promise<T>
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create.
- **`traceName`** (`| string | null`, required)
  The name of the trace to nest the span in. If one doesn't exist, it will be created.
- **`filteringContext`** (`| IOInsights.FilteringContext | null`, required)
  Filtering context used to match against the tracing filtering configuration.
- **`options`** (`| IOInsights.WithSpanOptions | null`, required)
  Options to use when creating the span.
- **`callback`** (`| IOInsights.WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `Promise<T>`

### withSpan

Allows creating a span for the currently active trace. If one doesn't exist, it will be created.

```ts
<T>(source: string, callback: WithSpanCallback<T>) => T
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create.
- **`callback`** (`WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `T`

### withSpan

Allows creating a span for the currently active trace. If one doesn't exist, it will be created.

```ts
<T>(source: string, filteringContext: FilteringContext, callback: WithSpanCallback<T>) => T
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create.
- **`filteringContext`** (`FilteringContext`, required)
  Filtering context used to match against the tracing filtering configuration.
- **`callback`** (`WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `T`

### withSpan

Allows creating a span for the currently active trace or a specified trace. If one doesn't exist, it will be created.

```ts
<T>(source: string, filteringContext: FilteringContext, propagationInfo: PropagationInfo | PropagationInfoCarrier | null, callback: WithSpanCallback<T>) => T
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create.
- **`filteringContext`** (`FilteringContext`, required)
  Filtering context used to match against the tracing filtering configuration.
- **`propagationInfo`** (`PropagationInfo | PropagationInfoCarrier | null`, required)
  Span and trace id to use for manually nesting the new trace.
- **`callback`** (`WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `T`

### withSpan

Allows creating a span for the currently active trace or a specified trace. If one doesn't exist, it will be created.

```ts
<T>(source: string, filteringContext: FilteringContext, propagationInfo: PropagationInfo | PropagationInfoCarrier | null, options: WithSpanOptions | null, callback: WithSpanCallback<T>) => T
```

**Parameters**

- **`source`** (`string`, required)
  The name of the span to create.
- **`filteringContext`** (`FilteringContext`, required)
  Filtering context used to match against the tracing filtering configuration.
- **`propagationInfo`** (`PropagationInfo | PropagationInfoCarrier | null`, required)
  Span and trace id to use for manually nesting the new trace.
- **`options`** (`WithSpanOptions | null`, required)
  Options to use when creating the span.
- **`callback`** (`WithSpanCallback<T>`, required)
  Logic to execute in the span.

**Returns**: `T`

## Related types

- [FilteringContext](https://docs.interop.io/browser/reference/javascript/insights/filteringcontext/index.md)
- [MarkerSpanCallback](https://docs.interop.io/browser/reference/javascript/insights/markerspancallback/index.md)
- [PropagationInfo](https://docs.interop.io/browser/reference/javascript/insights/propagationinfo/index.md)
- [SpanFilter](https://docs.interop.io/browser/reference/javascript/insights/spanfilter/index.md)
- [TracesSettings](https://docs.interop.io/browser/reference/javascript/insights/tracessettings/index.md)
- [TracingState](https://docs.interop.io/browser/reference/javascript/insights/tracingstate/index.md)
- [WithSpanCallback](https://docs.interop.io/browser/reference/javascript/insights/withspancallback/index.md)
- [WithSpanOptions](https://docs.interop.io/browser/reference/javascript/insights/withspanoptions/index.md)
