// @bun
import{CodeBlock as t,InstallCommand as o}from"@contractspec/lib.design-system";import r from"@contractspec/lib.ui-link";import{ChevronRight as i}from"lucide-react";import{jsx as e,jsxs as a}from"react/jsx-runtime";function s(){return a("div",{className:"space-y-8",children:[a("div",{className:"space-y-4",children:[e("h1",{className:"font-bold text-4xl",children:"Observability Library"}),a("p",{className:"text-lg text-muted-foreground",children:["The ",e("code",{children:"@contractspec/lib.observability"})," library provides a thin wrapper around OpenTelemetry to simplify instrumentation."]})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Installation"}),e(o,{package:"@contractspec/lib.observability"})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Tracing"}),e(t,{language:"typescript",code:`import { traceAsync, traceSync } from '@contractspec/lib.observability/tracing';

await traceAsync('process_order', async (span) => {
  span.setAttribute('order_id', order.id);
  await db.save(order);
});`})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Metrics"}),e(t,{language:"typescript",code:`import { createCounter, createHistogram } from '@contractspec/lib.observability/metrics';

const ordersCounter = createCounter('orders_total');
const latencyHistogram = createHistogram('request_duration_seconds');

ordersCounter.add(1, { status: 'success' });
latencyHistogram.record(0.123);`})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Middleware"}),e("p",{className:"text-muted-foreground",children:"Automatically instrument your HTTP handlers:"}),e(t,{language:"typescript",code:`import { createTracingMiddleware } from '@contractspec/lib.observability/tracing/middleware';

app.use(createTracingMiddleware());`})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Anomaly Detection"}),e("p",{className:"text-muted-foreground text-sm",children:"Includes baseline calculation and anomaly detection helpers for auto-rollback without writing custom math."}),e(t,{language:"typescript",code:`import { AnomalyDetector, RootCauseAnalyzer, AlertManager } from '@contractspec/lib.observability';

const detector = new AnomalyDetector({ errorRateDelta: 0.4 });
const analyzer = new RootCauseAnalyzer();
const alertManager = new AlertManager({ transport: sendOpsAlert });

const signals = detector.evaluate(point);
signals.forEach((signal) => {
  const analysis = analyzer.analyze(signal, recentDeployments);
  alertManager.notify(signal, analysis);
});`})]}),a("div",{className:"flex items-center gap-4 pt-4",children:[e(r,{href:"/docs/libraries",className:"btn-ghost",children:"Back to Libraries"}),a(r,{href:"/docs/libraries/slo",className:"btn-primary",children:["Next: SLO ",e(i,{size:16})]})]})]})}export{s as LibrariesObservabilityPage};
