Skip to main content

Logging

Logging is how you find out what your applications actually sent to a model, what came back, what it cost and how long it took. The gateway records every request in its own spend logs, and callbacks forward the same data to the observability platforms your teams already use. A callback receives the request, the response, token usage, cost, latency, the calling key and team, and any metadata, for both successful and failed calls. Callbacks are configured once and apply to every endpoint, so an application never has to change to be logged.

A real-world scenario​

A support team ships an assistant that answers tickets through the gateway. One morning a customer complains about a wrong answer, and the support lead wants to see the exact conversation, which model answered and what the request cost. The platform admin added a Langfuse callback from the Admin UI when the gateway went live, so every call already lands in the team's Langfuse project. The lead searches for the ticket id the application put in the request metadata, opens the trace, and sees the prompt, the response, the model, the tokens and the cost. No one had to redeploy anything.

Add a callback from the Admin UI​

  1. Sign in as a proxy admin and open Settings, then Logging & Alerts. The Logging Callbacks tab opens first and lists the callbacks that run for every request under Active Logging Callbacks.

  2. Click Add Callback. In the Add Logging Callback dialog, pick the destination in the Callback dropdown, for example Langfuse.

  3. Fill in the fields the dialog shows for that destination. For Langfuse they are Public Key, Secret Key, Host URL and Tracing Environment. Fields marked required must be filled.

  4. Click Add Callback. The dialog closes with the message "Callback langfuse added successfully" and the new row appears in the table with the mode badge Success.

  5. Open the row's actions menu and click Test. The gateway sends a mock request through the callback and shows "Health check triggered". Check the destination for the test event.

  6. Confirm from the API which callbacks are active:

    curl http://localhost:4000/callbacks/list \
    -H "Authorization: Bearer $SPANWAY_API_KEY"

    Expected result:

    {
    "success": ["langfuse", "prometheus"],
    "failure": ["langfuse"],
    "success_and_failure": ["otel"]
    }

Saving stores the field values encrypted in the database as environment variables and registers the callback as a success callback. No restart or config file change is needed. GET /callbacks/configs returns the same catalogue of destinations and fields the dialog is built from, and GET /active/callbacks shows the raw callback lists together with the alerting destinations.

Add a callback in the config file​

Callbacks can also live in spanway_settings, which suits infrastructure as code and the destinations the Admin UI cannot add.

spanway_settings:
success_callback: ["langfuse", "prometheus"]
failure_callback: ["langfuse"]
callbacks: ["otel"]

success_callback runs after successful calls, failure_callback after failed ones, and callbacks for both. Each integration reads its own environment variables, listed on its page. Restart the gateway after a change. The startup log prints Initialized Success Callbacks - [...] and Initialized Failure Callbacks - [...] with the names it loaded.

Built-in integrations​

Callback nameDestination
langfuse, langfuse_otelLangfuse, see Langfuse integration
langsmithLangSmith, see LangSmith integration
gcs_bucket, gcs_pubsubGoogle Cloud Storage or Pub/Sub, see GCS bucket
s3_v2Amazon S3
otelAny OpenTelemetry collector, see OpenTelemetry
levoLevo, see Levo integration
prometheusPrometheus metrics at /metrics, see Prometheus metrics
datadog, datadog_llm_observabilityDatadog logs and LLM observability
newrelic, signoz, arize, galileo, braintrust, posthog, agentops, deepevalTheir respective platforms, see New Relic
cloudzero, vantage, focus, mavvrik, pointfiveCost management platforms
aws_sqs, zerobus, generic_apiQueues and any HTTP endpoint
pagerdutyIncident alerts
smtp_email, sendgrid_email, resend_emailEmail notifications, see email

Destinations the Admin UI can add​

DestinationCallback nameFields
AgentOpsagentopsAPI key, service name, environment
ArizearizeAPI key, space ID
Arize Phoenixarize_phoenixAPI key, collector endpoint (HTTP or gRPC), project name
Azure Blob Storageazure_storageStorage account, container, then an account key or a service principal
BraintrustbraintrustAPI key, API URL
Custom Callback APIgeneric_apiEndpoint URL, headers
Databricks ZerobuszerobusWorkspace URL, server endpoint, client ID and secret, table name
Datadog, Datadog Metricsdatadog, datadog_metricsAPI key, site
Datadog LLM Observabilitydatadog_llm_observabilityAPI key, site
DeepEvaldeepevalConfident AI API key
GalileogalileoAPI key or username and password, project, log stream, base URL
Google Cloud Storagegcs_bucketBucket name, service account path
Google Cloud Pub/Subgcs_pubsubProject ID, topic ID, service account path
LagolagoAPI URL, API key, billable metric code, charge by
Langfuse, Langfuse OTELlangfuse, langfuse_otelPublic and secret key, host, tracing environment
LangsmithlangsmithAPI key, project, base URL, sampling rate, tenant ID
LangtracelangtraceAPI key, API host
LevolevoAPI key, organization ID, workspace ID, collector URL
Literal AIliteralaiAPI key, API URL
LogfirelogfireWrite token, base URL
Microsoft Sentinelazure_sentinelIngestion endpoint, data collection rule ID, stream name, tenant ID, client ID and secret
New RelicnewrelicLicense key, app name
OpenMeteropenmeterAPI key, API endpoint
OpenTelemetryotelEndpoint, traces endpoint, headers, protocol
OpikopikAPI key, workspace, project name, API URL
PointFivepointfiveAPI key, API URL
PostHogposthogProject API key, API URL
SigNozsignozIngestion endpoint and key

