Docs
DocumentationQuery ReferenceAPI Reference
Open Console→→
DocumentationQuery ReferenceAPI Reference

Platform overview

What is Axiom?QuickstartArchitectureFeatures
Fundamentals
Datasets
Edge deployments
Limits
Performance
Optimize usage
Requirements
Semantic conventions
Glossary
Tour
SecurityRoadmap

Send data

Reference architecturesMethods

Understand data

Console
Query
Builder
Editor
Query results
Visualize
Traces
Metrics
Correlations
Save queries
Stream
Dashboard
Create
Elements
Create
Configure
Element types
Gauge
Heatmap
Log stream
Monitor list
Note
Pie chart
Scatter plot
Statistic
Table
Time series
Sections
Configure
Filter
Monitor
Overview
View status
Configure
Examples
Monitor types
Anomaly
Match
New values
Threshold
Alerting
Overview
Configure
Notifier types
Amp
ChatGPT Workspace Agent
Claude Code
Cursor
Custom Webhook
Discord
Email
incident.io
Jira Service Management
Microsoft Teams
Opsgenie
PagerDuty
Slack
Annotations
Command Menu
Manage
Datasets
Overview
Views
Virtual fields
Access
RBAC
Tokens
CLI
Organization
Labels
Audit log
Settings
Usage and billing
Profile
Extend
Overview
AWS Lambda
AWS PrivateLink
Cloudflare Workers
Cloudflare Logpush
Convex
Grafana
Hex
Netlify
Supabase
Supabase metrics
Tailscale
Terraform
Unkey
Vercel
Intelligence
Overview
Spotlight
AI agents
Overview
MCP Server
Overview
Tools
Query cost limits
Agent-created orgs
Skills
Overview
Axiom alerting
Build dashboards
Control costs
SRE
Translate SPL to APL
Splunk
Overview
Splunk app
Install and configure
Commands
Traces
Examples
Portal
How it works
Set up standard mode
Set up transparent mode
Observability Cloud
OCSF data
OCSF as CIM
SPL command support
Examples
Monitor and troubleshoot

Use cases

ObservabilityProduct analytics
OCSF security data
Overview
Send data
Query data
LLM observability
Overview
Use Vercel AI SDK
Manual instrumentation
OpenAI Agents SDK
GenAI attributes
Redaction policies

Miscellaneous

LLMs
Overview
List of docs pages
Full docs
Query reference
FAQs
Legal
Acceptable use policy
Axiom for Startups terms
Committed use terms
Cookies
Data processing
HIPAA
Partner agreement
Partner program guide
Privacy policy
SLA
Terms of service
Terms of use

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-Dataset header.
  • Metrics use the X-Axiom-Metrics-Dataset header, 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.

Rendering diagram…

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:

YAML
extensions:
  # Accept requests only from Modal
  bearertokenauth:
    scheme: Bearer
    token: ${env:COLLECTOR_TOKEN}

receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318
        tls:
          cert_file: /etc/otelcol-contrib/tls/cert.pem
          key_file: /etc/otelcol-contrib/tls/key.pem
        auth:
          authenticator: bearertokenauth

processors:
  batch:
    send_batch_max_size: 8192

exporters:
  otlphttp/axiom-logs:
    compression: zstd
    endpoint: https://AXIOM_DOMAIN
    headers:
      authorization: Bearer ${env:AXIOM_API_TOKEN}
      x-axiom-dataset: LOGS_DATASET_NAME
  otlphttp/axiom-traces:
    compression: zstd
    endpoint: https://AXIOM_DOMAIN
    headers:
      authorization: Bearer ${env:AXIOM_API_TOKEN}
      x-axiom-dataset: TRACES_DATASET_NAME
  otlphttp/axiom-metrics:
    compression: zstd
    endpoint: https://AXIOM_DOMAIN
    headers:
      authorization: Bearer ${env:AXIOM_API_TOKEN}
      x-axiom-metrics-dataset: METRICS_DATASET_NAME

