Real User Monitoring (RUM) lets you report data using a custom domain name. This process involves four steps: uploading a certificate, verifying data reporting locally, modifying the DNS record for the custom domain name, and using the custom domain name to report data.
Prerequisites
You have integrated your application with RUM, and a corresponding Simple Log Service (SLS) project has been created.
To find the SLS project for RUM, navigate to Application Name > Application Settings > Basic Information > Application Information > Log Information.
The Java software development kit (SDK) is required to upload certificates. Use version 0.6.78 or later. For the Maven dependency configuration, see the following example:
<dependency> <groupId>com.aliyun.openservices</groupId> <artifactId>aliyun-log</artifactId> <version>0.6.142</version> </dependency>
Procedure
Step 1: Upload a certificate
Permissions
Use the AccessKey pair of a Resource Access Management (RAM) user to perform operations. Before you start, grant the necessary permissions to the RAM user. For more information, see Manage RAM user permissions.
Grant the log:PutCname, log:DeleteCname, and log:ListCname permissions to the project resource for RUM. The following example shows a custom policy with the minimum required permissions:
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": ["log:PutCname", "log:DeleteCname", "log:ListCname"],
"Resource": "acs:log:*:*:project/${your_rum_sls_project_name}/*"
}
]
}Sample code for uploading a certificate
import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.CertificateConfiguration;
import com.aliyun.openservices.log.request.SetProjectCnameRequest;
import com.aliyun.openservices.log.response.ListProjectCnameResponse;
import org.junit.Test;
import java.io.*;
import java.nio.file.Files;
public class CnameSample {
public static String readStreamAsString(InputStream in, String charset) throws IOException {
if (in == null) {
return "";
}
Reader reader = null;
Writer writer = new StringWriter();
String result;
char[] buffer = new char[1024];
try {
int n = -1;
reader = new BufferedReader(new InputStreamReader(in, charset));
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
result = writer.toString();
} finally {
in.close();
if (reader != null) {
reader.close();
}
if (writer != null) {
writer.close();
}
}
return result;
}
private static String readFileAsString(String filename) throws Exception {
File file = new File(filename);
return readStreamAsString(Files.newInputStream(file.toPath()), "utf-8");
}
@Test
public void testCname() throws Exception {
// The public key file for the custom domain name certificate.
String pubKey = readFileAsString("public.pem");
// The private key file for the custom domain name certificate.
String priKey = readFileAsString("private.key");
// The project that corresponds to Real User Monitoring.
String project = "${your_rum_sls_project_name}";
// The custom domain name, for example, xx.abc.com.
String cname = "your_cname";
// The endpoint for Simple Log Service. This example uses Beijing. Replace it with the endpoint for your region.
String endpoint = "cn-beijing.log.aliyuncs.com";
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
SetProjectCnameRequest request1 = new SetProjectCnameRequest(project, cname);
request1.setCertificateConfiguration(new CertificateConfiguration()
.withPublicKey(pubKey)
.withPrivateKey(priKey));
Client client = new Client(endpoint,
accessKeyId,
accessKeySecret);
client.setProjectCname(request1);
}
}Parameters for the client object:
Parameter name | Description |
endpoint | For information about SLS endpoints, see Endpoints. Use the public network endpoint. |
accessKeyId | For information about how to view the AccessKey of a RAM user, see View the AccessKey information of a RAM user. |
accessKeySecret | For information about how to view the AccessKey of a RAM user, see View the AccessKey information of a RAM user. |
Disassociate and query certificates
Step 2: Verify data reporting locally
Before you switch the DNS record for your custom domain name, verify that data reporting works correctly on your local machine. This confirms that the certificate was uploaded successfully.
Run the dig command on your local machine to obtain an IP address for the domain name ${your_rum_sls_project}.${sls_public_network_endpoint_for_the_region}. For information about public network endpoints for SLS, see the parameter description in Step 1: Upload a certificate.
In your local hosts file, map the custom domain name to the IP address that you obtained.
In the RUM integration configuration, replace the domain name part of the endpoint with your custom domain name. Then, test data reporting on your local machine. For more information, see Step 4: Use a custom domain name to report data.
Step 3: Modify the DNS record for the custom domain name
After you verify that data is reported successfully from your local machine, create a CNAME record. Point your custom domain name to ${your_rum_sls_project}.${sls_public_network_endpoint_for_the_region}.
Step 4: Use the custom domain name to report data
For Web, miniapp, mini-game, Uniapp, Flutter, and ReactNative applications, replace the domain name part of the endpoint with your custom domain name. The endpoint is displayed under Application Settings > Basic Information > Integrate Probe.
For example, consider a web application. The console displays the following endpoint:
https://proj-xtrace-xxxx-cn-hangzhou.cn-hangzhou.log.aliyuncs.com/rum/web/v2?workspace=default-cms-xxxx-cn-hangzhou&service_id=xxx@yyyy. Replace the domain name part of the endpoint with your custom domain name. The updated endpoint is:https://your.custom.domain/rum/web/v2?workspace=default-cms-xxxx-cn-hangzhou&service_id=xxx@yyyy.
For Android, iOS, and HarmonyOS applications, if the SDK version is earlier than 2.0.0, replace the domain name in ConfigAddress with your custom domain name. If the version is 2.0.0 or later, replace the domain name in Endpoint with your custom domain name.
For an Android application, for example, if your SDK version is < 2.0.0, change ConfigAddress to
https://your.custom.domain. If your SDK version is ≥ 2.0.0, change Endpoint tohttps://your.custom.domain.