Retrieve Session Metadata
The Embrace SDK provides several methods for retrieving metadata about the current session. Note that each of the following methods should be called after the SDK has initialized in order for them to return valid data.
Current Session ID
import {getCurrentSessionId} from '@embrace-io/react-native';
getCurrentSessionId().then(sessionId=>{
console.log("Embrace Session Id", sessionId)
})
Embrace SDK’s API enables customers to programmatically obtain the current Embrace Session ID. Depending on your use case, having the ability to obtain the Embrace Session ID will enable you to share that ID with other observability tools in order to build a URL to that specific session in the Embrace dashboard and make that link available on those third-party tools.
To build the URL to a specific session please insert your app id and the provided session id into the following:
https://dash.embrace.io/app/{app_id}/open?session_id={session_id}
When should I call the Current Session ID method?
If you call the method before the SDK has started, it will return null. So, you need to call it once the SDK has been started.
Can I call this method in the background?
You can also call this method when the app is in the background. If Background Activity is enabled for your app, you’ll get the Session ID for that background activity; if it’s disabled, you’ll get null/nil
.
If you call getCurrentSessionId()
inside the AppState change
listener; keep in mind that this is the moment when
the session is ending, and a new one is starting. Therefore, there is a high chance that you will get the session ID of
the session that is still ending. You might need to delay the call or obtain the session ID at any other point of the app
lifecycle to make sure the session ID you get is the one you are looking for.
Last Run End State
import {getLastRunEndState} from '@embrace-io/react-native';
getLastRunEndState().then(resp => {
console.log('LastRunEndState', resp);
});
This API enables customers to automatically/programmatically understand if the previous app instance ended in a crash. Depending on your use case, having the ability to query an API to understand if the previous app instance ended in a crash will enable you to adjust the behavior or UI of your app after a crash has occurred.
What do we mean by previous app instance?
A cold launch, basically. If the app gets backgrounded/resumed so a new session starts, the value returned will not change. So:
- App crashes
- App is relaunched
getLastRunEndState
returns "crashed"- App is sent to background
- App is resumed, starting a new session
getLastRunEndState
still returns "crashed"- App exits cleanly
- App is relaunched
getLastRunEndState
returns "clean exit"
Important Notes
- The API can only be called after the SDK has been started. If a call is made prior to starting the Embrace SDK you will get a response of
INVALID
- It will return that a crash occurred if the app crashed any time since the app last came to the foreground. This includes if the app crashed while running in the background.
Possible Values
/// Used to represent the end state of the last run of the application.
export type SessionStatus = 'INVALID' | 'CRASH' | 'CLEAN_EXIT';
Current Device ID
import {getDeviceId} from '@embrace-io/react-native';
getDeviceId().then(deviceId=>{
console.log("Embrace Device Id", deviceId)
})