billions-lawyer-8588
08/12/2025, 5:30 PMtall-airline-16756
08/12/2025, 5:30 PMtall-airline-16756
08/12/2025, 5:30 PMEventMetric
structure from LiveKit’s metrics system. It’s got these handy start_timestamp_ms
and end_timestamp_ms
fields that log the times in milliseconds.
Here’s a simple way to do it:
1. When a conversation item kicks off, grab the current time in milliseconds and save it as start_timestamp_ms
.
2. Once the conversation item wraps up, record the current time again as end_timestamp_ms
.
3. Then, create an EventMetric
object with those timestamps and add it to your metrics batch.
Check out this example code snippet:
from livekit.agents import metrics
import time
# When a conversation item starts
start_time = int(time.time() * 1000) # Current time in milliseconds
# When the conversation item ends
end_time = int(time.time() * 1000)
# Create the EventMetric for this conversation item
conversation_metric = metrics.EventMetric(
label=your_label,
participant_identity=your_participant_id,
track_sid=your_track_id,
start_timestamp_ms=start_time,
end_timestamp_ms=end_time,
metadata="conversation_item"
)
# Add it to your metrics batch
metrics_batch.events.append(conversation_metric)
If you want to dive deeper, the LiveKit Metrics Documentation has all the details you might need. Feel free to reach out if you have any questions!