Skip to content

Commit

Permalink
add remaining 6x feature pages (#49)
Browse files Browse the repository at this point in the history
* add remaining feature pages

* fix link

* fix breadcrumb

* fix title

* fix link

* fix link
  • Loading branch information
davidlawrencer authored Oct 28, 2024
1 parent 74f2e97 commit e468e74
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/ios/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Embrace Apple SDK is designed to provide first class observability and diagn

Our Apple 6.x SDK is recommended for all current and new customers. The 6.x SDK is our [open-source](https://github.com/embrace-io/embrace-apple-sdk) superset of [OpenTelemetry](https://opentelemetry.io) instrumentation, built in Swift for modern language (such as async/await) and mobile observability (spans, logs) features. It has all the latest Embrace features and semantics, and will continue to grow as Embrace helps expand the OTel ecosystem for mobile.

We recommend that customers use our version 6 SDK, as it contains OTel primitives, open-source support, and better use of modern Swift features like async/await. If you are upgrading from our older 5x SDK, a [migration guide](/docs/ios/open-source/upgrade-guide.md) is available to implement the new features and interface in the 6.x SDK.
We recommend that customers use our version 6 SDK, as it contains OTel primitives, open-source support, and better use of modern Swift features like async/await. If you are upgrading from our older 5x SDK, a [migration guide](/ios/open-source/upgrade-guide.md) is available to implement the new features and interface in the 6.x SDK.

This documentation reflects information on the 6.x SDK. Current documentation for the 6.x SDK is split into three sections:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
---
title: User Personas
title: Identify Users
sidebar_position: 4
---


# User Personas
# Identify your users

Months after your app has been released and your user base is growing, you are going to want to start triaging issues you find in your app based on segments of your user base. Setting the stage for that activity now means you will be well positioned to do that work when the time comes.

It is important that you annotate your sessions with enough information so that developers and other agents can find problem sessions when required. You will also want to be able to answer questions about a session to help you understand the severity of an issue. Embrace offers two mechanisms for annotating sessions in a searchable way:

- [User Personas](./#user-personas). This is data you can set and update about the user of a session.
- [Session Properties](./#session-properties). This is data you use to track information about the device or the session itself.

These mechanisms annotate the session so that you can subsequently filter and sort on this data.

## User Personas

The `MetadataHandler` provides an [extension](https://github.com/embrace-io/embrace-apple-sdk/blob/main/Sources/EmbraceCore/Public/Metadata/MetadataHandler%2BPersonas.swift) for managing User Personas. User Personas allow you to dynamically segment app users and their sessions according to their behavior, characteristics, or other criteria that you create. This feature helps with analyzing user segments, understanding variations or poor performance in user behavior, and tailoring the application experience to meet the diverse of ways that users use your application.

## Interface
### Interface

### Retrieving Current User Personas
#### Retrieving Current User Personas

To retrieve the current set of persona tags, use the `currentPersonas` property. This property fetches persona tags from the storage that apply to the user at the current point in time.

```swift
let personas = Embrace.client?.metadata.currentPersonas
```

### Adding User Personas in the Embrace SDK
#### Adding User Personas in the Embrace SDK

User Personas in the Embrace SDK allow you to tag sessions with specific user traits or behaviors. This can help you prioritize fixing bugs that affect certain user segments.

Expand All @@ -42,6 +53,17 @@ extension PersonaTag {
}
```

## Session Properties
Session Properties are another way to annotate the session. The difference between session properties and user personas is that the former are for items relating to the session or the device, and not necessarily to the user. Although, you are free to use both mechanisms interchangeably.

Here is an example of setting a session property:

```swift
Embrace.client?
.metadata
.addProperty(key: "launch type", value: "normal", lifespan: .session)
```

## Overview of the Metadata Lifespan

When you add Embrace metadata, you can apply a [lifespan](https://github.com/embrace-io/embrace-apple-sdk/blob/main/Sources/EmbraceCore/Public/Metadata/MetadataHandler.swift#L9-L17) to that value. Sometimes it can be very useful to let contextual data "auto-expire" when no longer relevant, and at other times you want that data to exist for the user's entire time in your app.
Expand All @@ -56,4 +78,4 @@ There are three metadata lifespans:

## Conclusion

User Personas provide a flexible way to tag and categorize user sessions for better analysis and personalization. By leveraging this functionality, developers can gain insights into user behavior and improve the application experience based on user segments.
User Personas and Session Properties provide a flexible way to tag and categorize user sessions for better analysis and personalization. By leveraging this functionality, developers can gain insights into user behavior and improve the application experience based on user segments.
6 changes: 4 additions & 2 deletions docs/ios/open-source/features/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ The Embrace Apple SDK includes many advanced features that you can enable to hel

1. [Export your OpenTelemetry traces and logs](/ios/open-source/features/otel-exporter.md) using any compatible OTel Exporter.
1. Measure and prioritize performance in your app using [ Tracing](/ios/open-source/features/traces.md).
1. Dynamically segment users to understand variations and tailor diverse app experiences using [User Personas](/ios/open-source/features/metadata-personas.md).
1. Capture the vitals of any troublesome networking using [Network Body Capture](/ios/open-source/features/network-body-capture.md)
1. Dynamically segment users to understand variations and tailor diverse app experiences using [User Personas](/ios/open-source/features/identify-users.md).
1. Capture the vitals of any troublesome networking using [Network Body Capture](/ios/open-source/features/network-body-capture.md).
1. Get insight into [Push Notifications](/ios/open-source/features/push-notifications.md) the user received on the native OS.
1. Find the source of a previous session's termination with the [Last Run End State API](/ios/open-source/features/last-run-end-state.md).
66 changes: 66 additions & 0 deletions docs/ios/open-source/features/last-run-end-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Last Run End State
description: Learn about the advanced ways Embrace can help your application
sidebar_position: 6
---

# Last Run End State API

## Overview

---

The Last Run End State 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:

1. App crashes
1. App is relaunched
1. `lastRunEndState` returns "crash"
1. App is sent to background
1. App is resumed, starting a new session
1. `lastRunEndState` still returns "crash"
1. App exits cleanly
1. App is relaunched
1. `lastRunEndState` returns "cleanExit"

## Integration Steps

---

In order to use this feature, you will need to follow two steps:

1. Make sure your app is using the latest version of the Embrace SDK
2. Implement the API call to receive the state of the last run.

:::info
This feature only works with the Embrace crash reporter. It is **NOT** compatible if you use Crashlytics for crash reporting.
:::

## Implementation

The API will return a value noting the last run end state of the application. Note that:

- 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 `.unavailable`.
- 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.


```swift
let lastRunEndState = Embrace.client?.lastRunEndState()
```
### Possible Values

The current [possible values](https://github.com/embrace-io/embrace-apple-sdk/blob/main/Sources/EmbraceCore/Public/LastRunEndState.swift) for end state are:

```swift
// Last end state can't be determined
case unavailable

// Last app run ended in a crash
case crash

// Last app run ended cleanly
case cleanExit
```
15 changes: 15 additions & 0 deletions docs/ios/open-source/features/push-notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Push Notifications
description: Embrace can capture push notifications received by your app.
sidebar_position: 5
---

# Push Notifications

The Embrace SDK can capture push notifications received by your app.

You can change the way Embrace captures push notifications with the [CaptureService](/docs/ios/open-source/integration/customizing-signals.md) `PushNotificationCaptureService`. This automatic mode doesn't require any changes in your code.

:::info
If you want to prevent any data inside the notifications from being captured, you can set the `captureData` to `false` when you initialize the service with `PushNotificationCaptureService.Options`.
:::
21 changes: 21 additions & 0 deletions docs/ios/open-source/getting-started/background-sessions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: Capture Background Sessions
description: Embrace can capture background sessions so that you can gain insight into user experiences that are affected by events that happen in the background.
sidebar_position: 5
---

# Capture Background Sessions

The Embrace SDK can be configured to enable the capturing of background sessions. You can enable and disable capturing background sessions on the settings page of the Embrace dashboard.

A background session will contain any activity that happens when the app goes to the background, and its duration will be how long the app remains in this state.

Please note that when an app is backgrounded, it is only "alive" for a short period of time and it is then sent to "sleep" by the OS. How long the app remains active in the background may vary depending on what the app is doing, but ultimately it is the OS the one that has the control. This means that a background session could be 1 hour long, but only 1 minute in that hour will have any kind of activity.

Here are some examples of what can start a background session:
- The app is active and it is sent to the background: this can happen when the user minimizes the app manually or another app goes to the foreground.
- The app is closed and then gets "waken up" in the background by the OS: usually happens when the app is configured with background tasks like handling silent push notifications.

:::warning Important
Enabling the collection of background session will increase the amount of sessions that are collected.
:::
28 changes: 28 additions & 0 deletions docs/ios/open-source/getting-started/breadcrumbs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Breadcrumbs
description: Add context to sesions with Breadcrumbs.
sidebar_position: 4
---

# Breadcrumbs

Breadcrumbs are a lightweight way to add logging to your session. They provide context to user activity in sessions, while adding little CPU or memory overhead.

## Adding Context to Sessions

Embrace can collect basic session data and crashes as you've already seen in the [Crash Reporting](/docs/ios/open-source/getting-started/crash-report.md) and [Session Reporting](/docs/ios/open-source/getting-started/session-reporting.md) sections. Embrace can also collect your logging data and include it as context within your sessions. Here's how you add a breadcrumb to the session:

```swift
Embrace.client?
.add(event: .breadcrumb("something happened RIGHT NOW"))
```

:::warning Important
Breadcrumb messages must be 256 characters or less.
:::

Note here that the `.add(event:)` method adds a SpanEvent to the [session span](/ios/open-source/#how-we-built-it). Embrace's Breadcrumbs are an OpenTelemetry-compliant subclass of SpanEvents, and are add in-context in the [User Timeline](/docs/features/user-session-insights.md).

:::info
For how to best use Breadcrumbs, check out the [Best Practices](/docs/best-practices/breadcrumbs.md) page.
:::
3 changes: 3 additions & 0 deletions docs/ios/open-source/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Read on to find out more about:
- Adding [crash reporters](/ios/open-source/getting-started/crash-report.md) to your app.
- Making sense of [sessions](/ios/open-source/getting-started/session-reporting.md) in your app.
- Symbolicating [crash reports and dSYMs](/ios/open-source/getting-started/symbolicating-crash-reports.md) in your app.
- Adding context to sessions with [breadcrumbs](/ios/open-source/getting-started/breadcrumbs.md).
- Get immediate warning of any issues with the [Log Message API](/ios/open-source/getting-started/logs.md)
- Learn what processes are still running when users [background](/ios/open-source/getting-started/background-sessions.md) your application

## Prerequisites

Expand Down
68 changes: 68 additions & 0 deletions docs/ios/open-source/getting-started/logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Log Message API
description: Trigger alerts for your iOS application using logs with the Embrace SDK
sidebar_position: 6
---

# Adding Logs

As we've discussed in the [Session Reporting section](/docs/ios/open-source/getting-started/session-reporting.md), Embrace will end sessions and attempt to upload the current session when the app is sent to the background.

However, some situations might require immediate feedback, such as hunting an especially difficult bug, troubleshooting on behalf of high-value users, or monitoring a new version rollout.

You can leverage the Log Message API for this.

## Using the Log Message API

You can log a message immediately by calling the `log` method.

```mdx-code-block
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```

<Tabs groupId="ios-language" queryString="ios-language">
<TabItem value="swift" label="Swift">

```swift
let attributes = ["property_a": "value_a", "property_b": "value_b"]
Embrace.client?.log(
"Loading not finished in time.", // message
severity: .warn,
timestamp: Date.now,
attributes: attributes
)
```

</TabItem>
</Tabs>

Let's examine the method call from above to understand the arguments involved:

1. **message**: The first argument is a string and represents the message itself.
1. **severity**: This is the [LogSeverity](https://github.com/embrace-io/embrace-apple-sdk/blob/main/Sources/EmbraceCommonInternal/Enums/LogSeverity.swift) of the event. Typically we use this mechanism for errors and warnings and occasionally for tracing purposes, but that is better left to [breadcrumbs](/docs/ios/open-source/getting-started/breadcrumbs.md).
1. **timestamp**: This is the time that this log message should show in the timeline. If the log points to an error or warning happening prior to the current time, the timestamp for the occurrence can be added here.
1. **attributes**: This is a dictionary of key-value pairs. When logging an event, break out any details into this dictionary and you will be able to categorize and filter on those values.

import LogLimit from '@site/shared/log-limit.md';

<LogLimit />

## Being Alerted on Logs

Once you start using our alerting feature you can also configure how these are handled on the backend.
Using the Embrace Dashboard, you can configure email alerts to be sent to your team when certain thresholds are met with logEvents.

For example, if you have a steady rate of 1% for a given logEvent, then you can set a threshold so that if it rises in a sustained way you get an email sent directly to you.

## Best Practices

Embrace's Log Message API is immediate mode.

A call to this API results in a networking call between your app and Embrace's servers immediately.
This can have a negative effect on your application's performance or battery life when over-used.
It can also be an invaluable tool for getting information about your application quickly.

:::info
For more tips on making the most of the Log Message API, checkout the [Best Practices](/best-practices/log-message-api).
:::

0 comments on commit e468e74

Please sign in to comment.