Skip to content

Commit

Permalink
Await forceFlush() metrics with Promise.all()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rindrics committed Oct 18, 2024
1 parent a5e4779 commit 55162a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use server";

import { metricReader } from "@/instrumentation";
import { openai } from "@ai-sdk/openai";
import { streamObject } from "ai";
import { createStreamableValue } from "ai/rsc";
Expand Down Expand Up @@ -57,6 +58,8 @@ export async function generateArtifactStream(
generation.end({
output: result,
});

Promise.all([metricReader.forceFlush()]);
await lf.shutdownAsync();
},
});
Expand Down
19 changes: 10 additions & 9 deletions instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import * as Sentry from "@sentry/nextjs";
import { registerOTel } from "@vercel/otel";

export const metricReader = new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: "https://ingest.us.signoz.cloud:443/v1/metrics",
headers: {
"signoz-access-token": process.env.SIGNOZ_INGESTION_TOKEN,
},
}),
});

export async function register() {
registerOTel({
serviceName: "giselle",
attributes: {
environment: process.env.VERCEL_ENV || "not-set",
},
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: "https://ingest.us.signoz.cloud:443/v1/metrics",
headers: {
"signoz-access-token": process.env.SIGNOZ_INGESTION_TOKEN,
},
}),
exportIntervalMillis: 10000,
}),
metricReader: metricReader,
});

if (process.env.NEXT_RUNTIME === "nodejs") {
Expand Down

0 comments on commit 55162a6

Please sign in to comment.