Instrumenting Apache Server
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel,
n'hésitez pas à nous contacter.
To try the preview for RUM Auto-Instrumentation, follow the instructions on this page.
Overview
RUM Auto-Instrumentation works by injecting the RUM Browser SDK into the HTML responses being served through a web server or proxy. This method leverages the Apache httpd Modules capability to implement a response body filter. The filter injects the RUM Browser SDK into the response body for responses identified as HTML. After auto-instrumentation is set up, you can manage configurations from the UI.
To understand important limitations and compatibility requirements, see Limitations.
Prerequisites
The Datadog Agent is installed and configured.
Set up your RUM application
To automatically instrument your RUM application:
- In Datadog, navigate to the Digital Experience > Manage Applications Page, click on New Application, and select the JavaScript (JS) application type.
- Select Auto-Instrumentation and Apache httpd.
- Configure your application parameters. See guidance on configuring sampling.
- Copy and run the installer command to load the Datadog httpd Module with the RUM SDK Injector onto httpd.
- After the installer successfully installs the SDK Injector, restart Apache HTTP Server to begin collecting RUM sessions.
- (Optional) To verify the module is successfully injecting the RUM Browser SDK into HTML pages, check the error logs for relevant messages. The module logs important steps during the injection process. Ensure that Apache HTTP Server is configured with at least the
info log level.
Alternatively, you can manually install and configure the module.
Updating your RUM application
You can update your RUM application settings at any time. From the Application Management list, select your RUM application and navigate to the SDK Configuration page. Click Save Changes after making updates.
Sampling rates
Adjust the slider or enter a specific percentage in the input box for Session Sampling or Session Replay Sampling. Copy and paste the configuration snippet to your /opt/datadog-httpd/datadog.conf file.
Advanced configuration
After you have RUM Auto-Instrumentation set up, configure User Attributes and Allowed Tracing URLs directly from the Datadog UI without modifying your application code.
User attributes
User Attributes allow you to associate RUM sessions with specific users, enabling you to:
- Track individual user journeys across your application
- Filter and search sessions by user details
- Gain insights into user-specific issues and behaviors
Configure three user properties: User ID, User Name, and User Email.
Source types
For each user attribute, select how the RUM SDK should extract the value:
| Source | Description | Example |
|---|
| JavaScript | Read from a JavaScript variable on the page | window.currentUser.id or dataLayer.user.email |
| Cookie | Read from a browser cookie | Cookie name: user_session |
| DOM | Read from an HTML element’s text content or attribute | CSS selector: #user-id or [data-user-email] |
Use a regex pattern to extract specific values when your source contains extra characters. For example:
- Source value:
user_id=12345;session=abc - Regex pattern:
user_id=(\d+) - Extracted value:
12345
If your regex pattern includes a capture group (parentheses), the SDK extracts that value. Otherwise, it extracts the entire matched string.
Allowed tracing URLs
Configure allowed tracing URLs to connect your RUM sessions to backend APM traces. This provides end-to-end visibility from the browser to your backend services.
When a user’s browser makes a request to an allowed URL, the RUM SDK injects trace headers. Your backend APM agent reads these headers and links the backend trace to the RUM session.
Configuration
Add the URLs of your backend services that you want to connect to RUM:
| Field | Description |
|---|
| URL | The backend URL to trace. Use an exact URL (for example, https://api.example.com) or enable Regex for pattern matching (for example, https://.*\.example\.com). |
| Propagator Type | The trace header format your backend expects. Options: datadog, tracecontext (W3C), b3, b3multi. Select multiple if needed. |
Tracing requires a configured service name. Set this in the App Attributes section.
Learn more
See Connect RUM and Traces for detailed information about RUM and APM integration.
Troubleshooting
RUM is not injected
If you notice that RUM is not being injected into HTML pages, consider the following potential causes:
- Content-Type mismatch: RUM is injected only into HTML pages. If the
Content-Type header does not correctly indicate text/html, the injection is skipped.
Limitations
See other Limitations.
Uninstall
To manually remove RUM from your auto-instrumented web server:
- Locate the Apache (
httpd) configuration file by running httpd -V. Depending on the Linux distribution used, this binary file could be named http, apachectl, apache2 or apache2ctl. The following steps use httpd as an example. In this instance, the file location could be: /usr/local/apache2/conf/httpd.conf. - At the end of the httpd configuration file, remove the line:
Include /opt/datadog-httpd/datadog.conf. - Delete the directory
/opt/datadog-httpd/ and all of its contents. - Restart or reload Apache httpd.
Alternative installation method
If you need finer control over more parameters than what the automatic instrumentation provides, you can manually load the module onto your web server instead of running the installation script.
To manually instrument your RUM application:
Download the module file
- Download the zipped module.
- Extract the zip to obtain the
mod_datadog.so file. Move it to a location that Apache HTTP Server has access to (referenced as <RUM_MODULE_PATH> in the steps below).
Update Apache HTTP server configuration
Locate the configuration file. You can use apachectl -V to find the default configuration path. Add the following line to load the module:
LoadModule datadog_module <RUM_MODULE_PATH>
Within the appropriate root or location section, add the following:
# APM Tracing is enabled by default. The following line disables APM Tracing
DatadogTracing Off
DatadogRum On
<DatadogRumSettings "v6">
DatadogRumOption "applicationId" "<DATADOG_APPLICATION_ID>"
DatadogRumOption "clientToken" "<DATADOG_CLIENT_TOKEN>"
DatadogRumOption "site" "<DATADOG_SITE>"
DatadogRumOption "service" "my-web-application"
DatadogRumOption "env" "production"
DatadogRumOption "version" "1.0.0"
DatadogRumOption "sessionSampleRate" "100"
DatadogRumOption "sessionReplaySampleRate" "100"
DatadogRumOption "trackResources" "true"
DatadogRumOption "trackLongTasks" "true"
DatadogRumOption "trackUserInteractions" "true"
</DatadogRumSettings>
Restart your server
- Restart the Apache HTTP Server to begin collecting data for your Datadog RUM application. By default, the RUM SDK is injected to all HTML documents. You may need to clear your browser cache.
- (Optional) To verify the module is successfully injecting the RUM Browser SDK into HTML pages, check the httpd error logs for relevant messages. The module logs important steps during the injection process. Ensure that Apache HTTP Server is configured with at least the
info log level.
Further reading
Documentation, liens et articles supplémentaires utiles: