Datadog
تعرّف على كيفية دمج أخطاء الواجهة الخلفية في Datadog مع عمليات إعادة تشغيل الجلسات في OpenReplay لتوسيع قدراتك في المراقبة وتصحيح الأخطاء.
1. إنشاء Datadog API Key و Application Key
Section titled 1. إنشاء Datadog API Key و Application Key- انتقل إلى Datadog > Integrations > APIs وأنشئ API Key، أو استخدم المفتاح الموجود.
- في الصفحة نفسها، انقر على Application Keys وأنشئ application key جديدًا.
2. تكوين تكامل Datadog في OpenReplay
Section titled 2. تكوين تكامل Datadog في OpenReplayفي حساب OpenReplay الخاص بك، اتبع هذه الخطوات الثلاث لإكمال ربط عمليات إعادة تشغيل الجلسات بأخطاء الواجهة الخلفية في Datadog.
تفعيل تكامل Datadog
Section titled تفعيل تكامل Datadog- انتقل إلى Preferences > Integrations في OpenReplay.
- حدد علامة التبويب Backend Logging.
- حدد المشروع الذي تريد تفعيل تكامل Datadog له: حدد بطاقة تكامل Datadog > انقر عليها.
إدخال بيانات اعتماد Datadog
Section titled إدخال بيانات اعتماد Datadogفي الشريط الجانبي لتكامل Datadog، أدخل:
- Datadog API Key
- Application Key
التحقق من الاتصال
Section titled التحقق من الاتصال- انقر على Add لاختبار الاتصال
3. تمرير openReplaySession.id
Section titled 3. تمرير openReplaySession.idلربط حدث Datadog بجلسة المستخدم المسجّلة، يجب تمرير معرّف جلسة فريد openReplaySession.id من الواجهة الأمامية إلى الواجهة الخلفية في كل طلب ترغب في تتبّعه. يمكن تحقيق ذلك باستخدام ترويسة HTTP مخصّصة.
الواجهة الأمامية: تضمين openReplaySession.id في طلبات الـ API
Section titled الواجهة الأمامية: تضمين openReplaySession.id في طلبات الـ API// JavaScript Example for for Single Page Applications (SPA):
const sessionId = tracker.getSessionID();
const headers = {
'Content-Type': 'application/json',
};
if (sessionId) {
headers['openReplaySession.id'] = sessionId;
}
// Make the API request
fetch('https://www.your-backend.com/api/endpoint', {
method: 'GET', // or 'POST', 'PUT', etc.
headers,
// ...other options
})
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
الواجهة الخلفية: تضمين openReplaySession.id في السجلات
Section titled الواجهة الخلفية: تضمين openReplaySession.id في السجلاتفيما يلي مثال بلغة Python يستخدم وحدة logging لتضمين openReplaySession.id تلقائيًا في سجلاتك.
import logging
from flask import Flask, request, g
app = Flask(__name__)
# Configure the root logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
# Create a custom logging filter
class OpenReplayFilter(logging.Filter):
def filter(self, record):
session_id = getattr(g, 'openreplay_session_id', None)
if session_id:
record.msg = f"[openReplaySession.id={session_id}] {record.msg}"
return True
# Add the filter to the logger
logger.addFilter(OpenReplayFilter())
@app.before_request
def before_request():
# Extract the session ID from headers and store it in the Flask `g` object
g.openreplay_session_id = request.headers.get('openReplaySession.id')
@app.route('/api/endpoint')
def api_endpoint():
# Your logic here
# Log an event with the session ID automatically included
logger.info("Endpoint accessed")
return 'Success', 200
@app.errorhandler(Exception)
def handle_exception(e):
# Log the error with the session ID automatically included
logger.error(f"Error: {str(e)}")
return 'Internal Server Error', 500
if __name__ == '__main__':
app.run()
هل لديك أسئلة؟
Section titled هل لديك أسئلة؟إذا واجهت أي مشكلات، تواصل معنا عبر Slack أو تفقّد المنتدى الخاص بنا واحصل على المساعدة من مجتمعنا.