All recipes
OpenTelemetry.
CodeGenericOTLP
Use the SDK's `beforeSend` hook to mirror every captured event into your OpenTelemetry pipeline. Lets you correlate upstream health signals against the rest of your trace and metric data without leaving your APM.
Mirror events to your OTel exporter.
instrumentation.ts
import { metrics } from "@opentelemetry/api";
import { initCheckUpstream } from "@checkupstream/sdk/integrations/next";
const meter = metrics.getMeter("checkupstream");
const latency = meter.createHistogram("upstream.latency_ms", { unit: "ms" });
const errors = meter.createCounter("upstream.errors");
export function register() {
initCheckUpstream({
sdkKey: process.env.CHECKUPSTREAM_SDK_KEY!,
beforeSend: (events) => {
for (const e of events) {
latency.record(e.latency_ms, { service: e.service, method: e.method });
if (e.error_class) {
errors.add(1, { service: e.service, error_class: e.error_class });
}
}
// Return the events so CheckUpstream still ingests them.
return events;
},
});
}Note
Returning `null` from `beforeSend` drops the batch entirely. Returning the events array lets CheckUpstream and your OTel collector both receive them — useful while you migrate or run them in parallel for sanity checks.
Related
Ship reliable upstream.
Drop the SDK in, point it at your project key, and start seeing live upstream telemetry inside the dashboard.