Sending logs

SDKs send logs to Hypertune Edge in the background. This allows you to:

Manually flush logs

You can manually trigger and wait for logs to be flushed with the flushLogs method:

import { NextFetchEvent, NextRequest } from "next/server";
import getHypertune from "./lib/getHypertune";

export async function middleware(
  req: NextRequest,
  context: NextFetchEvent
): Promise<void> {
  const hypertune = await getHypertune();

  const exampleFlag = hypertune.exampleFlag({ fallback: false });
  console.log("Middleware Example Flag:", exampleFlag);

  context.waitUntil(hypertune.flushLogs());
}

This is particularly useful in serverless and edge environments like Vercel deployments, Cloudflare Workers, AWS Lambdas, etc, where background SDK tasks like flushing logs aren't guaranteed to execute.

Last updated