Configuration

The native configuration a Flutter app needs on each platform — sophonz-config.json and Sophonz-Info.plist — how service identity works, and every option available from Dart.

Where the data goes and which service it belongs to is native configuration: sophonz-config.json on Android, Sophonz-Info.plist on iOS. Neither can be set from Dart. The Dart side only decides what the Flutter layer captures and how routes are timed.

At a glance

SettingAndroid (sophonz-config.json)iOS (Sophonz-Info.plist)
Collector URLsdk_config.ingest.collector_urlCollectorURL
Service keysdk_config.ingest.service_keyAppKey
Service namethe application IDAppName
Projectsdk_config.ingest.service_namespaceProject
Environmentsdk_config.ingest.deployment_environmentDeploymentEnvironment
Frameworksdk_config.app_framework: "flutter"fromPlist(platform: .flutter)
Read atbuild time, by the Gradle pluginlaunch, by Sophonz.Options.fromPlist

Service identity

Every span and log carries resource attributes that say which service it belongs to.

Resource attributeMeaning
service.keyThe service key. The collector resolves the tenant and app from it
service.nameThe app's name. On Android it is the application ID; on iOS AppName, or <bundle ID>:<process name> without it
service.namespaceThe project
deployment.environment.nameThe environment, such as production or staging

Use the same service key and project on both platforms if the Android and iOS builds should appear as one app.

WARNING — No service key, no data

The collector runs with the service key enforced. Telemetry with a missing or unregistered key is dropped without an error. The app starts, captures and uploads normally, and nothing appears in Sophonz. When data is missing on one platform, check that platform's key first.

To separate environments, keep one service key per app and change deployment_environment / DeploymentEnvironment per build, as shown below for each platform.

Android

sophonz-config.json

Create the file in the app module. The Gradle plugin builds it into the SDK, so a change needs a rebuild.

android/app/src/main/sophonz-config.json
{
  "sdk_config": {
    "app_framework": "flutter",
    "ingest": {
      "collector_url": "https://in.sophonz.ai",
      "service_key": "sk_replace_me",
      "service_namespace": "my-project",
      "deployment_environment": "production"
    }
  }
}
KeyDefaultEffect
sdk_config.app_frameworkunsetSet to flutter so the SDK reports the app as a Flutter app
sdk_config.ingest.collector_urlhttps://in.sophonz.aiBase URL of the collector. The SDK appends /v1/traces and /v1/logs
sdk_config.ingest.service_keynoneSent as service.key. Without it nothing is accepted
sdk_config.ingest.service_namespacenoneSent as service.namespace
sdk_config.ingest.deployment_environmentnoneSent as deployment.environment.name
ndk_enabledtrueNative (C/C++) crash capture. The Flutter engine is native code, so leave it on
app_id, api_tokennoneMapping file upload credentials, not telemetry credentials. See Release builds

The Android SDK's capture toggles (ANR, WebView, taps, network) use the same file. They are listed in the Android configuration reference.

CAUTION — Unknown keys fail the build

The parser rejects keys it does not recognise. A typo stops the build, so only use keys from this page or the Android configuration reference.

Per build type or flavor

The file is looked up in this order, and the first match wins: src/<variant>/, flavor combinations, individual flavors, src/<build type>/, then src/main/. A debug build can therefore report a different environment:

android/app/src/debug/sophonz-config.json
{
  "sdk_config": {
    "app_framework": "flutter",
    "ingest": {
      "service_key": "sk_replace_me",
      "service_namespace": "my-project",
      "deployment_environment": "development"
    }
  }
}

With flutter build apk --flavor staging, a file in android/app/src/staging/ is used.

Keeping the key out of the repository

collector_url and service_key can come from environment variables at build time:

SOPHONZ_SERVICE_KEY=sk_... flutter build appbundle --release
VariableReplaces
SOPHONZ_SERVICE_KEYsdk_config.ingest.service_key
SOPHONZ_COLLECTOR_URLsdk_config.ingest.collector_url

A value in the file wins over the variable, so leave the key out of the file when using this.

iOS

Sophonz-Info.plist

Create ios/Sophonz-Info.plist and add it to the Runner target in Xcode (File > Add Files to "Runner", Runner target checked). It must end up in the app bundle as a resource.

ios/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_replace_me</string>
  <key>Project</key>
  <string>my-project</string>
  <key>DeploymentEnvironment</key>
  <string>production</string>
</dict>
</plist>
KeyRequiredEffect
CollectorURLyesBase URL of the collector. Do not append /v1/...
AppKeyyesThe service key, sent as service.key
AppNamenoSent as service.name. Without it the name is <bundle ID>:<process name>
ProjectnoSent as service.namespace
DeploymentEnvironmentnoSent as deployment.environment.name. Defaults to production

