SDK Troubleshooting
First, understand the failure mode
The TrailAI SDK is built never to crash your application. trail.init() wraps its entire body in a
try/except — a bad URL, missing keys, an unreachable server, or a failed instrumentation are logged
and swallowed. Your app runs on; it just stops sending telemetry.
That makes silence the failure mode. Before anything else, turn on logging:
import logging
logging.basicConfig(level=logging.DEBUG)
import trail
trail.init(...)
You'll see exactly what happened: credentials resolved or missing, tracing set up or not, which instrumentors ran, and any errors. Most problems on this page are diagnosed in one run with this enabled.
No data in the dashboard
Work down this list in order.
1. Did trail.init() actually succeed?
Look for these in your logs:
| Log line | Meaning |
|---|---|
Starting TrailAI initialization... |
init was called |
Missing TrailAI URL: … |
No url argument and no TRAIL_URL |
Missing Public key: … / Missing Secret key: … |
Credentials missing |
Trail tracing setup failed… |
Exporter couldn't be configured |
Error during TrailAI initialization: … |
Something else failed — the message says what |
2. Are the credentials right?
import os
print("URL:", os.environ.get("TRAIL_URL"))
print("PK :", os.environ.get("TRAIL_PUBLIC_KEY", "")[:12], "...")
print("SK set:", bool(os.environ.get("TRAIL_SECRET_KEY")))
- Public key starts with
pk-trail-, secret withsk-trail-. - Both keys must come from the same generated pair.
- The key must not have been revoked.
3. Is the URL right?
✅ https://your-trail-host/api/sdk/v1
✅ https://your-trail-host/api/sdk (trailai ≥ 1.7.0)
❌ https://your-trail-host/api ← nothing works
❌ https://your-trail-host ← nothing works
Why.
4. Was trail.init() called before your provider client?
# ❌ Not traced — the client was built before instrumentation ran
client = OpenAI()
trail.init(...)
# ✅ Traced
trail.init(...)
client = OpenAI()
Watch for module-level clients in imported modules — the import may run before your init() call.
5. Did the process exit before the batch flushed?
Short scripts and serverless functions can end before buffered spans are exported:
trail.init(..., disable_batch=True) # export immediately
6. Are you looking at the right project and window?
The key belongs to exactly one project. Check the project switcher, then widen the time range. See Dashboard Troubleshooting.
7. Can the network reach TrailAI?
curl -X POST https://your-trail-host/api/sdk/v1/prompt/compiled \
-H "X-Public-Key: pk-trail-…" \
-H "X-Secret-Key: sk-trail-…" \
-H "Content-Type: application/json" \
-d '{"name":"any-name","source":"curl"}' -v
401 means the endpoint is reachable and your keys are wrong. A connection error means a firewall,
proxy, or DNS problem. 404 means the URL path is wrong.
Errors
ValueError: make sure trail.init is defined
Raised by get_prompt(), get_secrets(), or guard.*.
Cause: trail.init() wasn't called, or it couldn't find a URL and keys (check the log line
Missing TrailAI URL / Missing Public key / Missing Secret key). On trailai older than 1.7.0
this also happened when credentials came from environment variables only.
Fix: call trail.init() first with TRAIL_URL, TRAIL_PUBLIC_KEY and TRAIL_SECRET_KEY set
(or passed as url=, public_key=, secret_key=). On older versions, upgrade or pass them as
arguments — details.
ValueError: make sure input is defined
Raised by guard.output().
Cause: output() links to the preceding input() call, and there wasn't one.
Fix: call guard.input() first in the same request (thread or async task), or pass
guard.output(text, guard_prompt_id=...) explicitly — guide.
TypeError: @trace can only be applied to callables
You decorated something that isn't a function. Check decorator ordering if you're stacking several.
RuntimeError: Missing TrailAI URL/Public key/Secret key
Only surfaces with debug logging on (init swallows it). Set the missing value.
ValueError: API key required via 'api_key' parameter or 'OPENAI_API_KEY' environment variable
Partial data
| Symptom | Cause | Fix |
|---|---|---|
| LLM spans appear, your functions don't | You haven't added manual spans | Manual Tracing |
| Your functions appear, LLM calls don't | The library isn't auto-instrumented, or the client predates init() |
Auto-Instrumentation |
| Agent analytics empty, traces present | Spans lack agent roles | Add role="agent" / "agent step" / "tool" |
Cost is 0 |
Model missing from the pricing table | Custom pricing |
| No prompts/completions on spans | Content capture is off | Check capture_message_content and OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT |
| One library never traced | Not installed, disabled, or unsupported | Check pip show, disabled_instrumentors, and the support table |
Everything grouped as default |
application_name / environment unset |
Set them in init() |
Instrumentation problems
An instrumentor fails to load
Failed to instrument <name>: <error>
Usually a version mismatch between the library and the instrumentor. Options:
- Try a different version of the library.
- Disable that instrumentor and trace manually:
trail.init(..., disabled_instrumentors=["problematic-library"]) - Report it with the library version and the error.
Duplicate spans
You're tracing the same operation twice — usually an auto-instrumented call that you've also wrapped
in @trail.trace. Remove your wrapper, or disable that instrumentor.
Library for X (Y) not found. Skipping instrumentation
Informational, not an error. The library isn't installed and TrailAI skipped it. Expected for anything you don't use.
Performance
| Symptom | Cause | Fix |
|---|---|---|
| Noticeable latency per request | disable_batch=True under load |
Use batching in production |
| Memory growth | Spans buffering faster than they export | Check network to TrailAI; reduce span volume |
| High span volume | Tracing something very high-frequency | Disable that instrumentor, or remove fine-grained @trace decorators |
| Slow startup | Pricing table fetched at init | Supply a local pricing_json file |
| Guardrails add ~1 s per request | LLM-based detection on input and output | Use regex for the fast path, or a smaller judge model — guide |
Environment issues
| Symptom | Cause | Fix |
|---|---|---|
ModuleNotFoundError: No module named 'trail' |
Package not installed, or wrong environment | pip install trailai in the active venv |
| Installed but import fails | You installed trail, not trailai |
pip uninstall trail && pip install trailai |
| Dependency conflicts on install | OpenTelemetry version clash with another library | Use a clean virtualenv; align OTel versions |
| Works locally, not in Docker | Env vars not passed into the container | Check your compose/K8s env configuration |
| Works locally, not in production | Egress blocked by a firewall or proxy | Allow-list the TrailAI host; configure proxy env vars |
Diagnostic script
Run this to check an installation end to end:
import os, logging
logging.basicConfig(level=logging.DEBUG)
print("=== Environment ===")
for k in ("TRAIL_URL", "TRAIL_PUBLIC_KEY", "TRAIL_SECRET_KEY"):
v = os.environ.get(k)
print(f"{k}: {'set' if v else 'MISSING'}", f"({v[:16]}…)" if v and k != "TRAIL_SECRET_KEY" else "")
print("\n=== Import ===")
import trail
print("trail imported OK")
print("\n=== Init ===")
trail.init(
application_name="diagnostic",
environment="test",
url=os.environ.get("TRAIL_URL"),
public_key=os.environ.get("TRAIL_PUBLIC_KEY"),
secret_key=os.environ.get("TRAIL_SECRET_KEY"),
disable_batch=True,
)
print("\n=== Manual span ===")
@trail.trace(role="tool")
def diagnostic_span():
return "ok"
print(diagnostic_span())
print("\n=== Prompt endpoint reachability ===")
try:
trail.get_prompt(name="__nonexistent__")
print("Endpoint reachable (a missing prompt is expected here)")
except ValueError as e:
print("Credentials not passed as init arguments:", e)
print("\nCheck Observations → Tracing for a 'diagnostic_span' trace.")
A diagnostic_span trace in the dashboard means the whole chain works.
Getting help
Include:
- SDK version —
pip show trailai - Python version —
python --version - Your
trail.init()call, with credentials redacted - Debug logs from startup through the failing operation
- What you expected vs. what happened
- A minimal reproduction, if you can produce one
Never include real API keys, secret values, or user content.
Related
- Configuration — every option and its gotchas
- Dashboard Troubleshooting — when the data arrives but the UI doesn't show it
- REST API — for testing endpoints directly with curl