Send records in, read them back
Ingest endpoints, authentication, the Python SDK, the read API and the settings that control capture and retention.
OpenTelemetry ingest
InsightLense accepts OTLP over HTTP at POST /v1/traces, in the JSON encoding: set the exporter’s protocol to http/json.
An OTLP trace becomes a run and each OTLP span becomes a step. A span that is re-sent with the same span id is ignored, so exporter retries do not duplicate.
Attributes that are read
| Field | Attributes, first match wins |
|---|---|
| Input tokens | gen_ai.usage.input_tokens gen_ai.usage.prompt_tokens llm.usage.prompt_tokens llm.token_count.prompt |
| Output tokens | gen_ai.usage.output_tokens gen_ai.usage.completion_tokens llm.usage.completion_tokens llm.token_count.completion |
| Provider | gen_ai.provider.name gen_ai.system llm.vendor |
| Model | gen_ai.response.model gen_ai.request.model llm.request.model |
| Span type | gen_ai.operation.name llm.request.type traceloop.span.kind, then the OTLP span kind |
| Run / session | gen_ai.conversation.id session.id, then the OTLP trace id |
| Application | resource service.name; environment from deployment.environment.name |
| Business thread | insightlense.correlation_id or correlation_id |
| Actor | insightlense.actor_code (or gen_ai.agent.id), insightlense.actor_kind, insightlense.capability, insightlense.autonomy |
| Subject | insightlense.entity_type, insightlense.entity_ref |
To keep fields beyond these, send the span through the trace API or SDK with metadata_json.
Authentication
Reads always need a signed-in user’s token. Writes from emitters are accepted with any of:
- an ingest key in
X-Lense-Ingest-KeyorAuthorization: Bearer, matched againstLENSE_INGEST_KEYSon the server. Use one key per product so each can be revoked alone; - a platform user token;
- nothing, only while
LENSE_OPEN_INGEST=1. This is on by default outside production and off in production. Every unauthenticated write is counted.
GET /api/traces/ingest-status and the Ingest & retention page show which keys are configured, how many writes were signed, unsigned or refused since start, and which products are reporting.
Python SDK
The insightlense package needs Python 3.9 or later and depends only on requests. Spans are queued and sent in batches to /api/traces/batch.
Callback handlers are available for LangChain, LangGraph and LlamaIndex (get_langchain_handler(), get_langgraph_handler(), get_llamaindex_handler()). log_agent_action() posts a tool call to the agent-actions endpoint and inherits the current span’s trace id.
Record APIs
| Write | Endpoint | Notes |
|---|---|---|
| Spans | POST /api/tracesPOST /api/traces/batch | Required: trace_id, application_name, model_provider, model_name. Optional business fields: correlation_id, actor_code, actor_kind, capability, autonomy, entity_type, entity_ref, prompt_id, prompt_version. |
| Agent actions (authority) | POST /api/security/agent-actions | One tool call: action_type, tool_name, outcome (allowed, refused, escalated, downgraded), autonomy_held, autonomy_required, escalated_to, refusal_reason. |
| Business events | POST /api/business-eventsPOST /api/business-events/batch | Required: event_id, source_system, entity_type, action. Idempotent on event_id: a retry is reported as a duplicate, not stored twice. There is no update or delete route. |
| Scores | POST /api/scoresPOST /api/scores/batch | subject_type (trace, session, business_event, dataset_item), subject_ref, name, value (number, boolean or string), source (human, judge, code, feedback). |
Read API
| Read | Endpoint |
|---|---|
| Runs, with totals and breakdowns | GET /api/traces/runs (filters: application, environment, actor, references, search, status, time range) |
| One span and its tree | GET /api/traces/{trace_id}, GET /api/traces/{trace_id}/tree |
| Guardrails and evaluations for a run set | GET /api/traces/controls |
| Export | GET /api/traces/export?format=json|csv |
| Performance by prompt | GET /api/traces/by-prompt/{prompt_id} |
| One account’s thread | GET /api/business-events/thread/{correlation_id} |
| Agent share and top actions | GET /api/business-events/summary |
| Scores | GET /api/scores, GET /api/scores/summary |
| Cost | GET /api/costs/summary, /breakdown, /forecast, /budgets, /pricing |
| Alerts, incidents, SLA | /api/alerts/rules, /api/alerts/events, /api/incidents, /api/sla/definitions |
| Retention | GET /api/traces/retention, POST /api/traces/retention/purge?dry_run=true |
Responses are wrapped as {"status": ..., "data": ...}. An instance run in a local or development environment serves its OpenAPI description at /docs.
Settings
| Variable | Where | What it does |
|---|---|---|
LENSE_INGEST_KEYS | Server | Comma-separated ingest keys accepted on write paths. |
LENSE_OPEN_INGEST | Server | 1 accepts unsigned writes. Default on outside production, off in production. |
LENSE_TRACE_RETENTION_DAYS | Server | Days a span is kept. Default 365; 0 keeps everything. |
LENSE_INGEST_KEY | Emitter | The key the SDK sends as X-Lense-Ingest-Key. |
LENSE_ENDPOINT | Emitter (Insight agent runtime) | The InsightLense API root. Unset means nothing is sent. |
LENSE_CAPTURE_IO | Emitter (Insight agent runtime) | 1 sends prompt and response text. Default off. |
Guard spans
Products that use the platform guard write a span of type GUARD named guard.<stage> under the step that ran the check. Its metadata holds the stage, the overall action, whether it was enforced, and for each decision the rule, action, reason and the offsets and labels of what matched. The matched text is never stored.
| Variable | What it does |
|---|---|
INSIGHT_GUARD_MODE | observe records what enforcement would have done and changes nothing; enforce applies redactions and blocks. |
INSIGHT_GUARD_POLICY | The guard policy: a path to a JSON file, or inline JSON. |
INSIGHT_GUARD_TRACE | off writes no guard spans. |
INSIGHT_GUARD_TRACE_CLEAN | 0 leaves checks that found nothing off the trace. Default 1. |