Skip to main content

Python observability/tracing client for Spect.

Project description

spect-track

Python tracing client for Spect.

Status

spect-track provides the core observer/session lifecycle, trace payload building, HTTP transport, local mode, and typed payload contracts.

Provider-specific wrappers are still in progress. For now, record spans manually around the SDK call you want to trace.

Install

uv add spect-track
# or
pip install spect-track

Usage

import asyncio
import time

from spect_track import ModelSpec, ObserverOptions, SendResult, SessionOptions, create_observer


async def main() -> None:
    started_at = time.time_ns() // 1_000_000
    observer = create_observer(
        ObserverOptions(
            organization_id="your-org-id",
            api_key="your-spect-api-key",
            provider="openai",
        )
    )
    session = observer.start_session(
        SessionOptions(
            model=ModelSpec(model_id="gpt-4.1", provider="openai"),
            name="openai.responses.create",
            start_time=started_at,
        )
    )

    session.start_span(
        name="system",
        kind="system",
        status="ok",
        start_time=started_at,
        messages=[{"role": "system", "content": "You are a helpful assistant."}],
    )
    session.start_span(
        name="user",
        kind="user",
        status="ok",
        start_time=started_at,
        messages=[{"role": "user", "content": [{"type": "text", "text": "Explain tracing."}]}],
    )

    response_started_at = time.time_ns() // 1_000_000
    text = "Tracing records the model call, transcript, tools, timing, and metadata."
    response_ended_at = time.time_ns() // 1_000_000

    session.start_span(
        name="openai.responses.create",
        kind="generate",
        status="ok",
        start_time=response_started_at,
        end_time=response_ended_at,
        model={"modelId": "gpt-4.1", "provider": "openai"},
        messages=[{"role": "assistant", "content": [{"type": "text", "text": text}]}],
    )

    await session.send(
        SendResult(
            text=text,
            response={"model": "gpt-4.1", "finishReasons": ["stop"]},
            start_time=response_started_at,
            duration=max(0, response_ended_at - response_started_at),
            end_time=response_ended_at,
        )
    )


asyncio.run(main())

Message Shape

Record transcript items on spans with messages. Timing belongs on spans, not messages.

  • System messages use content: str.
  • User and assistant messages can use text/content parts.
  • Tool calls/results should include both the span-level tool overlay and canonical message parts.
{"role": "system", "content": "You are a helpful assistant."}
{"role": "user", "content": [{"type": "text", "text": "Hello"}]}
{"role": "assistant", "content": [{"type": "reasoning", "text": "I should search first."}]}
{"role": "assistant", "content": [{"type": "tool-call", "toolCallId": "call_1", "toolName": "search", "input": {"query": "asthma"}}]}
{"role": "tool", "content": [{"type": "tool-result", "toolCallId": "call_1", "toolName": "search", "output": {"type": "json", "value": {"matches": 3}}}]}

Local Mode

payloads = []

observer = create_observer(
    ObserverOptions(
        organization_id="org_123",
        local=True,
        provider="openai",
        on_trace=payloads.append,
    )
)

Development

From the repo root:

cd python
uv sync
uv run --package spect-track ruff check packages/spect-track packages/playground
uv run --package spect-track ty check packages/spect-track
uv run --package spect-track pytest packages/spect-track/tests

Build

cd python
uv build --package spect-track

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spect_track-0.0.1a3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spect_track-0.0.1a3-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file spect_track-0.0.1a3.tar.gz.

File metadata

  • Download URL: spect_track-0.0.1a3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for spect_track-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 5be2ced2699ac57fb872f299c343fc7f8770fadfe81038d3cfd5e665e9ede4dc
MD5 23d5f2ef98341d4988f4f67a9a97059c
BLAKE2b-256 f71045eb04069b0235abe7f077b582e41c0ec4d532346b70b36c27645218b917

See more details on using hashes here.

File details

Details for the file spect_track-0.0.1a3-py3-none-any.whl.

File metadata

  • Download URL: spect_track-0.0.1a3-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for spect_track-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f1f2316620d6d39df1f08810e8329123758c6a0dec42960e4987285eb81f17
MD5 f5aceabc50731a84e6a0fec7e7fe9d97
BLAKE2b-256 80fbc213c990386b4496439903ea35653f037fe6cb93369f4b403066b98863ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page