|
| 1 | +--- |
| 2 | +title: Java Servlet |
| 3 | +beta: true |
| 4 | +code_lang: java |
| 5 | +type: multi-code-lang |
| 6 | +code_lang_weight: 7 |
| 7 | +further_reading: |
| 8 | +- link: '/real_user_monitoring/browser/setup/server/' |
| 9 | + tag: 'Documentation' |
| 10 | + text: 'Browser Monitoring Auto-Instrumentation' |
| 11 | +--- |
| 12 | + |
| 13 | +{{< callout url="https://forms.gle/RdVvDsmmzW21s2vd7" header="Join the Preview!">}} |
| 14 | + RUM Auto-Instrumentation through Java servlet-based web servers is in Preview. |
| 15 | +{{< /callout >}} |
| 16 | + |
| 17 | +## Overview |
| 18 | + |
| 19 | +RUM Auto-Instrumentation automatically adds RUM monitoring to your web application server, so you can start collecting RUM data by editing a configuration file instead of having to modify your frontend code directly. However, if you want to track specific user actions (custom actions) or add custom event details (event attributes), you still need to add some code to your application. |
| 20 | + |
| 21 | +## How it works |
| 22 | + |
| 23 | +The Java SDK works by monitoring your servlet API (which handles web requests and responses), automatically checking each HTTP response your server sends. When it detects an HTML response, it looks for the `<head>` section and automatically adds the RUM JavaScript code there. The rest of your HTML content remains unchanged. This approach adds minimal overhead, so it works well even with streaming responses (where content is sent in real-time). |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +### Server requirements |
| 28 | +- Java web application server with Servlet API 3.0 or higher support: |
| 29 | + - Jetty 7+ |
| 30 | + - Tomcat 7+ |
| 31 | + - GlassFish 3+ / Payara 4.1+ |
| 32 | + - JBoss AS 6+ / Wildfly 8+ |
| 33 | + - Undertow 1+ |
| 34 | + - WebLogic 12+ |
| 35 | + - WebSphere AS 8+ / Open Liberty 17+ |
| 36 | + |
| 37 | +### SDK requirements |
| 38 | +- Java SDK installed using either: |
| 39 | + - [Automatic instrumentation][1] (SSI) |
| 40 | + - [Manual Java SDK installation][2] |
| 41 | + |
| 42 | +### Datadog configuration |
| 43 | +- RUM application [created in Datadog][3] |
| 44 | +- Configuration values ready: |
| 45 | + - `clientToken` |
| 46 | + - `applicationId` |
| 47 | + - `remoteConfigurationId` |
| 48 | + |
| 49 | +## Configuration |
| 50 | + |
| 51 | +To get access to configuration steps for this feature, [join the preview program][4]. |
| 52 | + |
| 53 | +## Troubleshooting |
| 54 | + |
| 55 | +### RUM JavaScript tag is not injected |
| 56 | + |
| 57 | +If you don't see the RUM JavaScript tag injected, try the following steps: |
| 58 | + |
| 59 | +1. **Check server logs** for any error messages related to RUM Auto-Instrumentation |
| 60 | +2. **Verify configuration** - ensure all required environment variables defined at the configuration step are set: |
| 61 | + - `DD_RUM_ENABLED=true` |
| 62 | + - `DD_RUM_APPLICATION_ID=<your-application-id>` |
| 63 | + - `DD_RUM_CLIENT_TOKEN=<your-client-token>` |
| 64 | + - `DD_RUM_REMOTE_CONFIGURATION_ID=<your-remote-config-id>` |
| 65 | +3. **Enable debug logging** by setting `dd.trace.debug=true` (system property) or `DD_TRACE_DEBUG=true` (environment variable) |
| 66 | +4. **Check HTML response** - ensure your server is returning HTML with a `<head>` section |
| 67 | +5. **Clear browser cache** - cached pages do not show the injected JavaScript |
| 68 | + |
| 69 | +In addition, when debug logging is enabled, you should see a message like this at startup: |
| 70 | + |
| 71 | +```shell |
| 72 | +DEBUG datadog.trace.api.Config - New instance: Config{..., rumEnabled=true, rumInjectorConfig={"applicationId":"appid","clientToken":"token","site":"datadoghq.com","remoteConfigurationId":"remoteconfigid"}, ...} |
| 73 | +``` |
| 74 | + |
| 75 | +This confirms that RUM Auto-Instrumentation is properly configured. |
| 76 | + |
| 77 | +## Further reading |
| 78 | + |
| 79 | +{{< partial name="whats-next/whats-next.html" >}} |
| 80 | + |
| 81 | +[1]: /tracing/trace_collection/automatic_instrumentation/?tab=singlestepinstrumentation |
| 82 | +[2]: /tracing/trace_collection/automatic_instrumentation/dd_libraries/java/ |
| 83 | +[3]: https://app.datadoghq.com/rum/list |
| 84 | +[4]: https://forms.gle/RdVvDsmmzW21s2vd7 |
0 commit comments