The Sentry-compatible SDK for Real User Monitoring (RUM) supports reporting the following types of data:
Auto-instrumentation — Pageloads (including Web Vitals metrics), resource requests, long tasks, and actions.
Custom event — Track business workflows and key operations.
Custom log — Record business logs and key milestone information.
Exception — Capture and report JavaScript exceptions.
User — Associate events with user information for user-centric analysis and search.
1. SDK initialization configuration
To get the most comprehensive RUM data, enable the following options when you call Sentry.init.
Native JavaScript project (browser)
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://key@<YOUR-ENDPOINT>/0",
// ─── Basic Configuration ───
release: "my-web-app@1.2.0",
environment: "production",
// ─── Performance Tracing ───
tracesSampleRate: 1.0, // For production, adjust as needed, for example to 0.2
integrations:[
// Auto-instrumentation for pageload, navigation, resource, Web Vitals, etc.
Sentry.browserTracingIntegration(),
],
});Android project (Kotlin)
import android.app.Application
import io.sentry.android.core.SentryAndroid
import io.sentry.android.core.SentryAndroidOptions
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
SentryAndroid.init(this) { options ->
options.dsn = "https://key@<YOUR-ENDPOINT>/0"
// ─── Basic Configuration ───
options.release = "my-android-app@1.2.0"
options.environment = "production"
// ─── Performance Tracing ───
options.tracesSampleRate = 1.0
}
}
}Additional Note for Android: For network requests (resource events), if you are using OkHttp or Retrofit, you must add SentryOkHttpInterceptor() when building your OkHttpClient. Otherwise, the SDK cannot auto-instrument API request latency.iOS project (Swift)
import UIKit
import Sentry
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
SentrySDK.start { options in
options.dsn = "https://key@<YOUR-ENDPOINT>/0"
// ─── Basic Configuration ───
options.environment = "production"
options.releaseName = "my-ios-app@1.2.0"
// ─── Performance Tracing ───
options.tracesSampleRate = 1.0
}
return true
}
}Key parameters
Parameter | Recommended value | Corresponding RUM data | Description |
|
| View, Resource, long task, action, custom event | The sampling rate for performance tracing. Must be set to a value > 0 to collect performance data. |
| Enabled | View (pageload/navigation), Resource, long task, Web Vitals | Automatically creates transactions for pageloads and navigations, and collects metrics such as FCP, LCP, FID, CLS, and INP. |
| Version string | All events | The application version, used for version-based analysis and source map association. |
|
| All events | The environment identifier, used to distinguish between production and test environments. |
Auto-instrumented RUM data
With the preceding configuration enabled, the following data is automatically collected with no extra code:
RUM event type | Data source | Description |
View |
| Pageloads and navigations, including Web Vitals (FP, FCP, LCP, FID, CLS, INP, TTFB). |
Resource |
| XHR/Fetch requests and loading of static assets (JS, CSS, images, etc.). |
Long task |
or Vue/React component renders (≥ 50ms) | Tasks that block the main thread. |
Action |
or | User interactions such as clicks, inputs, and scrolls, including INP. |
Application |
| Application lifecycle events, such as foreground and background transitions (for mobile apps). |
Unnecessary parameters
Parameter | Description |
| This option is not needed, as Session Replay data is not stored. |
| This option is not needed, as profiling data is not stored. |
| This only affects whether |
2. Custom events
Use custom events to track the duration and status of business workflows or key operations, such as a payment process, form submission, or search request.
Usage
Report custom events using Sentry.startSpan. The op parameter must be rum.custom.
import * as Sentry from "@sentry/vue"; // or @sentry/react, @sentry/browser, etc.
// Basic usage
Sentry.startSpan(
{
op: "rum.custom",
name: "payment flow",
attributes: {
"custom.group": "payment",
"custom.value": "99.9",
},
},
() => {
// Business logic...
}
);
// With custom business attributes
Sentry.startSpan(
{
op: "rum.custom",
name: "product search",
attributes: {
"custom.group": "search",
"custom.value": "42",
// The following attributes are automatically stored in `properties` and can be queried in the console.
"keyword": "bluetooth headset",
"result_count": 42,
"search_type": "full_text",
},
},
() => {
// Search logic...
}
);Asynchronous scenarios
If your business logic is asynchronous, return a Promise from the callback function. The SDK automatically waits for the promise to resolve before calculating the duration.
await Sentry.startSpan(
{
op: "rum.custom",
name: "upload file",
attributes: {
"custom.group": "upload",
"file_type": "image",
"file_size": 1024000,
},
},
async () => {
await uploadFile(file);
}
);Parameters
Parameter | Required | Stored field | Description |
| Yes | — | Must be |
| Yes |
| The event name, used for display and search in the console. |
| Optional |
| The event group, used for aggregated statistics (e.g., |
| Optional |
| The event value, used for numerical analysis (e.g., amount, quantity). |
Other fields in | Optional |
| Custom business properties. Supports |
Automatically calculated | — |
| The execution time of the callback function in milliseconds, collected automatically by the SDK. |
3. Custom logs
Use custom logs to record business logs, key milestone information, or warning messages.
Usage
Report custom logs using Sentry.captureMessage:
import * as Sentry from "@sentry/vue";
// Basic usage (default level is "info")
Sentry.captureMessage("User completed the onboarding process");
// Specify a log level
Sentry.captureMessage("Payment retries exceeded the maximum limit", "warning");
Parameters
Parameter | Required | Stored field | Description |
| Yes |
| The log content. |
| Optional |
| The log level. Supported values are |
4. Exceptions
Use this method to capture runtime exceptions, business logic errors, or rejected Promises. This data is stored as a RUM exception event, which includes the error type, message, and a full stack trace. These events are also automatically processed for error grouping.
Usage
Report exceptions using Sentry.captureException:
import * as Sentry from "@sentry/vue";
// Basic usage — capture an Error object
try {
riskyOperation();
} catch (err) {
Sentry.captureException(err);
}
// Manually construct and report an Error
Sentry.captureException(new Error("Payment API returned an abnormal status code"));
// Capture a Promise rejection
fetchOrder(orderId).catch((err) => {
Sentry.captureException(err);
});
Data storage
Events reported with captureException generate the following RUM data:
Storage model | Description |
ExceptionModel | The main error event, including the error type ( |
NodeStore | Stores the complete raw Sentry Event JSON, used for display on the console's details page. |
GroupMessage | Error grouping information, used to aggregate errors in the error list. |
Important notes
Always pass an Error object:
captureException(new Error("msg"))is better thancaptureException("msg")because the former includes a full stack trace.Difference from captureMessage:
captureExceptioncreates an exception event, which includes a stack trace and is eligible for error grouping. In contrast,captureMessagecreates a lightweight custom log.Do not use captureMessage to report errors: For error scenarios, use
captureExceptionto access full error analysis capabilities in the console.
5. User identity configuration
After you set user information with Sentry.setUser, all subsequent events (custom events, custom logs, exceptions, etc.) automatically include the user's identity. This allows you to search for and analyze data by user in the console.
Usage
import * as Sentry from "@sentry/vue";
// Set user information after login
Sentry.setUser({
id: "user-12345",
username: "Zhang San",
data: {
vip_level: "gold",
department: "engineering",
},
});
// Clear user information after logout
Sentry.setUser(null);
Fields
Sentry user field | Stored field | Description |
|
| A unique identifier for the user. Recommended, as it enables searching by user in the console. |
|
| The username, used for display in the console. |
|
| Custom user attributes (such as membership level or department), used for multi-dimensional analysis. |
| — | This field is not currently stored. Do not rely on it. |
| — | This is collected automatically from server-side HTTP request headers; do not set it manually. |
Important notes
Call
setUseras early as possible: Set user information immediately after a user logs in to ensure all subsequent events are associated with that user.The
idfield is the most important: User-based searches in the console rely on this field. Use the user ID from your business system.The
datafield is ideal for business attributes: Attributes like membership level, user role, or organization are stored as a JSON object in theuserTagsfield.Clear user information on logout: Call
Sentry.setUser(null)to prevent events from being incorrectly associated with a logged-out user.
6. Selection guide
Scenario | Recommended method | Stored as | Reason |
Track the duration of an operation |
| Custom event | Automatically collects duration, which is ideal for performance analysis. |
Record key milestones in a business workflow |
| Custom event | Can include a group, value, and custom properties, which is ideal for aggregated analysis. |
Record a log message |
| Custom log | Lightweight and includes a log level, which is ideal for logging scenarios. |
Record a non-critical warning or tip |
| Custom log | Semantically clear and distinct from captureException. |
Capture a JS exception or runtime error |
| Exception | Provides a stack trace, error grouping, and trend analysis. |
Capture a Promise rejection |
| Exception | Same as above; preserves the full call stack. |
Capture a business logic error (e.g., a 500 API response) |
| Exception | Provides a stack trace for debugging and enables error grouping. |
7. Important notes
The
opparameter must berum.custom. Spans with otheropvalues are not converted into custom events.nameshould be concise and aggregatable: Avoid writing variables, such as user IDs or order numbers, directly intoname. They should be placed inattributes.Value type of attributes: The value can be a
string,number, orboolean. Objects and arrays are not supported.Use
captureExceptionfor errors, notcaptureMessage. Reporting an error requiresSentry.captureException(new Error("..."))to create a full exception event with a stack trace.Always pass an Error object to captureException:
captureException(new Error("msg"))is better thancaptureException("msg"). The former includes a complete stack trace.