Applies to v1.3.18

Observability Guide

AI API Mapper emits standard OpenTelemetry signals and exposes Prometheus-compatible metrics. It does not include a collector, a metrics or trace store, or dashboards: you send its telemetry to the observability backend you already run. This guide covers how to connect it and what it emits.


What you connect

Signal How it leaves the platform Where it goes
Traces OTLP export from every .NET service, when an OTLP endpoint is configured Your OpenTelemetry Collector, or any OTLP-capable backend
Metrics OTLP export, when an OTLP endpoint is configured, and a Prometheus scrape endpoint, /metrics, on every .NET service Your collector, or a Prometheus-compatible scraper
Logs Structured lines on each container's standard output, and a rolling file inside the container docker compose logs, or your container log collector

The .NET services are portal-api, runtime-host, jobs-worker and gateway. Portal Web is an nginx container that serves the SPA and is not instrumented.


Sending traces and metrics to your collector

OTLP export is off until it is configured. Two settings turn it on, on each service:

Variable Meaning
Observability__OtlpEndpoint Turns OTLP export of traces and metrics on when it has a value. Set it to your collector's address
OTEL_EXPORTER_OTLP_ENDPOINT The address the OpenTelemetry exporter sends to, e.g. http://otel-collector.example.internal:4317. Without it the exporter sends to http://localhost:4317, which inside a container is the container itself

The exporter is the standard OpenTelemetry .NET exporter, so its other standard variables apply as well, for example OTEL_EXPORTER_OTLP_PROTOCOL (grpc, the default, or http/protobuf for port 4318) and OTEL_EXPORTER_OTLP_HEADERS for a backend that needs an API key.

The installer writes apimapper/docker-compose.yml again on every run, so keep these settings in a file of your own next to it, apimapper/docker-compose.telemetry.yml:

x-otlp: &otlp
  Observability__OtlpEndpoint: http://otel-collector.example.internal:4317
  OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector.example.internal:4317

services:
  portal-api:
    environment: *otlp
  runtime-host:
    environment: *otlp
  jobs-worker:
    environment: *otlp
  gateway:
    environment: *otlp

Start the platform with both files, and again after each upgrade, because the installer restarts it with its own file only:

docker compose --project-directory apimapper --env-file apimapper/.env \
  -f apimapper/docker-compose.yml -f apimapper/docker-compose.telemetry.yml up -d

Add -f for each other file of your own (docker-compose.aisi.yml, docker-compose.proxy.yml in Installing AI API Mapper). If the services reach the outside world through HTTPS_PROXY / HTTP_PROXY (Behind a corporate proxy), add the collector's host name to NO_PROXY unless the telemetry should go through the proxy.

Each service identifies itself with the resource attribute service.name: CodedProjects.AI.ApiMapper.Portal.Api, CodedProjects.AI.ApiMapper.Runtime.Host, CodedProjects.AI.ApiMapper.Jobs.Worker and CodedProjects.AI.ApiMapper.Gateway.Host. service.instance.id is the container's host name, so the replicas of the Jobs Worker can be told apart.


Scraping /metrics

Every .NET service serves its metrics in the Prometheus text format at /metrics, whether or not OTLP export is on. In the installer's deployment the internal ports are not published on the host, so a scraper reaches them from the Compose network:

Service Scrape address
Portal API http://portal-api:5179/metrics
Runtime Host http://runtime-host:5065/metrics
Jobs Worker http://jobs-worker:5188/metrics (the name resolves to every replica; use DNS service discovery to scrape each one)
Gateway https://gateway:5253/metrics

A scraper on the Compose network is one you add as a service in a compose file of your own; one outside it uses OTLP instead. Observability__EnablePrometheusScrapingEndpoint: "false" removes the endpoint from a service.


Signals emitted by the platform

Traces

All services emit ASP.NET Core request spans and spans for their outgoing HTTP calls (downstream APIs, LLM providers, identity providers), with exceptions recorded on the span. Message-bus activity is traced through MassTransit's own instrumentation, so a request that leads to background work shows the message hop. Everything the platform emits itself is on a single activity source, CodedProjects.AI.ApiMapper.Platform, including ESRA's retrieval-stage spans and AISI's pipeline spans.

Request spans carry the standard OpenTelemetry HTTP attributes, such as http.request.method, http.route and http.response.status_code.

Metrics

All services expose standard ASP.NET Core, HTTP client and .NET runtime metrics. The platform's own instruments are published on a single meter, CodedProjects.AI.ApiMapper.Platform:

