{
  "version": "Notebook/1.0",
  "items": [
    {
      "type": 1,
      "content": {
        "json": "# Agentic Gateway — Azure Monitor Workbook\n\nRequests, latency, failures and exceptions of the Agentic Gateway, from the traces it sends to the **Application Insights** resource of `APPLICATIONINSIGHTS_CONNECTION_STRING`.\n\nEach inbound request is one `requests` row named `<METHOD> <route template>` (for example `POST /v1/chat/completions`); a 5xx is a failed request and an `exceptions` row typed by the gateway's error code. Counts use `itemCount`, so they stay right when `OTEL_TRACES_SAMPLER` samples.\n\nToken usage, cost, budget, provider health and the observability self-metrics are Prometheus metrics on the gateway's `/metrics` endpoint. The gateway does not export metrics to Application Insights, so they are not on this workbook: scrape `/metrics` with Azure Monitor managed Prometheus (or any Prometheus) and chart them there.\n\n---"
      },
      "name": "header"
    },
    {
      "type": 9,
      "content": {
        "version": "KqlParameterItem/1.0",
        "parameters": [
          {
            "id": "timeRange",
            "version": "KqlParameterItem/1.0",
            "name": "TimeRange",
            "type": 4,
            "value": {
              "durationMs": 3600000
            },
            "typeSettings": {
              "selectableValues": [
                {
                  "durationMs": 900000
                },
                {
                  "durationMs": 1800000
                },
                {
                  "durationMs": 3600000
                },
                {
                  "durationMs": 14400000
                },
                {
                  "durationMs": 43200000
                },
                {
                  "durationMs": 86400000
                },
                {
                  "durationMs": 604800000
                }
              ]
            },
            "label": "Time Range"
          }
        ],
        "style": "pills",
        "queryType": 0,
        "resourceType": "microsoft.insights/components"
      },
      "name": "parameters"
    },
    {
      "type": 1,
      "content": {
        "json": "## Overview"
      },
      "name": "overview-header"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where name !in ('GET /healthz', 'GET /readyz', 'GET /startupz', 'GET /health', 'GET /metrics')\n| summarize TotalRequests = sum(itemCount)",
        "size": 3,
        "title": "Total Requests",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "tiles",
        "tileSettings": {
          "titleContent": {
            "columnMatch": "TotalRequests",
            "formatter": 12
          },
          "leftContent": {
            "columnMatch": "TotalRequests",
            "formatter": 12
          },
          "showBorder": false
        }
      },
      "name": "tile-total-requests",
      "customWidth": "33"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where name !in ('GET /healthz', 'GET /readyz', 'GET /startupz', 'GET /health', 'GET /metrics')\n| summarize p95_ms = percentile(duration, 95)",
        "size": 3,
        "title": "p95 Latency (ms)",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "tiles",
        "tileSettings": {
          "titleContent": {
            "columnMatch": "p95_ms",
            "formatter": 12
          },
          "leftContent": {
            "columnMatch": "p95_ms",
            "formatter": 12
          },
          "showBorder": false
        }
      },
      "name": "tile-p95-latency",
      "customWidth": "33"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where name !in ('GET /healthz', 'GET /readyz', 'GET /startupz', 'GET /health', 'GET /metrics')\n| summarize FailedPct = round(100.0 * sumif(itemCount, success == false) / sum(itemCount), 2)",
        "size": 3,
        "title": "Failed Requests (%)",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "tiles",
        "tileSettings": {
          "titleContent": {
            "columnMatch": "FailedPct",
            "formatter": 12
          },
          "leftContent": {
            "columnMatch": "FailedPct",
            "formatter": 12
          },
          "showBorder": false
        }
      },
      "name": "tile-failed-requests",
      "customWidth": "33"
    },
    {
      "type": 1,
      "content": {
        "json": "## Request Throughput"
      },
      "name": "throughput-header"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where name !in ('GET /healthz', 'GET /readyz', 'GET /startupz', 'GET /health', 'GET /metrics')\n| summarize Requests = sum(itemCount) by bin(timestamp, {TimeRange:grain}), name\n| render timechart",
        "size": 0,
        "title": "Requests per Minute by Route",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "timechart"
      },
      "name": "chart-requests-route",
      "customWidth": "50"
    },
    {
      "type": 1,
      "content": {
        "json": "## Latency"
      },
      "name": "latency-header"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where name !in ('GET /healthz', 'GET /readyz', 'GET /startupz', 'GET /health', 'GET /metrics')\n| summarize\n    p50_ms = percentile(duration, 50),\n    p95_ms = percentile(duration, 95),\n    p99_ms = percentile(duration, 99)\n    by bin(timestamp, {TimeRange:grain})\n| render timechart",
        "size": 0,
        "title": "Request Latency Percentiles — p50 / p95 / p99 (ms)",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "timechart"
      },
      "name": "chart-latency",
      "customWidth": "50"
    },
    {
      "type": 1,
      "content": {
        "json": "## Error Rate"
      },
      "name": "errors-header"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where name !in ('GET /healthz', 'GET /readyz', 'GET /startupz', 'GET /health', 'GET /metrics')\n| summarize Total = sum(itemCount), Errors = sumif(itemCount, toint(resultCode) >= 500)\n    by bin(timestamp, {TimeRange:grain})\n| extend ErrorRatePct = 100.0 * Errors / Total\n| project timestamp, ErrorRatePct\n| render timechart",
        "size": 0,
        "title": "5xx Error Rate (%)",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "timechart"
      },
      "name": "chart-error-rate",
      "customWidth": "50"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "dependencies\n| where timestamp {TimeRange}\n| summarize Calls = sum(itemCount), P95DurationMs = percentile(duration, 95),\n    Failed = sumif(itemCount, success == false) by name\n| top 20 by P95DurationMs desc",
        "size": 0,
        "title": "Slowest Spans inside Requests (dependencies, p95 ms)",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "table"
      },
      "name": "chart-upstream-dependencies",
      "customWidth": "50"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where resultCode in ('401', '402', '429')\n| summarize Requests = sum(itemCount) by bin(timestamp, {TimeRange:grain}),\n    series = strcat(resultCode, ' ', name)\n| render timechart",
        "size": 0,
        "title": "Refused Requests — 401 / 402 / 429 by Route",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "timechart"
      },
      "name": "chart-client-errors",
      "customWidth": "50"
    },
    {
      "type": 1,
      "content": {
        "json": "## Model Calls"
      },
      "name": "traces-header"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "requests\n| where timestamp {TimeRange}\n| where name !in ('GET /healthz', 'GET /readyz', 'GET /startupz', 'GET /health', 'GET /metrics')\n| where name in ('POST /v1/chat/completions', 'POST /v1/flows/chat/completions', 'POST /v1/flows/responses', 'POST /v1/{group_slug}/chat/completions', 'POST /api/v1/agents/{agent_id}/chat/completions', 'POST /v1/messages', 'POST /v1/{group_slug}/messages', 'POST /v1/messages/count_tokens', 'POST /v1/responses', 'POST /v1/{group_slug}/responses', 'POST /v1/completions', 'POST /v1/{group_slug}/completions', 'POST /v1/embeddings', 'POST /v1/{group_slug}/embeddings', 'POST /api/v1/agents/{agent_id}/embeddings', 'POST /v1/images/generations', 'POST /v1/{group_slug}/images/generations', 'POST /api/v1/agents/{agent_id}/images/generations', 'POST /v1/audio/speech', 'POST /v1/{group_slug}/audio/speech', 'POST /api/v1/agents/{agent_id}/audio/speech', 'POST /v1/audio/transcriptions', 'POST /v1/{group_slug}/audio/transcriptions', 'POST /api/v1/agents/{agent_id}/audio/transcriptions', 'POST /v1/audio/translations', 'POST /v1/moderations', 'POST /v1/ocr', 'POST /v1/{group_slug}/ocr', 'POST /v1/decisions', 'POST /v1/{group_slug}/decisions', 'GET /v1/realtime', 'GET /v1/live/sessions', 'GET /v1/realtime/translations', 'POST /v1beta/models/{model_action}', 'POST /v1/models/{model_action}', 'POST /v1/projects/{project}/locations/{location}/publishers/google/models/{model_action}')\n| summarize\n    Count = sum(itemCount),\n    AvgDurationMs = avg(duration),\n    P95DurationMs = percentile(duration, 95),\n    FailureCount = sumif(itemCount, success == false)\n    by bin(timestamp, {TimeRange:grain})\n| render timechart",
        "size": 0,
        "title": "Model-Call Requests",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "timechart"
      },
      "name": "chart-traces",
      "customWidth": "50"
    },
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "exceptions\n| where timestamp {TimeRange}\n| summarize ExceptionCount = sum(itemCount) by bin(timestamp, {TimeRange:grain}), type\n| render timechart",
        "size": 0,
        "title": "Exceptions by Type",
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "visualization": "timechart"
      },
      "name": "chart-exceptions",
      "customWidth": "50"
    }
  ],
  "isLocked": false,
  "fallbackResourceIds": [],
  "styleSettings": {},
  "$schema": "https://github.com/Microsoft/Application-Insights-Workbooks/blob/master/schema/workbook.json"
}
