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.3.tar.gz (110.1 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.3-py3-none-any.whl (81.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tracenet-0.1.3.tar.gz
  • Upload date:
  • Size: 110.1 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.3.tar.gz
Algorithm Hash digest
SHA256 64e7f1c284990f1b344804be13abbcc9c0828e776d228bd322989d7a2678631e
MD5 64f0681dfeeb8bce1b273f620b1c1ad0
BLAKE2b-256 593295c0eca9b92f96feccc845d9333824452e3aba460d61735ccb6937ec4495

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tracenet-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 81.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cd3d263c31e89e58004ecc43c01fb06470cb04cc17b61b8f27d6b1558a3a83fb
MD5 4d18f7e99c64337c3dbaa108e0a6d543
BLAKE2b-256 f981995b5c6eda255bb83973583e17d36dec0a2d140d750d9ee2219782d06647

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