Secret fields such as API keys, tokens and passwords are masked in the form, and a secret that is only set in the gateway's environment is never sent back to the browser. Saving an edit without retyping such a secret keeps the current value. Changing a destination field such as the host, URL, endpoint or site while keeping the stored secret is refused with a 400 that names both fields, so a stored key is never sent to a new place without someone typing it again. Retype the secret together with the new destination. The same check applies to team and key callbacks, and a masked value sent back from the form is never saved as the secret. Where a destination supports it, the Test action on a saved callback sends a mock request through it, so check the destination for the event. Destinations with their own guide link to it from the form, and the rest link back to this section.

The routes behind this form and the alert settings, GET /get/config/callbacks, POST /config/callback/delete and GET /alerting/settings, are internal to the Admin UI. They are left out of the published API reference and the Python and TypeScript clients because their shape follows the screens and can change between releases, so scripts and infrastructure as code should set callbacks and alerting in the config file instead.

The form also lists S3, SQS and Datadog Cost Management, but today those only take effect when they are also set up in the config file, through s3_callback_params, aws_sqs_callback_params and the callbacks list respectively. The Test action is hidden for those three and for Microsoft Sentinel, Literal AI, DeepEval, Levo and AgentOps, eight destinations in all. For them, send one real request and look for it in the destination.

Deleting a gateway wide callback with Delete removes its name from the success callbacks only. Its credentials stay stored, encrypted, in the gateway's environment variables setting. To clear them, open the callback again before deleting it and empty its fields, or remove the variables from the config file. Only callbacks in the success list can be deleted from the Admin UI, a callback set under callbacks or failure_callback in the config file answers 404.

Destinations that need more than environment variables, such as Prometheus (its /metrics route is mounted from the config file at startup), the CloudZero and Vantage exports (CloudZero from its own tab on this page, Vantage through its API, see cost exports), the FOCUS and Mavvrik exports (their jobs are scheduled at startup), Argilla (it needs argilla_transformation_object) and DynamoDB (it needs dynamodb_table_name in spanway_settings), are configured in the config file instead. The same goes for name-dispatched loggers such as Helicone and Sentry, which initialize once per process and would stay inactive until a restart.

Who can turn logging off​

Nobody but an admin can stop the gateway wide callbacks for a request, so the logs an admin relies on cannot be skipped by a caller.

ControlDefaultWhat it does
A key's disabled callbacks listemptyA proxy admin can list callbacks a key's requests skip, with the Disabled Callbacks picker on the key form or metadata.spanway_disabled_callbacks. Use it for a test key whose traffic should not reach a paid destination. Needs an Enterprise license.
x-spanway-disable-callbacks headerignoredA comma separated list of callbacks one request should skip. It is honoured only when an admin sets spanway_settings.allow_dynamic_callback_disabling: true. Leave it off unless every key holder may hide their own requests from your logging, because any caller can send the header. Needs an Enterprise license.
no-log in the request bodydroppedThe gateway removes it from client requests, so it never skips logging. The gateway sets it only on its own internal calls. spanway_settings.global_disable_no_log_param: true also makes the gateway ignore it on internal calls.
turn_off_message_loggingoffKeeps prompts and answers out of every destination while usage and cost are still logged, see below. This is the right switch for sensitive content.

What is logged​

Each log entry carries the model and model group, provider, call type, request and response, prompt and completion tokens, cost, start and end time, cache hit flag, the key alias, user, team, organization, end user, tags, request id and your metadata. Request and response content can be redacted for callbacks with spanway_settings.turn_off_message_logging: true, and per request by passing turn_off_message_logging: true in the request, so that only usage and cost reach the platform. Under a zero data retention policy every callback receives the redacted payload whatever these settings say. The gateway's own spend logs keep request and response content only when store_prompts_in_spend_logs is on, which it is not by default, and what Spanway stores lists every store and its rules.

