Skip to main content

Ghost Doc black-box tracing agent for Python

Project description

ghost-doc-agent (Python)

Python tracing agent for Ghost Doc.

Installation

pip install ghost-doc-agent

Quick start

from ghost_doc_agent import Tracer

tracer = Tracer(agent_id="my-python-app")

@tracer.trace
def get_user(user_id: int) -> dict:
    """Fetches a full user record from the database."""
    return db.query("SELECT * FROM users WHERE id = ?", user_id)

# Async functions work too
@tracer.trace
async def fetch_data(url: str) -> bytes:
    """Downloads raw bytes from the given URL."""
    ...

Start the Ghost Doc Hub before running your application:

npx ghost-doc start
# → Hub + Dashboard at http://localhost:3001

Docstring auto-extraction

The agent automatically uses the first line of a function's docstring as its description in the dashboard tooltip and inspector panel. No extra configuration needed — just write normal Python docstrings.

@tracer.trace
def validate_order(order_id: str) -> bool:
    """Checks stock availability and payment validity for an order.

    Args:
        order_id: The UUID of the order to validate.

    Returns:
        True if the order can be fulfilled.
    """
    ...
# → Dashboard shows: "Checks stock availability and payment validity for an order."

To override the docstring or provide a description when there is none, pass description= explicitly:

@tracer.trace(description="Custom description that overrides the docstring")
def my_function(): ...

Decorator API

# No parentheses — docstring auto-extracted as description
@tracer.trace
def get_user(user_id: int): ...

# Custom label (overrides __qualname__ in the dashboard node name)
@tracer.trace(label="user.lookup")
def get_user(user_id: int): ...

# Explicit description (overrides docstring)
@tracer.trace(description="Fetches a user from the primary database replica")
def get_user(user_id: int): ...

# Label + description
@tracer.trace(label="user.lookup", description="Fetches a user from the primary database replica")
def get_user(user_id: int): ...

# Async functions — identical API
@tracer.trace
async def send_email(to: str, subject: str):
    """Sends a confirmation email via the SMTP relay."""
    ...

Configuration

from ghost_doc_agent import Tracer

tracer = Tracer(
    agent_id="api-service",               # shown in the dashboard as the agent badge
    hub_url="ws://localhost:3001/agent",   # default
    sanitize=frozenset({"password", "token", "secret", "api_key"}),
    buffer_size=500,                       # max spans buffered when Hub is unreachable
    enabled=True,                          # False disables all tracing (decorators become no-ops)
)

Sanitization

Sensitive fields are redacted before leaving your process. The default blocklist covers password, token, secret, authorization, and api_key.

tracer = Tracer(
    agent_id="api",
    sanitize=frozenset({"password", "token", "ssn", "credit_card", "api_key"}),
)

Lifecycle

# Gracefully stop the WebSocket transport
tracer.stop()

Requirements

  • Python 3.10+
  • websockets (installed automatically)

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

ghost_doc_agent-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

ghost_doc_agent-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file ghost_doc_agent-0.1.0.tar.gz.

File metadata

  • Download URL: ghost_doc_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ghost_doc_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 506255bc3669edf2a447f19860259ba0235a4620f9c51bf253fabefac732bbfc
MD5 d31f8bd5ef1e376eb1258f686d74c37f
BLAKE2b-256 ad33be38010af301d1ed68f8f7f74b04462b8775ea881503a3f81f098920cc61

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghost_doc_agent-0.1.0.tar.gz:

Publisher: publish-python.yml on jeffev/ghost-doc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ghost_doc_agent-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ghost_doc_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 591eba7c5ac731e1c3888b6b7c657491058d2d387d067dc26ca75b6a15f2f2da
MD5 67d1d202d0c2a139f3fd66695c590148
BLAKE2b-256 a6654e0773c973630b7f173930fbeb3276641c66989381bbf00d3c3402da6817

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghost_doc_agent-0.1.0-py3-none-any.whl:

Publisher: publish-python.yml on jeffev/ghost-doc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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