Laminar allows you to send custom events to the platform. This can be useful for tracking any events that are not covered by the spans and tracing.

Introduction

You can think of events as a data payload attached to a single timestamp. Main difference between events and spans is that events have a single timestamp and don’t have a duration. Events allow you to track any free-form data that happens in your application You can then run queries on the events to get event-based analytics and insights. You can also build custom dashboards to visualize the events.

Sending events

To send an event, simply use the event function on Laminar class.
import { Laminar } from "@lmnr-ai/lmnr"

Laminar.initialize();

Laminar.event({
    name: "my-event",
    attributes: {
        "user-feedback": "positive",
        "user_data": JSON.stringify({
            "name": "John Doe",
            "age": 30,
            "email": "john.doe@example.com"
        })
    }
})

Span context

If you create an event inside a span context, e.g. in an observed function, the event will be associated with the current span. Otherwise, we will create a new span for the event and attach the event to it.

Timestamp

By default, event will have the current timestamp. You can also specify the timestamp manually:
import { Laminar } from "@lmnr-ai/lmnr"

Laminar.initialize();

Laminar.event({
    name: "my-event",
    timestamp: new Date("2025-01-01T00:00:00.000Z")
})

Attributes

Attributes are passed as an object/dictionary. Allowed attribute types are string, number, boolean, string[], number[], boolean[].
If you want to pass a JSON object as an attribute, you need to stringify it first.

Specifying session or user id

You can associate an event with a session id or user id.
import { Laminar } from "@lmnr-ai/lmnr"

Laminar.initialize();

Laminar.event({
    name: "my-event",
    sessionId: "123",
    userId: "456"
})

Querying events

You can query events using the events table in Laminar SQL Editor.
SELECT * FROM events
WHERE session_id = '123'
AND timestamp >= '2025-01-01T00:00:00'