Metric Description
http_server_request_duration_seconds ASP.NET request latency histogram
runtime_tool_list_requests_total Tool listing counter
runtime_tool_invocations_total Tool invocation counter
runtime_tool_invocation_duration_ms Tool invocation latency histogram
runtime_downstream_requests_total Downstream call counter
runtime_downstream_request_duration_ms Downstream API latency histogram
runtime_downstream_response_rejected_total Downstream responses rejected by validation
runtime_auth_results_total Runtime authentication outcomes
llm.spend.tokens (Prometheus: llm_spend_tokens_total) Model tokens spent, tagged usage (functionality), purpose (stage) and direction (input/output). Added by the usage ledger's background flush in Runtime Host, Jobs Worker and Portal API, so it matches the LLM Usage Dashboard without querying the database. Tenants are not a tag: their cardinality is unbounded
hosted_agent_executions_total Hosted-agent executions that ended, tagged status and, where known, channel (Schedule, Webhook, Manual, A2a), failure_kind and tenant.id. Counted where the end is recorded, so it includes executions ended by the Jobs Worker's reaper and cancellations from the Portal
hosted_agent_execution_duration_seconds How long a hosted-agent execution ran, start to end, tagged channel and status. Executions that never started (skipped, or cancelled while queued) are not recorded
hosted_agent_executions_queued Hosted-agent executions waiting to start, across the deployment, as last sampled by the Jobs Worker's execution reaper (every minute by default)
hosted_agent_schedule_lag_seconds How long after its scheduled time a schedule trigger started, recorded by the Jobs Worker
hosted_agent_webhook_requests_total Webhook deliveries to hosted-agent triggers, tagged with the response status code (http.response.status_code)
dotnet_gc_collections_total GC collection counters
process_working_set_bytes Process memory

Tool invocation errors are read off runtime_tool_invocations_total by its outcome tag rather than from a separate counter. AISI's own metrics are described in AISI — operations.

For hosted agents, the useful views are executions ended by status, executions waiting, the 95th-percentile execution duration by channel, and webhook deliveries by response status beside the 95th-percentile schedule lag. A rising share of webhook 401s points at a sender with the wrong secret; 429s at an agent whose queue is full; a growing schedule lag at a Jobs Worker that is stopped or overloaded. See Monitoring Agent Runs.

Logs

Logs are structured (Serilog), written to the console and to a rolling file inside the container (daily, and at 5 MB, keeping the last 50 files). The console output is what docker compose logs <service> shows and what a container log collector picks up. Every log line for a request carries CorrelationId; request-completion lines additionally carry the ASP.NET TraceIdentifier, the request host and scheme, the client address and the requested tenant.

The client address in the request log is reduced to its network (/24 for IPv4, /48 for IPv6), because a full address is personal data. Set Observability__LogFullClientAddress: "true" on a service to log full addresses, for example during an incident, and mind the retention of whatever collects the logs.

To tie a trace to its log lines, search the logs for the CorrelationId; it is also returned to the caller on the X-Correlation-Id response header.


Correlation IDs

Every request carries a correlation ID, surfaced on the X-Correlation-Id response header and as the CorrelationId property on every log line for that request.

Where the ID comes from depends on who is calling:

Host Inbound X-Correlation-Id Behavior
Portal API, Jobs Worker, Gateway Present Adopted as the correlation ID, so a trace spans platform components
Portal API, Jobs Worker, Gateway Absent Generated
Runtime Present Not adopted. A correlation ID is generated (this is the execution ID) and the caller's value is recorded separately as the external correlation ID
Runtime Absent Generated

The Runtime is the AI-facing edge, so an inbound header there is caller input. Trusting it would let a caller merge its records into another caller's execution trace, so the Runtime always generates its own. The caller's value is not discarded: it is sanitized, stored as the external correlation ID on every governance audit record for the call, echoed back on X-External-Correlation-Id, and pushed onto the log context as ExternalCorrelationId.

See Runtime Governance for the acceptance rules and how operators search by it.


Metrics endpoint security

Outside the Development environment, /metrics and the /health endpoints answer only:

  • requests from loopback and private addresses (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, link-local, and IPv6 unique-local), which includes a scraper on the Compose network;
  • requests from a network listed in Observability__DiagnosticAllowedNetworks__<n> (CIDR, e.g. 203.0.113.0/24);
  • for /metrics only, requests carrying Authorization: Bearer <token> when Observability__MetricsBearerToken is set. Use it for a scraper that cannot be placed on a private network; generate the token with openssl rand -hex 32.

Any other request is answered 404. The client address is the one resolved through the trusted proxies described in Deployment Topology. Observability__RestrictDiagnosticEndpointsToLocalNetworks: "false" lifts the restriction altogether; leave it on unless something else in front of the services already restricts these paths. The settings are listed in the Configuration reference.


Retention and storage

The platform keeps no telemetry of its own beyond each container's log files (50 files of up to 5 MB per container, removed with the container). How long traces, metrics and logs are kept is set in the backend you send them to.