Guides / Platforms & Tools

Log Inngest Job Results to LogIt

4 min read·Platforms & Tools

Why Log Inngest Jobs

Inngest has its own dashboard, but checking it means switching context. Logging job events to LogIt puts failures in your existing event stream — and Smart Actions can alert you when jobs fail repeatedly.

Step 1: Create a Reusable Wrapper

ts
// lib/logit-job.ts
import { logit } from "@/lib/logit";

export async function withJobLogging<T>(
  jobName: string,
  context: Record<string, unknown>,
  fn: () => Promise<T>
): Promise<T> {
  await logit.now("jobs", {
    event: "Job started",
    description: jobName,
    icon: "⚙️",
    notify: false,
    tags: { job: jobName, status: "started" },
    metadata: context,
  });

  try {
    const result = await fn();

    await logit.now("jobs", {
      event: "Job completed",
      description: `${jobName} succeeded`,
      icon: "✅",
      notify: false,
      tags: { job: jobName, status: "completed" },
      metadata: context,
    });

    return result;
  } catch (err) {
    await logit.now("jobs", {
      event: "Job failed",
      description: `${jobName}${err instanceof Error ? err.message : String(err)}`,
      icon: "❌",
      notify: true,
      tags: { job: jobName, status: "failed" },
      metadata: { ...context, error: err instanceof Error ? err.message : String(err) },
    });

    throw err;  // re-throw so Inngest retries
  }
}

Step 2: Use It in Inngest Functions

ts
// inngest/functions/send-onboarding-email.ts
import { inngest } from "./client";
import { withJobLogging } from "@/lib/logit-job";

export const sendOnboardingEmail = inngest.createFunction(
  { id: "send-onboarding-email" },
  { event: "user/signup.completed" },
  async ({ event, step }) => {
    await withJobLogging(
      "send-onboarding-email",
      { eventId: event.id, email: event.data.email },
      async () => {
        await step.run("send-email", async () => {
          await sendEmail(event.data.email, "welcome");
        });
      }
    );
  }
);

Step 3: Smart Action for Job Failure Spike

FieldValue
NameJob failure spike
Channeljobs
Event nameJob failed
Threshold5
Window10 minutes
Cooldown30 minutes
ActionPush notification

Tips

  • Re-throw errors after logging so Inngest's built-in retry mechanism still fires.
  • Use the job tag to filter the dashboard to a specific function's history.
  • Log job duration in metadata by recording start time and computing elapsed ms at completion.

Try LogIt free

7-day trial. No credit card required.

Start free