Skip to main content

Universal tracing middleware for agent applications with support for multiple tracing backends

Project description

Tracenet

A universal tracing middleware for agent applications with support for multiple tracing backends. This package provides automatic tracing setup - just import it and it works!

Features

  • 🔄 Zero-configuration setup - just import and go!
  • 🤖 Automatic framework detection and integration
    • OpenAI Agents SDK
    • Google ADK
    • CrewAI
    • LangChain
  • 🎯 Manual instrumentation if needed
  • 🔌 Extensible backend system
  • 🚀 Async/sync support

Installation

pip install tracenet

Quick Start

The simplest way to use tracenet is to just import it:

# Just import the package - it automatically sets up tracing
import tracenet

# Your existing code will now be traced automatically!

If you need more control, you can use the manual instrumentation:

from tracenet import trace, start_span, start_generation

# Optional: Use decorators for specific functions
@trace(name="my_function")
def my_function(arg1, arg2):
    return arg1 + arg2

# Optional: Use context managers for manual tracing
with start_span("manual_operation") as span:
    result = perform_operation()
    span.update(output=result)

# Optional: Track LLM generations specifically
with start_generation("text_generation", model="gpt-4") as span:
    response = llm.generate("Hello!")
    span.update(output=response)

Configuration

The package uses environment variables for configuration:

  • Tracenet_TRACER: The tracing backend to use (default: 'langfuse')
  • Tracenet_SERVICE_NAME: Service name for framework integrations (default: 'agent_service')
  • AGENT_NAME: Agent name for automatic tagging of all traces. Can be set programmatically or via environment variable (optional)

For Langfuse backend:

  • LANGFUSE_PUBLIC_KEY
  • LANGFUSE_SECRET_KEY
  • LANGFUSE_HOST (optional)

API Reference

Automatic Tracing

Just import the package and it will automatically:

  • Detect and instrument supported frameworks
  • Set up appropriate tracing backends
  • Configure default settings

Manual Instrumentation (Optional)

Decorators

@trace(name=None, **kwargs)

@trace(name="custom_name", tags=["tag1", "tag2"])
def my_function():
    pass

Context Managers

start_span(context, **kwargs)

with start_span("operation_name", tags=["tag1"]) as span:
    result = operation()
    span.update(output=result)

start_generation(name, model, **kwargs)

with start_generation("text_gen", model="gpt-4") as span:
    response = llm.generate("prompt")
    span.update(output=response)

Agent Name Configuration

set_agent_name(name)

from tracenet import set_agent_name

# Set agent name for all traces (overrides AGENT_NAME environment variable)
set_agent_name('MyAgentName')

Environment Variable (Recommended)

# .env file
AGENT_NAME=MyProductionAgent

All traces will be automatically tagged with the agent name for better organization and filtering.

Utility Functions

flush()

from tracenet import flush

# After operations
flush()

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

tracenet-0.1.2.tar.gz (110.0 kB view details)

Uploaded Source

Built Distribution

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

tracenet-0.1.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file tracenet-0.1.2.tar.gz.

File metadata

  • Download URL: tracenet-0.1.2.tar.gz
  • Upload date:
  • Size: 110.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for tracenet-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7a408dbc053f818e202c05c72026a27b721847832e92d6dcb56c2d09e44d2a0e
MD5 385daf77047e82ee0db570777ad6206f
BLAKE2b-256 c52d00e7aecdc6b89f96905cd49aba38d40093bbb7ac8ce9c135dd7347d1c885

See more details on using hashes here.

File details

Details for the file tracenet-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: tracenet-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for tracenet-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 672b66f43f672e890512941d7aa6f95c2ae3ecbd4445e0edbe4a35e10148c421
MD5 aac745ed9a43c045f134df994499eddc
BLAKE2b-256 f21d30be8c484c244edbb4f2b8c3389f0d822e34d451cec5cc4cb1554a671260

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