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",
  track:{
    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: "Stripe payment failed",
  track:{
    user_id:"user_123"
   }
});

Event with additional fields

await log.error({
  message: "Payment gateway timeout",
  service: "billing",
  operation: "create-payment",
  subsystem: "stripe",
  importance: "high",
});

Logging exceptions

try {
  await chargeCustomer();
} catch (error) {
  await log.error({
    message: "Failed to charge",
    track:{
     user_id:"user_123"
    }
  });
}

Available logging methods

MethodPurpose
log.info()General application events
log.warn()Unexpected but recoverable situations
log.error()Errors and failed operations
log.debug()Debug information during development

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.