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
-
Enable network spans forwarding for your app in the Embrace dashboard. See Enable network spans forwarding.
-
On Android, add
enable_network_span_forwardingtoandroid/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.
- iOS
- Android
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.
Add traceparent_only_allow_domains to embrace-config.json. Each entry is an exact hostname (example.com) or a subdomain suffix (.example.com):
"networking": {
"enable_network_span_forwarding": true,
"traceparent_only_allow_domains": ["example.com", ".example.com"]
}
Disable network spans forwarding
- Remove your app from network spans forwarding in the Embrace dashboard.
- Stop header injection in your app:
- iOS
- Android
In your EmbraceInitializer.swift file, set onlyAllowDomains to an empty array:
.addUrlSessionCaptureService(withOptions: URLSessionCaptureService.Options(
traceparent: .init(onlyAllowDomains: [])
))
Set enable_network_span_forwarding to false, or remove it.