From 4be69c301ccbfd369bde7851bf7070ddd8947d26 Mon Sep 17 00:00:00 2001 From: melekr Date: Fri, 25 Sep 2026 13:28:58 -0400 Subject: [PATCH] Align attributes and docs - setCorrelationId is deprecated and writes the same field as setUserId, which overwrote it. The id now travels only as the sauce.correlation_id attribute, set before beginWithoutCrashHandler - session_started sent as "true"/"false" strings, session URL always overwritten on session start - mad.distribution_id only when configured (distributionId optional) - docs: update listener sample, uuid + react-native-get-random-values imports --- README.md | 2 +- docs/backtrace-coexistence.md | 32 +++++++++++++++++++++++--------- example/src/observability.ts | 24 ++++++++++++++---------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 477652b..6997d19 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ TestFairy.beginWithoutCrashHandler(''); ## Backtrace coexistence -Initialize Backtrace first, then Sauce Mobile Beta, and give both the same correlation identifiers. +Initialize Backtrace first, then Sauce Mobile Beta, and give both the same `sauce.correlation_id` attribute (a lowercase UUID v4 generated once per launch). See [docs/backtrace-coexistence.md](docs/backtrace-coexistence.md) for the full guide and [example/src/observability.ts](example/src/observability.ts) for a working setup. ## Session state diff --git a/docs/backtrace-coexistence.md b/docs/backtrace-coexistence.md index 4289bde..7c8a646 100644 --- a/docs/backtrace-coexistence.md +++ b/docs/backtrace-coexistence.md @@ -20,15 +20,26 @@ Sauce Mobile Beta is crashless. ## Initialization order ```ts -const backtrace = BacktraceClient.initialize(backtraceConfiguration); +import 'react-native-get-random-values'; // must be imported before uuid on React Native +import { v4 as uuidv4 } from 'uuid'; -TestFairy.setCorrelationId(correlationId); +const correlationId = uuidv4(); // lowercase UUID v4, once per app launch, before either SDK + +const backtrace = BacktraceClient.initialize({ + ...backtraceConfiguration, + userAttributes: { 'sauce.correlation_id': correlationId }, +}); + +TestFairy.setAttribute('sauce.correlation_id', correlationId); TestFairy.beginWithoutCrashHandler(sauceMobileBetaToken); ``` +Do not use `setCorrelationId` or `identify` for this: +both are deprecated and write the user-identity field (the same one `setUserId` writes), so they would collide with a real user id. Keep `setUserId` for the actual user. + ## Correlation attributes -Set the same values in both systems: +Generate `sauce.correlation_id` once per app launch (lowercase UUID v4) before initializing either SDK, and set the same values in both systems: ``` sauce.correlation_id @@ -41,16 +52,19 @@ mad.distribution_id ## Session URL -Subscribe before starting Sauce Mobile Beta; the session URL is asynchronous: +Subscribe before starting Sauce Mobile Beta; the session URL is asynchronous. +One launch can produce several sessions (after `stop()`/resume), overwrite the attribute on every callback: ```ts TestFairy.addSessionStateListener({ onSessionStarted({ sessionUrl }) { - if (sessionUrl) { - backtrace.addAttribute({ - 'sauce.mobile_beta.session_url': sessionUrl, - }); - } + backtrace.addAttribute({ + 'sauce.mobile_beta.session_started': 'true', + 'sauce.mobile_beta.session_url': sessionUrl ?? '', + }); + }, + onSessionFailed() { + backtrace.addAttribute({ 'sauce.mobile_beta.session_started': 'false' }); }, }); ``` diff --git a/example/src/observability.ts b/example/src/observability.ts index b048959..9d92eb5 100644 --- a/example/src/observability.ts +++ b/example/src/observability.ts @@ -15,7 +15,8 @@ export interface ObservabilityConfiguration { environment: string; release: string; dist: string; - distributionId: string; + /** Mobile App Distribution id; reported as mad.distribution_id only when set. */ + distributionId?: string; userId?: string; } @@ -41,7 +42,9 @@ export function initializeObservability( 'sauce.environment': configuration.environment, 'sauce.release': configuration.release, 'sauce.dist': configuration.dist, - 'mad.distribution_id': configuration.distributionId, + ...(configuration.distributionId + ? { 'mad.distribution_id': configuration.distributionId } + : {}), }; const backtraceConfiguration: BacktraceConfiguration = { @@ -68,24 +71,25 @@ export function initializeObservability( // asynchronously once the session is accepted by the server. const sessionSubscription = TestFairy.addSessionStateListener({ onSessionStarted({ sessionUrl }) { + // Overwritten on every session start: one launch can produce several sessions (stop()/resume), each with its own URL. + // String values keep the attribute type identical across iOS, Android and React Native. backtrace.addAttribute({ - 'sauce.mobile_beta.session_started': true, - ...(sessionUrl - ? { 'sauce.mobile_beta.session_url': sessionUrl } - : {}), + 'sauce.mobile_beta.session_started': 'true', + 'sauce.mobile_beta.session_url': sessionUrl ?? '', }); }, onSessionFailed() { backtrace.addAttribute({ - 'sauce.mobile_beta.session_started': false, + 'sauce.mobile_beta.session_started': 'false', }); }, }); - // Set shared identity before session initialization; the native SDK retains - // these values and attaches them to the Sauce Mobile Beta session. - TestFairy.setCorrelationId(correlationId); + // Identity and attributes are set before session initialization; + // the native SDK retains them and attaches them to every Sauce Mobile Beta session. + // The correlation id travels as the `sauce.correlation_id` attribute below. + // `setCorrelationId`/`identify` are deprecated and write the user-identity field and are not used for it. if (configuration.userId) { TestFairy.setUserId(configuration.userId);