Sending Events

Send events from anywhere in your application.

Use the logger you initialized earlier.

If you missed this step, check the SDK Configuration guide.

Every event you send will appear in your Live Events dashboard within a few seconds.

Basic event

import { log } from "@/lib/logs";

await log.info({
  message: "User signed in",
  eventName: "auth.login.succeeded",
  attributes: {
    "user.id": "user_123",
  },
});

💡 Tip

Start simple. Log only important events first. You can always add more fields later as your application grows.

Error event

await log.error({
  message: "Payment failed",
  eventName: "payment.charge.failed",
  attributes: {
    "payment.provider": "stripe",
    "user.id": "user_123",
  },
});

Event with additional fields

await log.error({
  message: "Payment failed",
  eventName: "payment.charge.failed",
  attributes: {
    "payment.provider": "stripe",
    "payment.failure_kind": "gateway_timeout",
    "order.id": "order_456",
  },
  traceId: currentTraceId,
});

eventName is a stable, lowercase identifier for the kind of event. attributes holds structured key/value context — use dotted OpenTelemetry-style keys. See the Event Fields reference for the full shape.

Logging exceptions

try {
  await chargeCustomer();
} catch (error) {
  await log.error({
    message: "Payment failed",
    eventName: "payment.charge.failed",
    attributes: {
      "error.type": (error as Error).name,
      "error.message": (error as Error).message,
      "user.id": "user_123",
    },
  });
}

Available logging methods

MethodPurpose
log.trace()Very fine-grained diagnostic detail
log.debug()Debug information during development
log.info()General application events
log.warn()Unexpected but recoverable situations
log.error()Errors and failed operations
log.fatal()Unrecoverable failures that stop the process

Where should I send events?

Log anything that helps you understand production.

Good examples include:

  • User authentication
  • Failed payments
  • API errors
  • Queue failures
  • Background jobs
  • External API failures

Keep sensitive data out

Avoid logging passwords, tokens, or personal data.

Learn more

Need more control over your events?

What's next?

Now that you're sending events, check the all type of available events you can use.

Found something unexpected? Let us know.