Dynatrace
Learn how to integrate Dynatrace backend logs with OpenReplay session replays to extend your monitoring and debugging capabilities.
This integration is available for Cloud (Serverless, Dedicated), and Self-Host (Community, Enterprise) users.
1. Generate your Dynatrace credentials
Section titled 1. Generate your Dynatrace credentialsFollow these steps to obtain the necessary credentials from Dynatrace:
- Log in to your Dynatrace account.
- Navigate to Account Management
- Create an OAuth Client:
- Click on Identity & Access Management
- Select OAuth clients
- Click on Create client to generate the required credentials.
- Save your credentials:
- After creating the client, save the following:
- Client ID
- Client Secret
- Account URN
- Obtain your
environment ID
:// Example Dynatrace URL: https://rzr85764.app.dynatrace.com/ Environment ID: rzr85764
2. Propagate openReplaySession.id to Backend
Section titled 2. Propagate openReplaySession.id to BackendTo link Dynatrace logs with OpenReplay sessions, a unique session ID openReplaySession.id
has to be propagated from your frontend to your backend on each request you want to track.
Include openReplaySession.id in Frontend API Requests
Section titled Include openReplaySession.id in Frontend API RequestsModify your frontend code to add the openReplaySession.id
to the headers of your API requests:
// JavaScript Example for for Single Page Applications (SPA):
// Import OpenReplay
import OpenReplay from '@openreplay/tracker';
// Initialize the tracker
const tracker = new OpenReplay({
projectKey: 'YOUR_PROJECT_KEY',
});
// Start the tracker and wait for it to resolve
tracker.start().then(() => {
// Get the session ID after the tracker has started
const sessionId = tracker.getSessionID();
const headers = {
'Content-Type': 'application/json',
};
// Get the session ID
const sessionId = tracker.getSessionID();
const headers = {
'Content-Type': 'application/json',
};
if (sessionId) {
headers['openReplaySession.id'] = sessionId;
}
// Make the API request
fetch('/api/endpoint', {
method: 'GET', // or 'POST', etc.
headers,
// ...other options
})
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
Include openReplaySession.id in Backend Logs
Section titled Include openReplaySession.id in Backend LogsIn your backend application, extract the openReplaySession.id
from incoming requests and include it in your logs using the specific key-value format openReplaySession.id=<sessionId>
:
// Example.....
// Middleware to extract the session ID
app.use((req, res, next) => {
const sessionId = req.headers['openreplaysession.id'];
req.sessionId = sessionId; // Attach to request object
next();
});
// When logging events or errors
app.get('/api/endpoint', (req, res) => {
// Your logic here
// Log with the session ID in the required format
console.log(`openReplaySession.id=${req.sessionId} - Endpoint accessed`);
res.send('Success');
});
// Error handling middleware
app.use((err, req, res, next) => {
console.error(`openReplaySession.id=${req.sessionId} - Error: ${err.message}`);
res.status(500).send('Internal Server Error');
});
By including the openReplaySession.id
in your backend logs, Dynatrace can collect logs associated with specific OpenReplay sessions. This enables you to view these logs during session replays in OpenReplay, providing a complete picture of user interactions and backend logs.
3. Create Custom Log Attribute in Dynatrace
Section titled 3. Create Custom Log Attribute in DynatraceCreate a custom log attribute in Dynatrace to extract the openReplaySession.id
from your logs.
- Access your Dynatrace SaaS account.
- Go to Settings.
- Select Log Monitoring > Custom attributes and then select Add custom attribute.
- Enter the Key
openReplaySession.id
.
Reference: See the detailed steps in Dynatrace docs: Log custom attributes.
4. Configure Dynatrace Integration in OpenReplay
Section titled 4. Configure Dynatrace Integration in OpenReplayIn your OpenReplay account, follow these 3 steps to complete the session replays correlations with Dynatrace backend logs.
Enable Dynatrace Integration
Section titled Enable Dynatrace Integration- Go to Preferences > Integrations in OpenReplay.
- Select the Backend Logging tab.
- Select the project to which you want to enable the Dynatrace integration: Locate the Dynatrace integration card > Click on it.
Enter Dynatrace Credentials
Section titled Enter Dynatrace CredentialsIn the Dynatrace integration sidebar enter:
- Environment ID: Your Dynatrace environment ID for external access.
- Client ID and Client Secret: Saved from the first step.
- Dynatrace Account URN: Your unique identifier used within the Dynatrace platform, also saved from the first step.
Verify Connection
Section titled Verify Connection- Click on Add to test the connection: A success message will confirm the integration is set up correctly.
5. View Dynatrace Logs in OpenReplay
Section titled 5. View Dynatrace Logs in OpenReplay- Navigate to Sessions in OpenReplay.
- Open any session replay.
- Click on the Traces button.
- Dynatrace logs related to the session will be displayed.
- Click on any log entry to view detailed information.
Logs of types
LOG
with statusesWARN
,ERROR
,INFO
, andNONE
are retrieved using the Dynatrace Log Monitoring API v2.
Have questions?
Section titled Have questions?If you encounter any issues, connect to our Slack or check out our Forum and get help from our community.