// src/components/docs/advanced/AdvancedTelemetryPage.tsx
import Link from "@contractspec/lib.ui-link";
import { ChevronRight } from "lucide-react";
import { jsx, jsxs } from "react/jsx-runtime";
function AdvancedTelemetryPage() {
  return /* @__PURE__ */ jsxs("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h1", {
            className: "text-4xl font-bold",
            children: "Telemetry"
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground",
            children: [
              "A ",
              /* @__PURE__ */ jsx("strong", {
                children: "TelemetrySpec"
              }),
              " defines what metrics, logs, and traces to collect for observability. ContractSpec automatically instruments your application based on these specs, ensuring you have the visibility you need to monitor, debug, and optimize your system."
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Why telemetry matters"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "You can't fix what you can't see. Telemetry provides visibility into how your application is performing, where errors are occurring, and how users are interacting with your system. Without proper instrumentation, you're flying blind in production."
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "ContractSpec takes a spec-first approach to telemetry: you declare what you want to observe, and runtime adapters instrument operations automatically. This ensures consistent, comprehensive coverage without manual effort."
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Three pillars of observability"
          }),
          /* @__PURE__ */ jsxs("div", {
            className: "space-y-3",
            children: [
              /* @__PURE__ */ jsxs("div", {
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "text-lg font-semibold",
                    children: "Metrics"
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground",
                    children: "Numerical measurements collected over time. Examples: request count, error rate, latency percentiles, active users, queue depth. Metrics are cheap to collect and store, making them ideal for high-level monitoring and alerting."
                  })
                ]
              }),
              /* @__PURE__ */ jsxs("div", {
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "text-lg font-semibold",
                    children: "Logs"
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground",
                    children: 'Timestamped text records of events. Examples: "User 123 logged in", "Payment failed for order 456", "Database connection pool exhausted". Logs provide detailed context for debugging specific issues.'
                  })
                ]
              }),
              /* @__PURE__ */ jsxs("div", {
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "text-lg font-semibold",
                    children: "Traces"
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground",
                    children: "Records of requests as they flow through your system. A trace shows the complete path of a request—which services it touched, how long each step took, and where errors occurred. Traces are essential for debugging distributed systems."
                  })
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Example TelemetrySpec"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "Here's how telemetry is configured in TypeScript:"
          }),
          /* @__PURE__ */ jsx("div", {
            className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded-lg border p-4 font-mono text-sm",
            children: /* @__PURE__ */ jsx("pre", {
              children: `import { defineTelemetry } from '@contractspec/lib.contracts-spec/telemetry';

export const OrderProcessingTelemetry = defineTelemetry({
  meta: {
    key: 'order.processing.observability',
    version: '1.0.0',
  },
  metrics: [
    {
      name: 'orders_created_total',
      type: 'counter',
      description: 'Total number of orders created',
      labels: ['status', 'payment_method'],
    },
    {
      name: 'order_processing_duration_seconds',
      type: 'histogram',
      description: 'Time to process an order',
      buckets: [0.1, 0.5, 1.0, 2.0, 5.0, 10.0],
      labels: ['status'],
    },
  ],
  traces: [
    {
      operation: 'createOrder',
      sampleRate: 1.0, // Trace 100% of requests
      includeInputs: true,
      includeOutputs: true,
      redactFields: ['creditCard', 'ssn'],
    },
    {
      operation: 'processPayment',
      sampleRate: 0.1, // Trace 10% of requests
      includeInputs: false, // Don't log payment details
    },
  ],
  alerts: [
    {
      name: 'high-error-rate',
      condition: 'error_rate > 0.05',
      duration: '5m',
      severity: 'critical',
      notify: ['pagerduty', 'slack'],
    },
  ],
});`
            })
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Automatic instrumentation"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "ContractSpec automatically instruments:"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "All operations"
                  }),
                  " – Request count, latency, error rate per Command/Query"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "All workflows"
                  }),
                  " – Step execution time, retry counts, compensation events"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "All data views"
                  }),
                  " – Query execution time, result set size"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "All policy decisions"
                  }),
                  " – Decision time, permit/deny ratio"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "System resources"
                  }),
                  " – CPU, memory, disk, network usage"
                ]
              })
            ]
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "You don't need to add instrumentation code manually—the runtime handles it based on your specs."
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Integration with observability platforms"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "ContractSpec supports multiple observability backends:"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Prometheus"
                  }),
                  " – For metrics collection and alerting"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Grafana"
                  }),
                  " – For dashboards and visualization"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Jaeger / Tempo"
                  }),
                  " – For distributed tracing"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Loki"
                  }),
                  " – For log aggregation"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Datadog"
                  }),
                  " – All-in-one observability platform"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "New Relic"
                  }),
                  " – Application performance monitoring"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Honeycomb"
                  }),
                  " – Observability for complex systems"
                ]
              })
            ]
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "You can configure multiple backends and send telemetry to all of them simultaneously."
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Sampling and performance"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "Collecting telemetry has a cost—CPU, memory, network bandwidth, and storage. ContractSpec provides several mechanisms to control overhead:"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Sampling"
                  }),
                  " – Trace only a percentage of requests (e.g., 10%)"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Adaptive sampling"
                  }),
                  " – Automatically reduce sampling rate under high load"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Tail-based sampling"
                  }),
                  " – Keep traces for failed requests, sample successful ones"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Field redaction"
                  }),
                  " – Remove sensitive data from traces and logs"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Aggregation"
                  }),
                  " – Pre-aggregate metrics before sending to reduce network traffic"
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Best practices"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsx("li", {
                children: "Start with high-level metrics (request rate, error rate, latency) and add more detailed instrumentation as needed."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Use structured logging—log events with structured fields, not free-form text."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Set up alerts for critical metrics so you're notified when things go wrong."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Use traces to debug complex issues—they show the complete picture of a request."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Redact sensitive data from logs and traces to comply with privacy regulations."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Review dashboards regularly to understand normal behavior—this makes anomalies easier to spot."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Use sampling to control costs, but always trace errors and slow requests."
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "flex items-center gap-4 pt-4",
        children: [
          /* @__PURE__ */ jsx(Link, {
            href: "/docs/advanced/mcp",
            className: "btn-ghost",
            children: "Previous: MCP Adapters"
          }),
          /* @__PURE__ */ jsxs(Link, {
            href: "/docs/comparison",
            className: "btn-primary",
            children: [
              "Next: Comparison ",
              /* @__PURE__ */ jsx(ChevronRight, {
                size: 16
              })
            ]
          })
        ]
      })
    ]
  });
}
export {
  AdvancedTelemetryPage
};
