Skip to content

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.

  1. 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.

  2. 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.

  3. Install the SDK. Python 3.12 or later:

    Terminal window
    python -m venv .venv && . .venv/bin/activate
    pip install ctxflow-otel==0.2.2
  4. Point the exporter at ctxflow. Replace <your key> with the secret of step 2. The SDK adds /v1/traces to the endpoint. Spaces in the header value are written as %20:

    Terminal window
    export OTEL_SERVICE_NAME=my-agent
    export OTEL_EXPORTER_OTLP_ENDPOINT=https://app.ctxflow.sh
    export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20<your key>"
  5. Check the setup. This sends no data:

    Terminal window
    ctxflow-otel check

    Every line must start with ok:. A line that starts with FAIL: names the problem. The identity line tells you which project and environment the key sends to. See Verify your setup.

  6. Write the agent. Save this as agent.py:

    import ctxflow_otel
    from opentelemetry import trace
    provider = ctxflow_otel.init() # reads OTEL_* and CTXFLOW_* from the environment
    tracer = 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
  7. Run it.

    Terminal window
    python agent.py
  8. 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-1 with turn 0 is under Conversations. Allow up to a minute: see First trace. Run ctxflow-otel check again: its identity line now says when the last event arrived.

  • ctxflow_otel.init() installs an OpenTelemetry TracerProvider with an OTLP/HTTP exporter configured from the standard OTEL_* 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: