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.4.tar.gz (113.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.4-py3-none-any.whl (84.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tracenet-0.1.4.tar.gz
  • Upload date:
  • Size: 113.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.4.tar.gz
Algorithm Hash digest
SHA256 7b413004407db9497b8ccc9b3d59ddf94bd3d8fa5090537a45198d96106e0a04
MD5 335d75a74b1265f24c5bb7ba07bc26c6
BLAKE2b-256 df89e4819e806be2c9989ba6c947cf6ca00ac2d2cf6d8c787f49e27069cbc2f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tracenet-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 84.6 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 17c53a7b8629fa0ccab9030773141e212e61a3924d9facfa8eb6000665fc358e
MD5 47c37a676423982b80497aac1b854730
BLAKE2b-256 b70fbd7e2a86d6f5ef3e1618efc348e005cc44f01a23ae63beb6fb2aedc05225

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