Skip to main content

beacon-sdk

Instrumentation SDK for Beacon.

Add tracing to Python agents with minimal changes and inspect traces in Beacon UI.

Quickstart

pip install beacon-sdk[openai]
import beacon_sdk
from openai import OpenAI

beacon_sdk.init()
client = OpenAI()

@beacon_sdk.observe
def run_agent(question: str) -> str:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": question}],
    )
    return response.choices[0].message.content or ""

run_agent("What is the capital of France?")

Start Beacon (make dev) and open http://localhost:5173.

Integrations

Integration Behavior
OpenAI auto-patched chat completions (sync/async + streaming + tool calls)
Anthropic auto-patched messages (sync/async + streaming + tool use)
Google Gemini auto-patched generate_content (sync/async + streaming)
CrewAI auto-patched Crew.kickoff() with callback injection
AutoGen auto-patched ConversableAgent.generate_reply() and GroupChat.run()
LlamaIndex auto-patched BaseQueryEngine.query() and BaseRetriever.retrieve()
Ollama auto-patched chat() and generate() (native client)
LiveKit Agents auto-patched AgentSession voice lifecycle + key session events
Playwright auto-patched page actions
subprocess auto-patched run and check_output
LangChain callback handler (BeaconCallbackHandler)

File operation patching (builtins.open) is opt-in via BEACON_PATCH_FILE_OPS=true.

Install Extras

pip install beacon-sdk
pip install beacon-sdk[openai]
pip install beacon-sdk[anthropic]
pip install beacon-sdk[playwright]
pip install beacon-sdk[livekit]
pip install beacon-sdk[all]

Configuration

Env var Default Meaning
BEACON_BACKEND_URL http://localhost:7474 backend ingestion URL
BEACON_ENABLED true enable/disable tracing
BEACON_AUTO_PATCH true enable/disable auto-patching
BEACON_LOG_LEVEL WARNING SDK logging level
BEACON_PATCH_FILE_OPS false enable file operation patch

init() options:

beacon_sdk.init(
    backend_url="http://localhost:7474",
    auto_patch=True,
    enabled=True,
    exporter="auto",  # auto | async | sync
)

Public API

  • init()
  • observe
  • get_current_span()
  • get_tracer()
  • flush()
  • shutdown()
  • Span, SpanType, SpanStatus, BeaconTracer

OTLP Ingestion (SDK-Free)

Beacon accepts traces in standard OpenTelemetry Protocol (OTLP) JSON format. This lets you send traces from any OTEL-instrumented application without installing the Beacon SDK.

Endpoint: POST /v1/otlp/traces

Example payload:

{
  "resourceSpans": [
    {
      "resource": {
        "attributes": [
          { "key": "service.name", "value": { "stringValue": "my-agent" } }
        ]
      },
      "scopeSpans": [
        {
          "scope": { "name": "my-instrumentation", "version": "1.0.0" },
          "spans": [
            {
              "traceId": "abc123",
              "spanId": "span001",
              "name": "llm_call",
              "kind": 1,
              "startTimeUnixNano": "1700000000000000000",
              "endTimeUnixNano": "1700000001500000000",
              "attributes": [
                { "key": "span_type", "value": { "stringValue": "llm_call" } },
                { "key": "llm.model", "value": { "stringValue": "gpt-4o" } },
                { "key": "llm.tokens.total", "value": { "intValue": "1500" } },
                { "key": "llm.cost_usd", "value": { "doubleValue": 0.023 } }
              ],
              "status": { "code": 1 }
            }
          ]
        }
      ]
    }
  ]
}

curl example:

curl -X POST http://localhost:7474/v1/otlp/traces \
  -H "Content-Type: application/json" \
  -d '{
    "resourceSpans": [{
      "scopeSpans": [{
        "spans": [{
          "traceId": "test-trace-001",
          "spanId": "test-span-001",
          "name": "my-llm-call",
          "startTimeUnixNano": "1700000000000000000",
          "endTimeUnixNano": "1700000001000000000",
          "attributes": [
            {"key": "span_type", "value": {"stringValue": "llm_call"}},
            {"key": "llm.model", "value": {"stringValue": "gpt-4o"}}
          ],
          "status": {"code": 1}
        }]
      }]
    }]
  }'

Response: { "accepted": 1, "rejected": 0 }

Attribute value types: stringValue, intValue, doubleValue, boolValue, arrayValue

Status codes: 0 = Unset, 1 = OK, 2 = Error

Valid span_type values: llm_call, tool_use, agent_step, shell_command, browser_action, custom (default)

Release files for beacon-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for beacon-sdk 0.1.0
File Size Uploaded
beacon_sdk-0.1.0.tar.gz 65.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for beacon-sdk 0.1.0
File Interpreter ABI Platform
beacon_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 103.2 kB

Release files / beacon_sdk-0.1.0.tar.gz

Download URL beacon_sdk-0.1.0.tar.gz
Size 65.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9cd9cd3f6950199a5cc8fe314b5b804281b35137a6b4e974109ed4266fee3e3d
BLAKE2b-256 checksum
How to use checksums
88ee383345e8046daf39497fbfd5cdd373bee98a36bb25acba1e29c598188dd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.

Transparency log

Release files / beacon_sdk-0.1.0-py3-none-any.whl

Download URL beacon_sdk-0.1.0-py3-none-any.whl
Size 38.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b4781f5b4a9d2987a898abb827b99d5504640490202acd9a5ea37f4a847cccf
BLAKE2b-256 checksum
How to use checksums
324084bd78b48014634282b9e3d7f7ead87a3ce92bb90b20ff1ab576a5047806
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page