Configuration
The app identity on each platform, where the collector URL and app key live, the order iOS resolves them in, and every option of initialize, sdkConfig, sophonz-config.json and the Expo config plugin.
The two platforms are configured in different places, because the native SDKs underneath them are. Android is configured at build time in sophonz-config.json; nothing is passed at runtime. iOS is configured at startup, from JavaScript, from Sophonz-Info.plist, or from native code.
Identity
Every batch the device sends carries resource attributes that tell the collector which app it belongs to.
| Attribute | Meaning | Android | iOS |
|---|---|---|---|
service.key | The app key (sk_...) minted by the portal | sdk_config.ingest.service_key | appKey / AppKey |
service.name | The name the app is registered under | The package name | appName / AppName, defaulting to the bundle identifier |
service.namespace | The project | sdk_config.ingest.service_namespace | project / Project |
deployment.environment.name | Environment | sdk_config.ingest.deployment_environment | deploymentEnvironment / DeploymentEnvironment, defaulting to production |
| Collector | Where telemetry is sent | sdk_config.ingest.collector_url | collectorUrl / CollectorURL |
| Read from | android/app/src/main/sophonz-config.json, at build time | JS sdkConfig.ios, Sophonz-Info.plist or Sophonz.Options, at startup |
Each platform is registered as its own app in the portal and has its own sk_ key. Do not share one key between them.
CAUTION — A wrong key fails silently
The collector drops telemetry whose key it cannot resolve to a tenant, and returns no error the SDK could report. A build with a placeholder or mistyped key starts, captures, uploads, and produces nothing — and initialize still resolves true. When a session does not appear, check the key before anything else.
AppName is a join key
service.name is how the portal matches telemetry to a registered app. On iOS it defaults to the bundle identifier; if the app is registered under a different name, set appName. Changing it later detaches the app from its portal entry: the collector keeps accepting data and the app page goes empty, which looks like delivery stopped.
Android: sophonz-config.json
The Gradle plugin compiles the file into the app. Values cannot be changed at runtime, and sdkConfig in JavaScript has no Android fields.
{
"sdk_config": {
"app_framework": "react_native",
"ingest": {
"collector_url": "https://in.sophonz.ai",
"service_key": "sk_android_replace_me",
"service_namespace": "my-project",
"deployment_environment": "production"
}
}
}| Key | Effect |
|---|---|
ingest.collector_url | Base URL of the collector. Defaults to https://in.sophonz.ai. Do not include /v1/traces |
ingest.service_key | The app key, sent as service.key |
ingest.service_namespace | service.namespace |
ingest.deployment_environment | deployment.environment.name |
app_framework | Set to react_native for a React Native app |
service_key and collector_url can also come from the SOPHONZ_SERVICE_KEY and SOPHONZ_COLLECTOR_URL environment variables at build time, so the key need not be committed. The file wins when both are set.
Keys that matter most in a React Native app
Every other option is the same as for a native app and is listed in Android configuration. A key the parser does not recognise fails the build.
| Key | Default | Why it matters here |
|---|---|---|
sdk_config.networking.enable_traceparent_injection | false | Adds traceparent to requests made by fetch; see Networking |
sdk_config.networking.traceparent_only_allow_domains | unset | Limits which hosts receive traceparent |
sdk_config.networking.enable_network_span_forwarding | false | Adds spz.w3c_traceparent to captured and manually recorded request spans |
sdk_config.networking.disabled_url_patterns | [] | Regular expressions for URLs not to capture, such as a second OTLP backend |
sdk_config.view_config.enable_automatic_activity_capture | true | A React Native app is usually one Activity; turn this off if the navigation package records your screens |
ndk_enabled | true | Native crash capture, which covers crashes inside Hermes and other C++ libraries |
api_token, app_id | unset | Build-time upload credentials, not telemetry credentials. See Release builds before setting them |
iOS: how the identity is resolved
When JavaScript starts the SDK, the native module picks the first of these that is available:
sdkConfig.ios.collectorUrlandsdkConfig.ios.appKeySophonz-Info.plistin the app bundle, with at leastCollectorURLandAppKey- OTLP exporters from
@sophonz/react-native-otlp, with no Sophonz collector at all - none of them: the start fails and
initializeresolvesfalse
An empty string counts as absent at every step. When the SDK is started natively, this order does not apply: the options in SophonzInitializer.swift are used as written.
From JavaScript
import {initialize} from "@sophonz/react-native";
await initialize({
sdkConfig: {
ios: {
collectorUrl: "https://in.sophonz.ai",
appKey: "sk_ios_replace_me",
appName: "my-ios-app",
project: "my-project",
deploymentEnvironment: "production",
disabledUrlPatterns: ["analytics.example.com"],
},
trackUnhandledRejections: true,
},
logLevel: "warn",
});From Sophonz-Info.plist
Create a file named exactly Sophonz-Info.plist next to the app's own Info.plist, add it to the app target so Copy Bundle Resources includes it, and leave collectorUrl and appKey out of sdkConfig.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CollectorURL</key>
<string>https://in.sophonz.ai</string>
<key>AppKey</key>
<string>sk_ios_replace_me</string>
<key>AppName</key>
<string>my-ios-app</string>
<key>Project</key>
<string>my-project</string>
<key>DeploymentEnvironment</key>
<string>production</string>
</dict>
</plist>This keeps the key out of the JavaScript bundle and lets one initialize call serve both platforms with no ios block.
CAUTION — Build settings are not expanded in this file
Xcode expands $(SETTING) references only in the target's own Info.plist. In Sophonz-Info.plist a value like $(SOPHONZ_APP_KEY) stays literal, and the SDK treats it as absent. Put real values here, or generate the file in a build phase.
From native code
SophonzInitializer.swift, written by the Expo plugin and the wizard, calls Sophonz.start(options:). Everything the iOS configuration page describes — capture service options, the traceparent allowlist, hang detection, crash reporter choice — is available there and nowhere else. Keep platform: .reactNative in the options.
initialize
initialize({sdkConfig?, patch?, logLevel?}): Promise<boolean>| Argument | Type | Default | Description |
|---|---|---|---|
sdkConfig | SDKConfig | {} | Start options, below |
patch | string | unset | Recorded as the JavaScript patch number. Use it for over-the-air updates, where the native version does not change |
logLevel | "info", "warn" or "error" | "info" | Console output of the JavaScript layer. Errors always print |
useSophonz(sdkConfig, patch?, logLevel?) takes the same values positionally.
sdkConfig reference
| Option | Type | Platform | Default | Description |
|---|---|---|---|---|
ios.collectorUrl | string | iOS | — | Collector base URL, without /v1/... |
ios.appKey | string | iOS | — | App key, service.key |
ios.appName | string | iOS | bundle identifier | service.name |
ios.project | string | iOS | — | service.namespace |
ios.deploymentEnvironment | string | iOS | production | deployment.environment.name |
ios.disableCrashReporter | boolean | iOS | false | Do not install the crash reporter |
ios.disableAutomaticViewCapture | boolean | iOS | false | Do not capture UIViewController screens |
ios.disableNetworkSpanForwarding | boolean | iOS | false | Add traceparent to no request, and no spz.w3c_traceparent to manually recorded requests |
ios.disabledUrlPatterns | string[] | iOS | [] | Requests whose URL contains any of these strings are not captured |
exporters | OTLPExporterConfig | both | — | Extra OTLP exporters; requires @sophonz/react-native-otlp. See OpenTelemetry and OTLP |
trackUnhandledRejections | boolean | both | false | Log unhandled promise rejections |
The SDKConfig type also declares a logLevel field. initialize does not read it; pass logLevel next to sdkConfig instead.
What still applies after a native start
If MainApplication or SophonzInitializer already started the SDK, initialize skips its own start. The ios options and exporters are then ignored without a warning. These still apply:
trackUnhandledRejectionspatch- the global JS error handler, and the React Native and SDK versions
- on iOS release builds, the JS bundle identifier
The equivalent start settings belong in native code: sophonz-config.json on Android, Sophonz.Options or Sophonz-Info.plist on iOS.
Exporter fields
Summarised here, explained in OpenTelemetry and OTLP.
| Field | Type | Description |
|---|---|---|
traceExporter.endpoint, logExporter.endpoint | string | Full URL, including /v1/traces or /v1/logs |
headers | {key, token}[] | Sent with every export |
timeout | number | Seconds |
Tracer provider options
useSophonzNativeTracerProvider(config?, enabled?) and new SophonzNativeTracerProvider(config?) take:
| Option | Type | Default | Description |
|---|---|---|---|
spanContextSyncBehaviour | "return_empty" or "throw" | "return_empty" | What span.spanContext() does before the native side has answered |
setGlobalContextManager | boolean | true when no config is passed, otherwise false | Registers the provider's context manager with @opentelemetry/api |
Passing {} turns the global context manager off. See OpenTelemetry and OTLP.
Expo config plugin
| Prop | Required | Description |
|---|---|---|
androidAppKey | yes | Written to sdk_config.ingest.service_key |
iOSAppKey | yes | Passed to Sophonz.Options.withCollector(appKey:) in SophonzInitializer.swift |
collectorUrl | Both platforms. Defaults to https://in.sophonz.ai | |
iOSAppName | iOS service.name | |
project | service.namespace on both platforms | |
deploymentEnvironment | deployment.environment.name on both platforms | |
androidSDKConfig | Extra keys merged into sdk_config, for example networking or view_config. An ingest object here replaces the generated one | |
productModuleName | Set when the iOS PRODUCT_MODULE_NAME differs from the project name, so the Objective-C AppDelegate imports the right Swift header | |
iOSUseSPM | true to source the Apple SDK from Swift Package Manager. Needs expo-build-properties with ios.useFrameworks: "dynamic" |
A missing androidAppKey or iOSAppKey, or a non-boolean iOSUseSPM, fails the prebuild. Any other problem the plugin hits is reported as a warning and the prebuild continues.
{
"expo": {
"plugins": [
[
"@sophonz/react-native",
{
"androidAppKey": "sk_android_replace_me",
"iOSAppKey": "sk_ios_replace_me",
"androidSDKConfig": {
"networking": {
"enable_traceparent_injection": true,
"traceparent_only_allow_domains": ["api.example.com"]
}
}
}
]
]
}
}Because the plugin starts the SDK natively on both platforms, sdkConfig passed to initialize in an Expo app with the plugin is ignored. iOS capture options that have no prop must be edited into the generated SophonzInitializer.swift, which a later prebuild leaves alone unless --clean is used.
Swift Package Manager on iOS
CocoaPods is the default. To take the Apple SDK from SPM instead (React Native 0.75 or later, dynamic frameworks):
cd ios
SOPHONZ_USE_SPM=1 USE_FRAMEWORKS=dynamic pod installWith Expo, set iOSUseSPM: true; the plugin writes ENV['SOPHONZ_USE_SPM'] ||= '1' at the top of the Podfile so the choice does not depend on the shell.
The Podfile's sophonz_post_install(installer) hook adds the SophonzIO package to the app target so it is embedded and signed; without it a Release build crashes at launch with Library not loaded. Keep the hook in the Podfile either way: with SOPHONZ_USE_SPM unset it removes what an earlier SPM install added.
SDK error logging
Every API call resolves a fallback instead of rejecting. To see why a call failed while developing:
import {configureSDKErrorLogging} from "@sophonz/react-native";
configureSDKErrorLogging({
enabled: __DEV__,
allowLogToConsole: true,
customHandler: (method, error) => {
// forward to your own diagnostics
},
});| Option | Default | Description |
|---|---|---|
enabled | false | Report failures of SDK calls |
allowLogToConsole | false | Print them with console.error |
customHandler | unset | Called with the method name and the error |