service:
  extensions: [bearertokenauth]
  pipelines:
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlphttp/axiom-logs]
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlphttp/axiom-traces]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlphttp/axiom-metrics]
Info

Replace AXIOM_DOMAIN with the base domain of your edge deployment. For more information, see Edge deployments.

Replace LOGS_DATASET_NAME, TRACES_DATASET_NAME, and METRICS_DATASET_NAME with the names of the Axiom datasets for logs, traces, and metrics.

Replace the paths in cert_file and key_file with the paths to the TLS certificate and private key for the host name of the Collector. If a load balancer or reverse proxy terminates TLS in front of the Collector, remove the tls section.

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.
shell
COLLECTOR_TOKEN=COLLECTOR_TOKEN AXIOM_API_TOKEN=API_TOKEN \
  otelcol-contrib --config=otel-collector-config.yaml
Info

Replace COLLECTOR_TOKEN with the random token you have generated.

Replace API_TOKEN with the Axiom API token you have generated. For added security, store the API token in an environment variable.

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:

shell
modal secret create modal-otel-collector 'OTEL_HEADER_Authorization=Bearer COLLECTOR_TOKEN'
Info

Replace COLLECTOR_TOKEN with the random token you have generated.

Alternatively, create the Secret in the Modal dashboard with OTEL_HEADER_Authorization as the key and Bearer COLLECTOR_TOKEN as the value.

  1. In Modal, go to the metrics integrations settings page.
  2. In the OpenTelemetry (OTEL) integration section, turn on Enable OTEL integration.
  3. 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.
  4. In Credentials secret, select the modal-otel-collector Secret. The list only shows Secrets that contain OTEL_HEADER_ keys.
  5. Click Connect.
  6. 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-logs service, with attributes such as app_name, function_name, and container_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, and modal.input_events.coldstart_time_us, tagged with app_name, function_name, and other tags. GPU Functions also send GPU metrics such as modal.gpu.compute.utilization and modal.gpu.memory.usage, with a gpu_billing_type tag such as H100.

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:

shell
modal secret create axiom-otel \
  OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://AXIOM_DOMAIN/v1/traces \
  'OTEL_EXPORTER_OTLP_TRACES_HEADERS=Authorization=Bearer API_TOKEN,X-Axiom-Dataset=TRACES_DATASET_NAME'
Info

Replace AXIOM_DOMAIN with the base domain of your edge deployment. For more information, see Edge deployments.

Replace API_TOKEN with the Axiom API token you have generated. For added security, store the API token in an environment variable.

Replace TRACES_DATASET_NAME with the name of the Axiom dataset for traces.

Create a file named traced_inference.py with the following content:

python
import os

import modal

app = modal.App("traced-inference")

image = modal.Image.debian_slim().pip_install(
    "opentelemetry-sdk",
    "opentelemetry-exporter-otlp-proto-http",
)

MODEL_NAME = "MODEL_NAME"


@app.cls(
    gpu="H100",
    image=image,
    secrets=[modal.Secret.from_name("axiom-otel")],
)
class Model:
    @modal.enter()
    def setup(self):
        from opentelemetry import trace
        from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
        from opentelemetry.sdk.resources import Resource
        from opentelemetry.sdk.trace import TracerProvider
        from opentelemetry.sdk.trace.export import BatchSpanProcessor

        # Identify the Modal container and environment that produce each span
        resource = Resource.create({
            "service.name": "traced-inference",
            "service.instance.id": os.environ.get("MODAL_TASK_ID", "local"),
            "deployment.environment.name": os.environ.get("MODAL_ENVIRONMENT", "local"),
        })

        # The exporter reads the endpoint and headers from the axiom-otel Secret
        self.provider = TracerProvider(resource=resource)
        self.provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
        trace.set_tracer_provider(self.provider)
        self.tracer = trace.get_tracer("traced-inference")

        # Measure the cold-start cost of loading the model
        with self.tracer.start_as_current_span("load_model"):
            self.model = load_model()

    @modal.method()
    def generate(self, prompt: str) -> str:
        with self.tracer.start_as_current_span(f"chat {MODEL_NAME}") as span:
            span.set_attribute("gen_ai.operation.name", "chat")
            span.set_attribute("gen_ai.provider.name", "PROVIDER_NAME")
            span.set_attribute("gen_ai.request.model", MODEL_NAME)

            output, input_tokens, output_tokens = run_model(self.model, prompt)

            span.set_attribute("gen_ai.usage.input_tokens", input_tokens)
            span.set_attribute("gen_ai.usage.output_tokens", output_tokens)
            return output

    @modal.exit()
    def shutdown(self):
        # Export buffered spans before the container stops
        self.provider.shutdown()


