bitter-pager-48976
08/15/2025, 5:17 PMtall-airline-16756
08/15/2025, 5:17 PMtall-airline-16756
08/15/2025, 5:18 PMlk agent update-secrets --secrets "DATADOG_TOKEN=your-client-token"
2. Initialize Datadog Logs: Next, in your client-side code, initialize Datadog logs using environment variables. If you’re using a Next.js app, you’d set NEXT_PUBLIC_DATADOG_CLIENT_TOKEN
and NEXT_PUBLIC_DATADOG_SITE
in your .env.local
file.
3. Set Log Extension: Then, use the LiveKit SDK’s setLogExtension
method to forward those logs to Datadog. Here’s an example:
datadogLogs.init({
clientToken: process.env.NEXT_PUBLIC_DATADOG_CLIENT_TOKEN,
site: process.env.NEXT_PUBLIC_DATADOG_SITE,
});
setLogExtension((level, msg, context) => {
switch (level) {
case LogLevel.debug:
datadogLogs.logger.debug(msg, context);
break;
case <http://LogLevel.info|LogLevel.info>:
<http://datadogLogs.logger.info|datadogLogs.logger.info>(msg, context);
break;
case LogLevel.warn:
datadogLogs.logger.warn(msg, context);
break;
case LogLevel.error:
datadogLogs.logger.error(msg, context);
break;
}
});
4. Example Application: If you want a hands-on example, check out the LiveKit Meet example—it shows this integration in action and can be a great reference.
With this setup, you’ll be able to keep a close eye on your app’s performance and troubleshoot any issues smoothly using Datadog’s analytics. If you have any questions along the way, just let me know—I’m here to help!bitter-pager-48976
08/15/2025, 5:19 PMtall-airline-16756
08/15/2025, 5:20 PMlk agent update-secrets --secrets "DATADOG_REGION=us1"
2. Instrument Your Agent: Use the log_metrics
helper function to handle metrics events. Here’s an example in Python:
from livekit.agents import metrics, AgentSession
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics.log_metrics(ev.metrics)
3. Aggregate Metrics (Optional): If you want to summarize session metrics, you can use the UsageCollector
like this:
from livekit.agents import metrics, AgentSession
usage_collector = metrics.UsageCollector()
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
usage_collector.collect(ev.metrics)
async def log_usage():
summary = usage_collector.get_summary()
<http://logger.info|logger.info>(f"Usage: {summary}")
ctx.add_shutdown_callback(log_usage)
4. Set Up Datadog to Parse Logs as Metrics: Take advantage of Datadog’s log-to-metrics feature to turn your log data into metrics. Just make sure your logs are tagged or structured so Datadog can easily recognize them as metrics.
5. Verify Metrics: Finally, check your Datadog dashboard to see if the metrics are showing up as expected. You can use tags from your LiveKit agent logs to help with querying.
This setup should make it straightforward to monitor and analyze your metrics in Datadog. If you run into any questions or need a hand with anything else, just let me know—I’m here to help!
Sources: Capturing metrics | LiveKit Docs | pnpm-lock.yaml | metrics/send-metrics-to-3p/metrics_server/README.md | Log collection | LiveKit Docs