This topic explains how to send application data collected by the Sentry SDK to Alibaba Cloud Simple Log Service (SLS) for viewing and analysis in the Real User Monitoring console.
Prerequisites
This feature is currently in a grayscale release. To apply for access, you can submit a ticket.
You have activated Cloud Monitor 2.0.
You have created a workspace.
You have integrated the Sentry SDK into your client application, and the SDK version meets the requirements. For a list of supported versions, see Overview of Sentry SDK Integration with Real User Monitoring.
This solution supports only the Sentry Envelope protocol format. If you use an older SDK version, such as JavaScript SDK v6 or earlier, you must upgrade to a version that supports Envelope.
Step 1: Create a RUM Application
Log on to the Cloud Monitor 2.0 console, select the target workspace, and click Integration Center in the navigation pane on the left.
In the navigation pane on the left, click Integration Center.
In the Real User Monitoring section, select the platform card that matches your application type, such as iOS, Android, or Web.
Enter an application name. Configure other parameters as needed. Click Create Application.
After the application is created, go to Application Settings > Basic Information and record the following values:
Parameter
Description
Get Location
Workspace
Workspace name
Application Settings > Basic Information
Endpoint
Data reporting domain name
Application Settings > Basic Information > Integration Configuration
ServiceId
RUM application ID
Application Settings > Basic Information
Step 2: Create a Project in Sentry (Optional)
This step is required only if you want to view data in the Sentry console. The purpose of this step is to obtain your Sentry project ID.
Log on to the Sentry console.
Create a new project. Select the same platform as your client application.
Go to the project settings page and locate the DSN configuration.
Extract the project ID from the DSN. It is the final numeric segment in the URL path.
For example, if the DSN is https://xxx@sentry.example.com/21, the project ID is 21.
Note: If you do not need the Sentry console, you can skip this step. In later configurations, set the project ID to 0.Step 3: Configure Data Ingestion
Select one of the following methods based on your scenario. We recommend that new users or users who have completed migration validation use the SDK direct write method. If you are migrating from a self-managed Sentry instance, we recommend that you first use the Nginx mirror dual-write method to verify data integrity before you switch to the SDK direct write method.
Method 1: SDK Direct Write
Update the DSN configuration in your client application’s Sentry SDK to point to Alibaba Cloud SLS.
DSN format
Original Sentry DSN format:
https://<public_key>@<sentry_host>/<project_id>Revised Alibaba Cloud DSN format:
https://<public_key>@<endpoint>/rum/sentry/<workspace>/<service_id>/<project_id>Parameters
Parameter | Description |
public_key | Public key from the Sentry DSN. SLS does not validate this parameter. You can use any value. |
endpoint | Data reporting domain name. Get this value in Step 1. |
workspace | Workspace name. Get this value in Step 1. |
service_id | RUM application ID. Get this value in Step 1. |
project_id | Sentry project ID. Get this value in Step 2. If you do not use the Sentry console, set this to |
Configuration Examples
The following examples show the SDK configuration for each platform.
iOS (Swift)
import Sentry
SentrySDK.start { options in
options.dsn = "https://key@cn-chengdu.log.aliyuncs.com/rum/sentry/my-workspace/abc123@example/21"
options.debug = true
}Android (Kotlin)
import io.sentry.android.core.SentryAndroid
SentryAndroid.init(this) { options ->
options.dsn = "https://key@cn-chengdu.log.aliyuncs.com/rum/sentry/my-workspace/abc123@example/21"
options.isDebug = true
}Web (JavaScript)
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://key@cn-chengdu.log.aliyuncs.com/rum/sentry/my-workspace/abc123@example/21",
debug: true,
});Electron
import * as Sentry from "@sentry/electron";
Sentry.init({
dsn: "http://key@cn-chengdu.log.aliyuncs.com/rum/sentry/my-workspace/abc123@example/21",
});Vue
import * as Sentry from "@sentry/vue";
Sentry.init({
app,
dsn: "http://key@cn-chengdu.log.aliyuncs.com/rum/sentry/my-workspace/abc123@example/21",
});Method 2: Nginx Mirror Dual Write
Use the Nginx mirror module to send data to both your existing Sentry service and Alibaba Cloud SLS.
Scenario: You need to view data in the Standard Edition Sentry console, the RUM Edition Sentry console, and the Alibaba Cloud RUM console.
Configuration steps
In your Nginx configuration file, add an upstream for SLS forwarding:
upstream rum_forwarder { server <endpoint>:80; keepalive 2; }Add a URI mapping rule. Configure different forwarding paths based on the Sentry project ID:
map $request_uri $forwarder_path { # Default forwarding path default /rum/sentry/<workspace>/<service_id>; # Forward by project ID "~^/api/<project_id>/envelope/" /rum/sentry/<workspace>/<service_id_for_project_1>; "~^/api/1/envelope/" /rum/sentry/<workspace>/<service_id_for_project_1>; "~^/api/2/envelope/" /rum/sentry/<workspace>/<service_id_for_project_2>; }Enable traffic mirroring for the Sentry API route:
location ~ ^/api/[1-9]\d*/ { proxy_pass http://relay; mirror /rum_mirror; mirror_request_body on; } location = /rum_mirror { internal; proxy_pass http://rum_forwarder$forwarder_path$request_uri; proxy_set_header Host <endpoint>; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Request-Id $request_id; proxy_set_header Connection ''; proxy_read_timeout 5s; proxy_send_timeout 5s; proxy_connect_timeout 5s; proxy_ignore_client_abort on; }Reload the Nginx configuration:
nginx -t && nginx -s reload
Multi-project configuration example
If you have multiple Sentry projects and need to forward them to different RUM applications, you can configure the map rules as follows:
map $request_uri $forwarder_path {
default /rum/sentry/my-workspace/default-service;
# Project 1 → RUM Application A
"~^/api/1/envelope/" /rum/sentry/my-workspace/service-a;
# Project 2 → RUM Application B
"~^/api/2/envelope/" /rum/sentry/my-workspace/service-b;
# Project 3 → RUM Application C
"~^/api/3/envelope/" /rum/sentry/my-workspace/service-c;
}
Full configuration example
http {
upstream rum_forwarder {
server <endpoint>:80;
keepalive 2;
}
map $request_uri $forwarder_path {
# Default forwarding path
default /rum/sentry/<workspace>/<service_id>;
# Forward by project ID
"~^/api/1/envelope/" /rum/sentry/<workspace>/<service_id_for_project_1>;
"~^/api/2/envelope/" /rum/sentry/<workspace>/<service_id_for_project_2>;
}
server {
listen 80;
server_name sentry.example.com;
# Sentry API route — enable mirroring
location ~ ^/api/[1-9]\d*/ {
proxy_pass http://relay;
mirror /rum_mirror;
mirror_request_body on;
}
# SLS mirror handling
location = /rum_mirror {
internal;
proxy_pass http://rum_forwarder$forwarder_path$request_uri;
proxy_set_header Host <endpoint>;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Request-Id $request_id;
proxy_set_header Connection '';
proxy_read_timeout 5s;
proxy_send_timeout 5s;
proxy_connect_timeout 5s;
proxy_ignore_client_abort on;
}
# Other Sentry route configurations
# ...
}
}
Parameter description
Parameter | Description |
endpoint | SLS data reporting domain name—for example, |
workspace | Workspace name |
service_id | RUM application ID |
project_id | Sentry project ID. |
Verify Data Ingestion
After you complete the configuration, you can perform the following steps to verify that data is ingested as expected:
Trigger a test error or event in your client application.
Log on to the Cloud Monitor 2.0 console and go to Real User Monitoring > Application List.
Select the RUM application and check whether new data is displayed. Data is typically displayed in the console 1 to 2 minutes after it is ingested.
FAQ
Q: Can I set the public_key in the DSN to any value?
A: Yes, you can. SLS does not validate the public_key parameter in the Sentry DSN. We recommend that you keep your original key for traceability.
Q: After data is ingested into SLS, can I still view it in the Sentry console?
A: Yes, you can. You can deploy a custom version of the Sentry web and Snuba API containers that read data from SLS. For instructions, see Configure the Sentry Console to Read Real User Monitoring Data.