AnoSys Logger for OpenAI Agents - Python
Automatically capture and send OpenAI API calls (and more) to AnoSys for monitoring, analytics, and observability.
Features
- ✨ Automatic Instrumentation: Automatically captures traces from OpenAI API calls via OpenTelemetry.
- ✨ Manual Instrumentation: Easy-to-use decorator
@anosys_loggerfor logging any function (sync or async). - ✨ Raw Logging: Send custom JSON data directly to AnoSys for unstructured events.
- ✨ Async & Streaming Support: Fully supports Python's
asyncioand streaming response aggregation. - ✨ OpenTelemetry Standards: Follows LLM / Gen AI semantic conventions.
Installation
Install the package via pip:
pip install anosys-logger-4-openai-agents
Configuration
You need an AnoSys API Key to send data. Set it as an environment variable:
export ANOSYS_API_KEY="your_anosys_api_key"
Or create a .env file in your project root:
ANOSYS_API_KEY=your_anosys_api_key
Usage
1. Automatic Tracing (with OpenAI Agents)
To automatically capture traces from OpenAI agents, register the AnosysOpenAIAgentsLogger as a trace processor. This requires the traceai-openai-agents package.
import os
import contextvars
from agents import add_trace_processor
from AnosysLoggers import AnosysOpenAIAgentsLogger
# 1. Set API Keys
os.environ["OPENAI_API_KEY"] = "your_openai_key"
os.environ['ANOSYS_API_KEY'] = "your_anosys_key"
# 2. (Optional) Setup User Context
current_user_context = contextvars.ContextVar("current_user_context")
current_user_context.set({"session_id": "session_123", "user_id": "user_456"})
# 3. Register the Logger
add_trace_processor(AnosysOpenAIAgentsLogger(get_user_context=current_user_context.get))
# Now, any agent execution will be automatically logged to AnoSys.
2. Manual Logging (Decorator)
Use the @anosys_logger decorator to log inputs, outputs, and execution details of any function.
Synchronous Example
from AnosysLoggers import anosys_logger
@anosys_logger(source="my_sync_function")
def calculate_sum(a, b):
return a + b
# Calling the function will automatically log data to AnoSys
result = calculate_sum(5, 10)
Asynchronous Example
import asyncio
from AnosysLoggers import anosys_logger
@anosys_logger(source="my_async_function")
async def fetch_data(url):
await asyncio.sleep(1) # Simulate network delay
return {"data": "sample", "url": url}
# Run the async function
asyncio.run(fetch_data("https://example.com"))
Streaming (Async Generator) Example
@anosys_logger(source="my_streaming_function")
async def stream_data():
yield "part1"
yield "part2"
# The logger will capture and aggregate the streamed output
async for chunk in stream_data():
print(chunk)
3. Raw Logging
If you need to log unstructured data or custom events, use anosys_raw_logger.
from AnosysLoggers import anosys_raw_logger
data = {
"event": "user_signup",
"user_id": "12345",
"status": "success"
}
anosys_raw_logger(data)
What Data is Captured?
OpenTelemetry Semantic Conventions
Following the Gen AI standards:
gen_ai.system: "openai"gen_ai.request.model: Model requested (e.g., "gpt-4")gen_ai.usage.input_tokens: Prompt token countgen_ai.usage.output_tokens: Completion token countgen_ai.response.finish_reasons: Why the generation stopped
Additional Metadata
- Request/response messages (optional)
- Execution duration and timestamps
- Error types and full stack traces
- Custom source identifiers
Advanced Usage
Custom API URL or Proxy
If you need to point to a specific AnoSys instance:
from AnosysLoggers import setup_api
setup_api(path="https://custom.anosys.endpoint/api/log")
Troubleshooting
- Missing API Key: Ensure
ANOSYS_API_KEYis set in your environment. - Import Error: Ensure you installed
anosys-logger-4-openai-agents. - Async Errors: Ensure you are
await-ing async functions decorated with@anosys_logger.
License
MIT License. See LICENSE for details.
Release files for anosys-logger-4-openai-agents 0.0.74
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| anosys_logger_4_openai_agents-0.0.74.tar.gz | 29.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| anosys_logger_4_openai_agents-0.0.74-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.9 kB
Release files / anosys_logger_4_openai_agents-0.0.74.tar.gz
| Download URL | anosys_logger_4_openai_agents-0.0.74.tar.gz |
|---|---|
| Size | 29.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42998d44fe5ab580a4a35a21cd619140710dcabc73df8a86c8b81b265ba5f03d
|
|
BLAKE2b-256 checksum How to use checksums |
d98bd581adac71a04c3944453bf58d0e52d101b69e0fc44efabce37d3cb7b7a1
|
| 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 Apr 4, 2026.
Transparency logRelease files / anosys_logger_4_openai_agents-0.0.74-py3-none-any.whl
| Download URL | anosys_logger_4_openai_agents-0.0.74-py3-none-any.whl |
|---|---|
| Size | 28.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b2097e4e1707b8decfdd52b8aca9420710b687eb37c3195bd6249973fbc1247
|
|
BLAKE2b-256 checksum How to use checksums |
6637c6dea566f69a2e46bc104d2a16484d252298f5270790ecbb80cb827e8324
|
| 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 Apr 4, 2026.
Transparency log