Quickstart
From zero to a first conversation in the hosted app, https://app.ctxflow.sh. You need Python 3.12 or later. The example agent uses a fake model, so you need no model key. Do the steps in order.
-
Sign in and create a project. Open app.ctxflow.sh, sign in with your email (you receive a sign-in link) or with your Google or GitHub account, and name your organization. Then open Projects and create a project. It starts with three environments: Development, Staging and Production.
-
Create an API key. On the project page, in the section of the Development environment, choose Create key. Copy the secret now: it is shown once. It looks like
ctx_xxxxxxxx_.... The same dialog shows the exporter settings with your key filled in. See API keys. -
Install the SDK. Python 3.12 or later:
Terminal window python -m venv .venv && . .venv/bin/activatepip install ctxflow-otel==0.2.2 -
Point the exporter at ctxflow. Replace
<your key>with the secret of step 2. The SDK adds/v1/tracesto the endpoint. Spaces in the header value are written as%20:Terminal window export OTEL_SERVICE_NAME=my-agentexport OTEL_EXPORTER_OTLP_ENDPOINT=https://app.ctxflow.shexport OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20<your key>" -
Check the setup. This sends no data:
Terminal window ctxflow-otel checkEvery line must start with
ok:. A line that starts withFAIL:names the problem. The identity line tells you which project and environment the key sends to. See Verify your setup. -
Write the agent. Save this as
agent.py:import ctxflow_otelfrom opentelemetry import traceprovider = ctxflow_otel.init() # reads OTEL_* and CTXFLOW_* from the environmenttracer = trace.get_tracer("my-agent")def fake_llm(prompt: str) -> str:with tracer.start_as_current_span("chat fake-model") as span:span.set_attribute("gen_ai.operation.name", "chat")span.set_attribute("gen_ai.request.model", "fake-model")span.set_attribute("gen_ai.prompt", prompt)span.set_attribute("gen_ai.usage.input_tokens", 12)span.set_attribute("gen_ai.usage.output_tokens", 3)return "Hello!"with ctxflow_otel.conversation("conv-1", user_id="u1", turn=0):fake_llm("Hi, who are you?")provider.shutdown() # flush before the process exits -
Run it.
Terminal window python agent.py -
Open the app. Open the Development environment. Its first screen waits for the first trace and opens the data by itself when it arrives. The conversation
conv-1with turn0is under Conversations. Allow up to a minute: see First trace. Runctxflow-otel checkagain: its identity line now says when the last event arrived.
What the example does
Section titled “What the example does”ctxflow_otel.init()installs an OpenTelemetryTracerProviderwith an OTLP/HTTP exporter configured from the standardOTEL_*variables. It is idempotent and returns the provider. See Python SDK.ctxflow_otel.conversation(...)puts the conversation id, the user id and the turn number on every span started inside the block. Without it ctxflow still shows the turn, but cannot group turns by conversation or attribute tool calls to a user. See Identity.- The model span carries
gen_ai.operation.name: that is how ctxflow recognizes a model call and reads its tokens and model. See Agent turns. provider.shutdown()flushes the spans. A short script that exits right away may lose its last spans if you do not call it.
By default the text of the span (here the prompt) is sent and stored for 30 days. See What is sent.
Pick the path that matches your app:
- A LlamaIndex agent, with or without MCP tools: LlamaIndex and MCP.
- Any retrieval code: Instrument a RAG agent: retrieval, tools and the answer, so ctxflow can tell what the agent was given.
- Node.js or PHP: JavaScript, PHP.
- Your ingestion pipeline: Instrument your ingestion: the index and source views and the lineage of each chunk.
- Keep the API key out of your apps: Run a collector.