---
title: "Custom Trace Propagation"
url: https://docs.sentry.io/platforms/javascript/guides/electron/tracing/distributed-tracing/custom-instrumentation/
---

# Custom Trace Propagation | Sentry for Electron

On this page you will learn how to manually propagate trace information into and out of your JavaScript application.

### [Inject Tracing Information into Outgoing Requests](https://docs.sentry.io/platforms/javascript/guides/electron/tracing/distributed-tracing/custom-instrumentation.md#inject-tracing-information-into-outgoing-requests)

For distributed tracing to work, the two headers that you extracted and stored in the active root span, `sentry-trace` and `baggage`, must be added to outgoing HTTP requests.

Here's an example of how to collect and inject this tracing information to outgoing requests:

```javascript
const traceData = Sentry.getTraceData();
const sentryTraceHeader = traceData["sentry-trace"];
const sentryBaggageHeader = traceData["baggage"];

// Make outgoing request
fetch("https://example.com", {
  method: "GET",
  headers: {
    baggage: sentryBaggageHeader,
    "sentry-trace": sentryTraceHeader,
  },
}).then((response) => {
  // ...
});
```

In this example, tracing information is propagated to the project running at `https://example.com`. If this project uses a Sentry SDK, it will extract and save the tracing information for later use.

The two services are now connected with your custom distributed tracing implementation.

### [Starting a New Trace](https://docs.sentry.io/platforms/javascript/guides/electron/tracing/distributed-tracing/custom-instrumentation.md#starting-a-new-trace)

Available since: `v8.5.0`

In case the SDK's [default behavior](https://docs.sentry.io/platforms/javascript/guides/electron/tracing/distributed-tracing.md#trace-duration) for the trace duration does not fit your needs, you can manually start a new trace that will no longer be connected to the current (distributed) trace. This means that spans or errors collected by the SDK during this new trace will not be connected to spans or errors collected before or after this new trace.

To start a new trace that remains valid throughout the duration of a callback, use `startNewTrace`:

```javascript
myButton.addEventListener("click", async () => {

  Sentry.startNewTrace(() => {
    Sentry.startSpan(
      { op: "ui.interaction.click", name: "fetch click" },
      async () => {
        await fetch("http://example.com");
      },
    );
  });

});
```

Once the callback ends, the SDK will continue the previous trace (if available).

## [Verification](https://docs.sentry.io/platforms/javascript/guides/electron/tracing/distributed-tracing/custom-instrumentation.md#verification)

If you make outgoing requests from your project to other services, check if the headers `sentry-trace` and `baggage` are present in the request. If so, distributed tracing is working.
