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.

AttributeMeaningAndroidiOS
service.keyThe app key (sk_...) minted by the portalsdk_config.ingest.service_keyappKey / AppKey
service.nameThe name the app is registered underThe package nameappName / AppName, defaulting to the bundle identifier
service.namespaceThe projectsdk_config.ingest.service_namespaceproject / Project
deployment.environment.nameEnvironmentsdk_config.ingest.deployment_environmentdeploymentEnvironment / DeploymentEnvironment, defaulting to production
CollectorWhere telemetry is sentsdk_config.ingest.collector_urlcollectorUrl / CollectorURL
Read fromandroid/app/src/main/sophonz-config.json, at build timeJS 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.

android/app/src/main/sophonz-config.json
{
  "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"
    }
  }
}
KeyEffect
ingest.collector_urlBase URL of the collector. Defaults to https://in.sophonz.ai. Do not include /v1/traces
ingest.service_keyThe app key, sent as service.key
ingest.service_namespaceservice.namespace
ingest.deployment_environmentdeployment.environment.name
app_frameworkSet 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.

KeyDefaultWhy it matters here
sdk_config.networking.enable_traceparent_injectionfalseAdds traceparent to requests made by fetch; see Networking
sdk_config.networking.traceparent_only_allow_domainsunsetLimits which hosts receive traceparent
sdk_config.networking.enable_network_span_forwardingfalseAdds 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_capturetrueA React Native app is usually one Activity; turn this off if the navigation package records your screens
ndk_enabledtrueNative crash capture, which covers crashes inside Hermes and other C++ libraries
api_token, app_idunsetBuild-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:

  1. sdkConfig.ios.collectorUrl and sdkConfig.ios.appKey
  2. Sophonz-Info.plist in the app bundle, with at least CollectorURL and AppKey
  3. OTLP exporters from @sophonz/react-native-otlp, with no Sophonz collector at all
  4. none of them: the start fails and initialize resolves false

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.

ios/MyApp/Sophonz-Info.plist
<?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>
ArgumentTypeDefaultDescription
sdkConfigSDKConfig{}Start options, below
patchstringunsetRecorded 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

OptionTypePlatformDefaultDescription
ios.collectorUrlstringiOS—Collector base URL, without /v1/...
ios.appKeystringiOS—App key, service.key
ios.appNamestringiOSbundle identifierservice.name
ios.projectstringiOS—service.namespace
ios.deploymentEnvironmentstringiOSproductiondeployment.environment.name
ios.disableCrashReporterbooleaniOSfalseDo not install the crash reporter
ios.disableAutomaticViewCapturebooleaniOSfalseDo not capture UIViewController screens
ios.disableNetworkSpanForwardingbooleaniOSfalseAdd traceparent to no request, and no spz.w3c_traceparent to manually recorded requests
ios.disabledUrlPatternsstring[]iOS[]Requests whose URL contains any of these strings are not captured
exportersOTLPExporterConfigboth—Extra OTLP exporters; requires @sophonz/react-native-otlp. See OpenTelemetry and OTLP
trackUnhandledRejectionsbooleanbothfalseLog 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:

  • trackUnhandledRejections
  • patch
  • 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.

FieldTypeDescription
traceExporter.endpoint, logExporter.endpointstringFull URL, including /v1/traces or /v1/logs
headers{key, token}[]Sent with every export
timeoutnumberSeconds

Tracer provider options

useSophonzNativeTracerProvider(config?, enabled?) and new SophonzNativeTracerProvider(config?) take:

OptionTypeDefaultDescription
spanContextSyncBehaviour"return_empty" or "throw""return_empty"What span.spanContext() does before the native side has answered
setGlobalContextManagerbooleantrue when no config is passed, otherwise falseRegisters the provider's context manager with @opentelemetry/api

Passing {} turns the global context manager off. See OpenTelemetry and OTLP.

Expo config plugin

PropRequiredDescription
androidAppKeyyesWritten to sdk_config.ingest.service_key
iOSAppKeyyesPassed to Sophonz.Options.withCollector(appKey:) in SophonzInitializer.swift
collectorUrlBoth platforms. Defaults to https://in.sophonz.ai
iOSAppNameiOS service.name
projectservice.namespace on both platforms
deploymentEnvironmentdeployment.environment.name on both platforms
androidSDKConfigExtra keys merged into sdk_config, for example networking or view_config. An ingest object here replaces the generated one
productModuleNameSet when the iOS PRODUCT_MODULE_NAME differs from the project name, so the Objective-C AppDelegate imports the right Swift header
iOSUseSPMtrue 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.

app.json
{
  "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 install

With 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
  },
});
OptionDefaultDescription
enabledfalseReport failures of SDK calls
allowLogToConsolefalsePrint them with console.error
customHandlerunsetCalled with the method name and the error