Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TestFairy.beginWithoutCrashHandler('<sauce-mobile-beta-token>');

## 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
Expand Down
32 changes: 23 additions & 9 deletions docs/backtrace-coexistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' });
},
});
```
Expand Down
24 changes: 14 additions & 10 deletions example/src/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 = {
Expand All @@ -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);
Expand Down
Loading