Skip to main content

What are Events?

Events are timestamped milestones within a trace. They record significant moments in your application flow, such as user actions, state changes, or external interactions.
Events recorded while a span is open nest under it in the trace timeline. Use span.addEvent() (or trace.addEvent() while a span is active) to group events by operation.

Adding Events

Use addEvent() to record an event:

With Details

Events can include additional details as a string or object:

With Custom Timestamp

By default, events use the current time. You can provide a custom timestamp using a Date object:

Event Patterns

User Interaction Flow

Error Handling

State Transitions

Method Signature

AddEventOptions

Severity Levels

Events can carry a severity level to distinguish informational milestones from warnings and errors. You can set the severity explicitly via the severity option:

Convenience Methods

info(), warn(), and error() are shortcuts that set the severity automatically:

When to Use Each Level

Example: Severity in a Try/Catch Flow

Best Practices

Use Consistent Naming

Adopt a naming convention for events:

Record Both Success and Failure

Always capture the outcome:

Include Relevant Context

Add details that help with debugging:

Don’t Over-Event

Record significant milestones, not every micro-operation:

Next Steps

Attributes & Tags

Add metadata to your traces

Transaction Hints

Correlate with blockchain transactions