Dynatrace
Dynatrace のバックエンドログを OpenReplay のセッションリプレイと連携させて、モニタリングとデバッグの機能を拡張する方法を紹介します。
このインテグレーションは、Cloud(Serverless、Dedicated)および Self-Host (Community, Enterprise) のユーザーが利用できます。
1. Dynatrace の認証情報を生成する
Section titled 1. Dynatrace の認証情報を生成するDynatrace から必要な認証情報を取得する手順は次のとおりです。
- Dynatrace アカウントにログインします。
- Account Management に移動します。
- OAuth クライアントを作成します。
- Identity & Access Management をクリックします。
- OAuth clients を選択します。
- Create client をクリックして、必要な認証情報を生成します。
- 認証情報を保存します。
- クライアントの作成後、次の情報を保存します。
- Client ID
- Client Secret
- Account URN
environment IDを取得します。// Example Dynatrace URL: https://rzr85764.app.dynatrace.com/ Environment ID: rzr85764
2. openReplaySession.id をバックエンドに伝播する
Section titled 2. openReplaySession.id をバックエンドに伝播するDynatrace のログを OpenReplay のセッションと紐付けるには、トラッキング対象とする各リクエストで、一意のセッション ID openReplaySession.id をフロントエンドからバックエンドへ伝播する必要があります。
フロントエンドの API リクエストに openReplaySession.id を含める
Section titled フロントエンドの API リクエストに openReplaySession.id を含めるフロントエンドのコードを変更して、API リクエストのヘッダーに openReplaySession.id を追加します。
// JavaScript Example for for Single Page Applications (SPA):
// Import OpenReplay
import { tracker } from '@openreplay/tracker';
// Initialize the tracker
tracker.configure({
projectKey: 'YOUR_PROJECT_KEY',
ingestPoint: "https://openreplay.mydomain.com/ingest", // when dealing with the self-hosted version of OpenReplay
});
// 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
});
バックエンドのログに openReplaySession.id を含める
Section titled バックエンドのログに openReplaySession.id を含めるバックエンドアプリケーションで、受信したリクエストから openReplaySession.id を取り出し、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');
});
バックエンドのログに openReplaySession.id を含めることで、Dynatrace は特定の OpenReplay セッションに関連付けられたログを収集できます。これにより、OpenReplay でのセッションリプレイ中にこれらのログを確認でき、ユーザーの操作とバックエンドのログの全体像を把握できます。
3. Dynatrace でカスタムログ属性を作成する
Section titled 3. Dynatrace でカスタムログ属性を作成するDynatrace でカスタムログ属性を作成し、ログから openReplaySession.id を抽出できるようにします。
- Dynatrace SaaS アカウントにアクセスします。
- Settings に移動します。
- Log Monitoring > Custom attributes を選択し、続けて Add custom attribute を選択します。
- キーに
openReplaySession.idを入力します。
参考:詳しい手順は、Dynatrace のドキュメント ログのカスタム属性 を参照してください。
4. OpenReplay で Dynatrace インテグレーションを設定する
Section titled 4. OpenReplay で Dynatrace インテグレーションを設定するOpenReplay アカウントで、次の 3 つの手順に従って、セッションリプレイと Dynatrace のバックエンドログの関連付けを完了します。
Dynatrace インテグレーションを有効にする
Section titled Dynatrace インテグレーションを有効にする- OpenReplay で Preferences > Integrations に移動します。
- Backend Logging タブを選択します。
- Dynatrace インテグレーションを有効にするプロジェクトを選択します。Dynatrace インテグレーションカードを見つけて、クリックします。
Dynatrace の認証情報を入力する
Section titled Dynatrace の認証情報を入力するDynatrace インテグレーションのサイドバーで、次の情報を入力します。
- Environment ID:外部アクセス用の Dynatrace 環境 ID。
- Client ID と Client Secret:最初の手順で保存したもの。
- Dynatrace Account URN:Dynatrace プラットフォーム内で使用される一意の識別子。こちらも最初の手順で保存したものです。
接続を確認する
Section titled 接続を確認する- Add をクリックして接続をテストします。成功メッセージが表示されれば、インテグレーションが正しく設定されています。

5. OpenReplay で Dynatrace のログを表示する
Section titled 5. OpenReplay で Dynatrace のログを表示する- OpenReplay で Sessions に移動します。
- 任意のセッションリプレイを開きます。
- Traces ボタンをクリックします。
- セッションに関連する Dynatrace のログが表示されます。
- ログエントリをクリックすると、詳細情報を確認できます。

ステータスが
WARN、ERROR、INFO、NONEのタイプLOGのログは、Dynatrace Log Monitoring API v2 を使用して取得されます。
ご質問はありますか?
Section titled ご質問はありますか?問題が発生した場合は、Slack に参加して、コミュニティのサポートを受けてください。