Send Modal telemetry to Axiom
Send logs and GPU container metrics from Modal to Axiom through an OpenTelemetry Collector, and trace AI workloads inside Modal Functions with the OpenTelemetry SDK.
Modal is a serverless platform for running AI inference, training, and batch jobs on GPUs. This page explains how to send two kinds of Modal telemetry to Axiom:
- Platform telemetry: The Modal OpenTelemetry integration exports Modal audit logs, Function logs, and container metrics such as GPU utilization, GPU memory usage, and cold start time. Send this data to Axiom through an OpenTelemetry Collector. For more information, see Send logs and metrics through a Collector.
- Traces from your code: The Modal integration doesn’t create traces. To see how long model loading and each inference call take, instrument your Modal Functions with the OpenTelemetry SDK and send traces directly to Axiom. For more information, see Send traces from Modal Functions.
Why the Modal integration needs a Collector
Axiom routes OpenTelemetry data to datasets with request headers:
- Logs and traces use the
X-Axiom-Datasetheader. - Metrics use the
X-Axiom-Metrics-Datasetheader, and they go to a separate dataset of the metrics type.
The Modal integration sends all signals to one endpoint with one set of headers. You define the headers in a Modal Secret with one key per header, named OTEL_HEADER_ followed by the header name. Modal Secret key names contain only letters, digits, and underscores, so a key name can’t contain the hyphens in X-Axiom-Dataset or X-Axiom-Metrics-Dataset. For more information, see the Modal documentation on OpenTelemetry integration and Secret limits.
As a result, the Modal integration can’t send the Axiom dataset headers, and Axiom can’t route its data to a dataset. An OpenTelemetry Collector solves this problem. Modal authenticates to the Collector with an Authorization header, which is a valid Secret key name. The Collector then forwards each signal to the right Axiom dataset with the right headers.
Prerequisites
- Create an Axiom account.
- Create three datasets in Axiom: one for logs and one for traces with the Events type, and one for metrics with the Metrics type.
- Create an API token in Axiom with permissions to ingest data to the three datasets.
- Create a Modal account and install the Modal Python package.
- To send platform telemetry, prepare a host for the OpenTelemetry Collector that Modal can reach over HTTPS from the internet.
Send logs and metrics through a Collector
Install the OpenTelemetry Collector Contrib distribution. It includes the bearertokenauth extension that the configuration below uses.
Create a Collector configuration file with the following content:
The traces pipeline handles spans that reach the Collector through the Modal integration. For more information, see Send custom spans and metrics through Modal.
Generate a random token that Modal uses to authenticate to the Collector. For example, run openssl rand -hex 32.
Start the Collector with the following environment variables:
COLLECTOR_TOKEN: The random token you have generated.AXIOM_API_TOKEN: The Axiom API token you have generated.
The Collector listens for OTLP over HTTP on port 4318 and rejects requests without the correct token.
Create a Modal Secret named modal-otel-collector that contains the Authorization header Modal sends to the Collector:
Alternatively, create the Secret in the Modal dashboard with OTEL_HEADER_Authorization as the key and Bearer COLLECTOR_TOKEN as the value.
- In Modal, go to the metrics integrations settings page.
- In the OpenTelemetry (OTEL) integration section, turn on Enable OTEL integration.
- In Push URL, enter the base URL of the Collector, for example
https://otel.example.com:4318. Don’t add a signal path such as/v1/logs. Modal adds the path for each signal. - In Credentials secret, select the
modal-otel-collectorSecret. The list only shows Secrets that containOTEL_HEADER_keys. - Click Connect.
- In the Test connection section, click Send test.
In Axiom, the logs dataset receives a Hello from Modal! 🚀 log from the modal.test_logs service.
After your Modal Functions run, Axiom receives the following:
- The logs dataset receives Function logs from the
modal.function-logsservice, with attributes such asapp_name,function_name, andcontainer_id. If your Modal plan includes audit logs, the logs dataset receives them too. - The metrics dataset receives container and Function metrics such as
modal.cpu.utilization,modal.memory.usage, andmodal.input_events.coldstart_time_us, tagged withapp_name,function_name, and other tags. GPU Functions also send GPU metrics such asmodal.gpu.compute.utilizationandmodal.gpu.memory.usage, with agpu_billing_typetag such asH100.
For the full list of metrics and their tags, see the Modal documentation.
Choose which signals to send
By default, the Modal integration forwards all signals. To send only some of them, for example only logs, go to the Telemetry signals section of the metrics integrations settings page, turn off Forward all signals, and then select the signals to send.
Send traces from Modal Functions
AI workloads on Modal spend time in places that logs and container metrics don’t break down: loading model weights during a cold start, waiting on the GPU, and generating tokens. Traces show each of these steps. The example below runs in a Modal Function and sends traces directly to Axiom with the OpenTelemetry SDK for Python. It doesn’t depend on the Modal integration or the Collector.
The OpenTelemetry SDK reads its exporter configuration from environment variables. Modal exposes the keys of a Secret as environment variables in the container. Secret key names that only contain letters, digits, and underscores are valid, and the header names in the values can contain hyphens.
Create a Modal Secret named axiom-otel:
Create a file named traced_inference.py with the following content:
The example uses the following Modal features:
- The
@modal.enter()method runs once when a container starts. It configures the tracer provider and records model loading in aload_modelspan. Each cold start appears as a separateload_modeltrace with the sameservice.instance.idas the inference calls of that container. - The
@modal.method()method records each inference call in achat MODEL_NAMEspan with thegen_ai.*attributes that Axiom uses for its AI trace views. - The
@modal.exit()method exports buffered spans before the container stops. Modal gives exit handlers a grace period of 30 seconds. For more information, see the Modal documentation on container lifecycle hooks. - The
MODAL_TASK_IDandMODAL_ENVIRONMENTenvironment variables identify the container and the Modal environment. For more information, see the Modal documentation on environment variables.
If you instrument a plain @app.function instead of a class, call trace.get_tracer_provider().force_flush() before the function returns. Modal lifecycle hooks are only available on classes.
Run the following command in your terminal:
In Axiom, the traces dataset receives a load_model span and a chat MODEL_NAME span, each in its own trace. The chat span carries the gen_ai.* attributes, so Axiom shows the trace in its AI trace views.
For more information on the attributes of AI spans and how Axiom displays them, see the following:
Send custom spans and metrics through Modal
Modal offers custom metrics and spans as a beta feature that you enable by contacting Modal. With this feature, the OpenTelemetry SDK in your Function sends data to a collector inside Modal, and the Modal integration forwards it with the rest of your platform telemetry. If you set up the Collector above, custom spans go to the traces dataset and custom metrics go to the metrics dataset. For the required environment variables, see the Modal documentation.
Use either this feature or the axiom-otel Secret for a Function, not both, so that each span reaches Axiom once.
Query Modal telemetry
The following queries are a starting point for a dashboard of your Modal workloads. Replace LOGS_DATASET_NAME, TRACES_DATASET_NAME, and METRICS_DATASET_NAME with the names of your Axiom datasets.

GPU utilization
Show the average GPU compute utilization of each app by GPU type:
Input execution time and cold start time
Show the 95th percentile of the time each input takes to run. Modal sends the timing metrics as histograms with delta temporality:
To see how long containers take to start, use the same query with the modal.input_events.coldstart_time_us metric.
Input success rate
Divide the successful inputs by all inputs:
Container terminations
Show why containers stop, for example because they’re idle or run out of memory:
Function errors
Find the most frequent errors in Function logs:
Inference latency and cold starts
Show the median and 95th percentile duration of inference calls from the tracing example:
Count cold starts and measure how long model loading takes:
Limitations
- Modal Secret key names can’t contain hyphens, so the Modal integration can’t send the Axiom dataset headers. To send platform telemetry to Axiom, route it through an OpenTelemetry Collector.
- The Modal integration doesn’t create traces. To trace your workloads, instrument your code with the OpenTelemetry SDK.
- The Collector must be reachable from Modal over the internet. Protect it with the bearer token and TLS as shown above.