def load_model():
    # Replace with the code that loads your model onto the GPU
    return None


def run_model(model, prompt):
    # Replace with your inference code. Return the output and the token counts.
    return f"Echo: {prompt}", len(prompt.split()), 2


@app.local_entrypoint()
def main():
    print(Model().generate.remote("Hello from Modal"))
Info

Replace MODEL_NAME with the name of the model, and PROVIDER_NAME with the provider or serving framework of the model.

Replace load_model and run_model with your own code. Change gpu="H100" to the GPU type your model needs. Modal only runs GPU Functions in workspaces that have a payment method.

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 a load_model span. Each cold start appears as a separate load_model trace with the same service.instance.id as the inference calls of that container.
  • The @modal.method() method records each inference call in a chat MODEL_NAME span with the gen_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_ID and MODAL_ENVIRONMENT environment 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:

shell
modal run traced_inference.py

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:

  • LLM observability
  • Manual instrumentation
  • Generative AI attributes

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.

Axiom dashboard with GPU utilization, GPU memory, running containers, inputs, cold start time, Function log errors, and chat latency of Modal apps

GPU utilization

Show the average GPU compute utilization of each app by GPU type:

MPL
`METRICS_DATASET_NAME`:`modal.gpu.compute.utilization`
| align to 5m using avg
| group by app_name, gpu_billing_type using avg

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:

MPL
`METRICS_DATASET_NAME`:`modal.input_events.elapsed_time_us`
| bucket by app_name to 5m using interpolate_delta_histogram(0.95)

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:

MPL
(
  `METRICS_DATASET_NAME`:`modal.input_events.successes`
  | align to 5m using sum
  | group by app_name using sum,
  `METRICS_DATASET_NAME`:`modal.input_events.total_inputs`
  | align to 5m using sum
  | group by app_name using sum
)
| compute success_rate using /

Container terminations

Show why containers stop, for example because they’re idle or run out of memory:

MPL
`METRICS_DATASET_NAME`:`modal.container.terminations`
| align to 5m using sum
| group by reason using sum

Function errors

Find the most frequent errors in Function logs:

APL
['LOGS_DATASET_NAME']
| where ['service.name'] == 'modal.function-logs' and severity_text == 'ERROR'
| summarize errors = count() by app = ['attributes.app_name'], message = body
| order by errors desc

Inference latency and cold starts

Show the median and 95th percentile duration of inference calls from the tracing example:

APL
['TRACES_DATASET_NAME']
| where ['attributes.gen_ai.operation.name'] == 'chat'
| summarize percentiles_array(duration, 50, 95) by bin_auto(_time)

Count cold starts and measure how long model loading takes:

APL
['TRACES_DATASET_NAME']
| where name == 'load_model'
| summarize cold_starts = count(), p95_load_time = percentile(duration, 95) by ['service.name']

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.

What’s next

  • Send OpenTelemetry data to Axiom
  • Query traces
  • Query metrics
Was this page helpful?
Suggest edits on GitHub
On this page
Why the Modal integration needs a CollectorPrerequisitesSend logs and metrics through a CollectorChoose which signals to sendSend traces from Modal FunctionsSend custom spans and metrics through ModalQuery Modal telemetryGPU utilizationInput execution time and cold start timeInput success rateContainer terminationsFunction errorsInference latency and cold startsLimitationsWhat’s next