A request that used a managed prompt also carries prompt_management_metadata in its metadata, with prompt_id, prompt_variables and prompt_integration. The prompt version and environment that were served are not recorded yet. prompt_variables holds what the application sent, which can include names and similar personal data, so treat it as request content when you choose where logs go.

Per-request metadata​

Anything under metadata in the request body is passed to callbacks. Integrations map well known keys, such as generation_name, trace_id, session_id and tags, onto their own concepts.

curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"model": "claude-haiku-5-5", "messages": [{"role": "user", "content": "Hi"}], "metadata": {"generation_name": "greeting", "tags": ["onboarding"]}}'

Expected result: the response is the normal chat completion, and within a few seconds the destination shows a generation named greeting tagged onboarding, with the key alias, team and user the gateway added.

Team and key level logging​

Teams can send their traffic to their own Langfuse or LangSmith project with team callbacks, described in team logging. Team and key logging needs a Spanway Enterprise license with the scoped_integrations feature, while the gateway wide callbacks on this page are free. For logic of your own, write a custom callback. For alerts rather than logs, see alerting.

Errors​

StatusWhereMeaningFix
401GET /callbacks/list, GET /callbacks/configsThe request carried no valid virtual key or master key.Send Authorization: Bearer <key> with a valid key.
400 naming a destination field and a secret fieldSaving a callback in the Admin UIThe host, URL, endpoint or site changed while the stored secret was kept, so the gateway refuses to send the stored secret to a new place.Retype the secret together with the new destination and save again.
400 ... set in the config file and cannot be changed hereSaving a callback or alert settingThe setting is fixed in the config file, and the database may not override it.Change it in the config file and restart, or remove it from the config file first.
403 Admin-only endpoint. Not allowed to access this., your role=<role>Deleting a callback (POST /config/callback/delete)The caller is a proxy admin viewer or another non-admin role.Sign in as a proxy admin.
403 Only proxy admins can update configSaving a callback (/config/update)The same, for saving.Sign in as a proxy admin.
400 DB not connected. This endpoint needs a database; set DATABASE_URL ...Deleting a callback (POST /config/callback/delete)The gateway runs without a database.Set DATABASE_URL.
404 Callback '<name>' not found in active configurationDelete in the Admin UIThe callback is not in the success callback list, for example it was set under callbacks or failure_callback in the config file.Remove it from the config file instead.
500 DB not connected. This endpoint needs a database; ...Delete in the Admin UIThe gateway runs without a database, so no saved callbacks exist to delete.Set DATABASE_URL and restart, or remove the callback from the config file.
500 Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature.Delete in the Admin UIThe gateway does not store its config in the database, so there is nothing to delete from.Set STORE_MODEL_IN_DB=True, or remove the callback from the config file.
400 Service must be specified. or Service must be in list. Service=<x> not in [...]Test (GET /health/services)The destination has no test.Send one real request and check the destination.
422 "<name>" is not set up on this gateway. Add it to spanway_settings.success_callback to test it.TestThe callback is not loaded on this gateway.Save the callback first, then test it.
403 Only proxy admins can trigger the webhook test alert., ... the New Relic test event. or ... the PointFive liveness ping.TestThose tests send a real alert or event, so only proxy admins may run them.Sign in as a proxy admin.
Destination stays empty with no errorAny callbackThe callback is not in GET /callbacks/list, or the destination rejected the events.Check the list, then look for Spanway.LoggingError lines in the gateway log and the spanway_callback_logging_failures_metric counter.

Audit​

Saving or deleting a gateway wide callback writes an updated or deleted row on Spanway_Config with object_id spanway_settings (the callback lists before and after), and saving its credentials writes object_id environment_variables with every value REDACTED. Filter the audit log on Gateway settings. Team callback changes are described in team logging.

Logs​

LevelLineMeaning
Startup outputInitialized Success Callbacks - ['langfuse', 'prometheus'] and Initialized Failure Callbacks - [...]The success_callback and failure_callback lists loaded. Normal. A name missing here was not recognised. Names under callbacks only print Initialized Callbacks - [...] at DEBUG, so confirm them with GET /callbacks/list.
ERRORSpanway.LoggingError: [Non-Blocking] Exception occurred while success logging ...A callback raised while handling a request. The request itself was unaffected. The traceback that follows names the destination and the cause, often bad credentials or an unreachable host. spanway_callback_logging_failures_metric counts these.
WARNINGModel=... not found in completion cost map. Setting 'response_cost' to NoneThe model has no price, so cost is logged as empty. Add a price with custom pricing.
WARNINGDEBUG OUTPUT PRINTS REQUEST AND RESPONSE BODIES: ...The gateway runs with --detailed_debug, SPANWAY_LOG=DEBUG or SPANWAY_PRINT_STANDARD_LOGGING_PAYLOAD, which print prompts and responses to the log. Never run this in production.