Skip to main content

Network spans forwarding

Network spans forwarding​

Network spans forwarding adds a W3C traceparent header to your app's network requests, so you can trace the same request in Embrace and in your backend observability platform. For an overview, see Network spans forwarding.

Enable network spans forwarding​

  1. Enable network spans forwarding for your app in the Embrace dashboard. See Enable network spans forwarding.

  2. On Android, add enable_network_span_forwarding to android/app/src/main/embrace-config.json. iOS needs no app changes.

    {
    "app_id": "xxxxx",
    "api_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "sdk_config": {
    "app_framework": "react_native",
    "networking": {
    "enable_network_span_forwarding": true
    }
    }
    }

    For more on this file, see Android configuration file.

Limit forwarding to specific domains​

By default, the Embrace SDK adds the header to every captured request. To add it only to your own domains, set an allowlist on each platform.

In your EmbraceInitializer.swift file, pass traceparent options to the URLSession capture service:

let captureServices = CaptureServicesOptionsBuilder()
.addUrlSessionCaptureService(withOptions: URLSessionCaptureService.Options(
traceparent: .init(onlyAllowDomains: ["example.com"])
))
.addDefaults()
.build()

try EmbraceIO.setup(
options: .withAppId(
"__APP_ID__", // 5 digits string
platform: .reactNative,
captureServices: captureServices
)
)
try EmbraceIO.shared.start()

Each entry is a bare hostname that matches the host and its subdomains. For the full rules, see Limiting injection to specific domains.

Disable network spans forwarding​

  1. Remove your app from network spans forwarding in the Embrace dashboard.
  2. Stop header injection in your app:

In your EmbraceInitializer.swift file, set onlyAllowDomains to an empty array:

.addUrlSessionCaptureService(withOptions: URLSessionCaptureService.Options(
traceparent: .init(onlyAllowDomains: [])
))