CAUTION — An unconfigured plist starts nothing

Sophonz.Options.fromPlist returns nil when CollectorURL or AppKey is missing or empty. A value that still reads $(SOMETHING) counts as missing: Xcode expands build settings only in the target's Info.plist, never in a plist copied as a resource. Put literal values in this file, or generate it in a build phase before Copy Bundle Resources.

NOTE — AppName needs a newer Apple SDK

AppName is read by Apple SDK builds after 1.0.0. With 1.0.0 the key is ignored and the service name is the bundle-derived default. The portal matches an app on project and service.name, so changing the name later detaches the data from the app's existing page.

Start options

fromPlist takes the other start options as arguments.

ios/Runner/AppDelegate.swift
let captureServices = CaptureServicesOptionsBuilder()
  .addDefaults()
  .addPushNotificationCaptureService(withOptions: .init())
  .build()
 
if let options = Sophonz.Options.fromPlist(
  platform: .flutter,
  captureServices: captureServices,
  crashReporter: .sophonz,
  logLevel: .default
) {
  try? Sophonz.start(options: options)
}
ArgumentDefaultNotes
platform.nativePass .flutter
captureServices.default()Push notification capture is not in the defaults; add it as above. The full list is in iOS instrumentation
crashReporter.sophonz.none to disable crash capture
logLevel.defaultConsole verbosity of the SDK itself
otelnilSophonz.OTelOptions with your own exporters. The only way to export elsewhere on iOS

To configure in code instead of a plist, use Sophonz.Options.withCollector(url:appKey:project:deploymentEnvironment:platform:). That is also the way to pick values per build configuration without a generated plist, for example by reading them from the target's Info.plist, where $(...) is expanded.

Dart

Dart has no collector or key setting. These are the options that exist.

OptionWhereDefault
actionSophonz.instance.startnone
routeSettingsExtractorSophonzNavigationObserver, SophonzGoRouterObserverroute.settings
screenLoadConfig.recencyThresholdboth observers, through SophonzScreenLoadConfig1 second
routerSophonzGoRouterObservernone
internalClientSophonzHttpClienta new http.Client()
endpoint, headers, timeoutSecondsaddSpanExporter, addLogRecordExporternative SDK timeout

The slow-frame, frozen-frame and isolate-hang thresholds are fixed in 0.1.0 and cannot be changed. Their values are in Instrumentation.

start

await Sophonz.instance.start(action: () => runApp(const MyApp()));

With action, start wraps FlutterError.onError (keeping the previous handler and calling it after recording), sets PlatformDispatcher.instance.onError, then runs action. Without action, no error handlers are installed; install them later:

await Sophonz.instance.start();
await Sophonz.instance.installErrorHandlers(() => runApp(const MyApp()));

CAUTION — PlatformDispatcher.onError is replaced, not chained

FlutterError.onError keeps your earlier handler, but PlatformDispatcher.instance.onError is overwritten. Set your own PlatformDispatcher handler before start and it no longer runs; set it after and Sophonz stops receiving those errors. If you need both, set yours after start and call Sophonz.instance.logDartError(error, stack) from it.

SophonzNavigationObserver(
  routeSettingsExtractor: (route) => route.settings,
  screenLoadConfig: const SophonzScreenLoadConfig(
    recencyThreshold: Duration(milliseconds: 500),
  ),
)
OptionEffect
routeSettingsExtractorReturns the RouteSettings whose name is recorded. Return null to skip a route
screenLoadConfig.recencyThresholdHow recent a touch must be to count as the start of a screen load. An older touch falls back to the push time

Route naming, go_router and what each observer records are covered in Navigation.

Additional exporters (Android only)

Sophonz.instance.addSpanExporter(
  endpoint: 'https://otlp.example.com/v1/traces',
  headers: [{'x-api-key': 'token'}],
  timeoutSeconds: 10,
);
Sophonz.instance.addLogRecordExporter(
  endpoint: 'https://otlp.example.com/v1/logs',
);
await Sophonz.instance.start(action: () => runApp(const MyApp()));
ParameterNotes
endpointThe full OTLP/HTTP URL including /v1/traces or /v1/logs. An empty string is ignored
headersA list of single-entry maps, one per header
timeoutSecondsExport timeout. The native default when omitted

These export in addition to Sophonz, not instead of it.

CAUTION — Exporters must reach the native SDK before it starts

Exporters are queued in Dart and forwarded when start() runs. A call after start() is ignored. If Application.onCreate() already started the Android SDK, the forwarded exporters arrive too late and are ignored as well, so using both means giving up startup timing or registering the exporter in Kotlin before Sophonz.start(this). On iOS they are never forwarded; use otel: in the start options.

Next