Zero-code Python tracing

Trace an existing Python app with fi-instrument, verify a model call in Tracing, and use doctor to distinguish a missing package from a pending import.

About

Start your Python app with fi-instrument to trace supported library calls without changing the app. In this example, you hide the support question and answer from the trace but keep the model, latency and token counts for a Ridgeline Outfitters request.

Trace a support request

Install the launcher and the provider instrumentor

Use the same Python environment as your app. The example uses Python 3.10 to 3.13, the OpenAI client that makes the request, and traceai-openai, the package that traces it. Installing packages alone does not turn tracing on.

python3 -m venv .venv
. .venv/bin/activate
python -m pip install 'fi-instrumentation-otel==1.5.1' 'traceai-openai==0.1.16' openai

Set the destination and choose what to capture

Load both Future AGI keys from the same source, such as your deployment’s secret manager. If you can’t open the keys page, ask your organization owner or an admin for access to the key pair. The model client needs its own credentials. For a terminal session, replace the placeholders and choose a chat model your account can use:

export FI_API_KEY="YOUR_API_KEY"
export FI_SECRET_KEY="YOUR_SECRET_KEY"
export FI_BASE_URL="https://api.futureagi.com"
export FI_PROJECT_NAME="ridgeline-support"
export FI_INSTRUMENTATIONS="openai"
export FI_HIDE_INPUTS=true
export FI_HIDE_OUTPUTS=true
export FI_HIDE_ERROR_DETAILS=true
export OPENAI_API_KEY="YOUR_MODEL_PROVIDER_KEY"
export OPENAI_MODEL="gpt-4.1-mini"

Prompts, responses and supported tool content are captured by default. For this chat call, the hide settings mask the question and answer and suppress exception details in the Future AGI export; they don’t configure your other exporters. For an OpenAI-compatible provider, also set OPENAI_BASE_URL to its API and use its model ID. If you self-host, set FI_BASE_URL to your Future AGI HTTP collector’s origin, not the model provider’s URL. The launcher, doctor and validate all send to FI_BASE_URL when it is set, even if FI_TRACES_URL is also set.

Launch the unchanged app

Use your own OpenAI app, or save this as support.py. There are no tracing imports:

import os
from openai import OpenAI

reply = OpenAI().chat.completions.create(
    model=os.environ["OPENAI_MODEL"],
    messages=[
        {"role": "system", "content": "You answer gear-care questions for Ridgeline Outfitters."},
        {"role": "user", "content": "How should I dry a rain jacket after a hike? Answer in one sentence."},
    ],
)
print(reply.choices[0].message.content)

Run the app through the launcher:

fi-instrument python support.py

The launcher sets up tracing before support.py imports openai. The script still prints the answer even though the trace hides it.

Verify delivery in Tracing

Under Observe in the sidebar, select Tracing and choose the ridgeline-support project. Open the trace from this run. Look for the ChatCompletion span. Check the model, latency and token counts when the provider returns usage. Seeing the span here confirms delivery; a successful model response alone does not.

The ridgeline-support ChatCompletion span shows openai/gpt-4.1-mini, an 806 ms duration, 34 prompt tokens and 27 completion tokens. Both Input and Output read REDACTED.

Choose a startup method

If your deployment…What to do
Lets you change the start commandPrefix the existing command with fi-instrument, as above.
Needs to keep the start commandWith a normal wheel install, run FI_AUTO_INSTRUMENT=true python support.py, or set that variable in the deployment environment. Child Python processes that inherit it also opt in. For an editable install, use the launcher instead.
Already uses opentelemetry-instrumentRun FI_AUTO_INSTRUMENT=true opentelemetry-instrument python support.py to use the provider OpenTelemetry sets up.
Sets its own global OpenTelemetry provider in application codeStart normally, without the launcher or startup variable. Call fi_instrumentation.init() after installing your provider. The agent keeps your sampler, processors and exporters and adds a Future AGI route for AI spans.

If your app already calls register(), don’t start the launcher first: OpenTelemetry accepts only one global provider. Start normally and call fi_instrumentation.init() after register() instead. With the default Future AGI exporter, init() filters the existing export rather than adding a second one. If you rely on custom spans without an AI span kind, they no longer go to Future AGI through that exporter. Don’t instrument the same client twice.

Select integrations

FI_INSTRUMENTATIONS is a comma-separated allowlist of integration names. In the example, openai is the only integration selected. Leave the variable unset to use the installed, enabled-by-default integrations. To exclude one, set FI_DISABLED_INSTRUMENTATIONS to its name; the denylist wins when a name appears in both lists. Restart the app after changing the selection.

To discover missing instrumentor packages for the libraries in this environment, run fi-instrument bootstrap. It lists what to install without changing anything. Use fi-instrument bootstrap --install to install the suggestions. Add --all to include vector databases and web servers. A plain HTTP call does not become a model span just because it reaches a supported provider.

Diagnose a missing span

Run fi-instrument doctor in the app’s environment. It reports the effective settings, integration states and collector check. Use --offline to skip the network check or --all to include libraries that are not installed.

Integration stateWhat it tells you
pendingThe library and instrumentor are available. The hook waits for an import. Doctor runs in a separate process, so this is normal even after the app has sent a span.
instrumentedThe library hook is active in this process. Make a supported call and check the project in Tracing to verify export.
missing_instrumentorThe client can make requests but has no tracing package. For Ridgeline, install traceai-openai in the app’s environment and restart.
manualStartup can’t attach this integration on its own. Follow the setup in the report. For example, mcp-use needs FutureAGICallback() passed to MCPAgent.
disabled, failed or not_installedCheck the selection settings, the reported failure detail or whether the target library is installed, respectively.

To distinguish pending from an import failure, ask the agent for its state after importing the client in a traced Python process:

fi-instrument python -c 'import openai; from fi_instrumentation import auto; print(next(s.status for s in auto.report() if s.name == "openai"))'

Expect instrumented for the example. If nothing arrives, run fi-instrument validate to check the configuration and send an empty export. This checks the collector, not model-span delivery. Verify the project name and both keys, then make a fresh request.

Spans are batched and flushed on normal process exit. In a job that must export before it returns, call auto.flush() in the same process after the request, using from fi_instrumentation import auto. Reserve auto.shutdown() for the final teardown: you cannot restart the agent in that process.

Next steps

Was this page helpful?

Questions & Discussion