traccia 0.1.2__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. {traccia-0.1.2 → traccia-0.1.6}/PKG-INFO +72 -15
  2. {traccia-0.1.2 → traccia-0.1.6}/README.md +69 -14
  3. traccia-0.1.6/__init__.py +73 -0
  4. traccia-0.1.6/auto.py +748 -0
  5. traccia-0.1.6/auto_instrumentation.py +74 -0
  6. traccia-0.1.6/cli.py +349 -0
  7. traccia-0.1.6/config.py +699 -0
  8. traccia-0.1.6/context/__init__.py +33 -0
  9. traccia-0.1.6/context/context.py +67 -0
  10. traccia-0.1.6/context/propagators.py +283 -0
  11. traccia-0.1.6/errors.py +48 -0
  12. traccia-0.1.6/exporter/__init__.py +8 -0
  13. traccia-0.1.6/exporter/console_exporter.py +31 -0
  14. traccia-0.1.6/exporter/file_exporter.py +178 -0
  15. traccia-0.1.6/exporter/http_exporter.py +214 -0
  16. traccia-0.1.6/exporter/otlp_exporter.py +190 -0
  17. traccia-0.1.6/instrumentation/__init__.py +26 -0
  18. traccia-0.1.6/instrumentation/anthropic.py +92 -0
  19. traccia-0.1.6/instrumentation/decorator.py +263 -0
  20. traccia-0.1.6/instrumentation/fastapi.py +38 -0
  21. traccia-0.1.6/instrumentation/http_client.py +21 -0
  22. traccia-0.1.6/instrumentation/http_server.py +25 -0
  23. traccia-0.1.6/instrumentation/openai.py +358 -0
  24. traccia-0.1.6/instrumentation/requests.py +68 -0
  25. traccia-0.1.6/integrations/__init__.py +39 -0
  26. traccia-0.1.6/integrations/langchain/__init__.py +14 -0
  27. traccia-0.1.6/integrations/langchain/callback.py +418 -0
  28. traccia-0.1.6/integrations/langchain/utils.py +129 -0
  29. traccia-0.1.6/integrations/openai_agents/__init__.py +73 -0
  30. traccia-0.1.6/integrations/openai_agents/processor.py +262 -0
  31. traccia-0.1.6/pricing_config.py +58 -0
  32. traccia-0.1.6/processors/__init__.py +35 -0
  33. traccia-0.1.6/processors/agent_enricher.py +159 -0
  34. traccia-0.1.6/processors/batch_processor.py +140 -0
  35. traccia-0.1.6/processors/cost_engine.py +71 -0
  36. traccia-0.1.6/processors/cost_processor.py +70 -0
  37. traccia-0.1.6/processors/drop_policy.py +44 -0
  38. traccia-0.1.6/processors/logging_processor.py +31 -0
  39. traccia-0.1.6/processors/rate_limiter.py +223 -0
  40. traccia-0.1.6/processors/sampler.py +22 -0
  41. traccia-0.1.6/processors/token_counter.py +216 -0
  42. {traccia-0.1.2 → traccia-0.1.6}/pyproject.toml +18 -4
  43. traccia-0.1.6/runtime_config.py +127 -0
  44. {traccia-0.1.2 → traccia-0.1.6}/tests/test_basic_e2e.py +0 -6
  45. {traccia-0.1.2 → traccia-0.1.6}/tests/test_comprehensive_e2e.py +24 -10
  46. {traccia-0.1.2 → traccia-0.1.6}/traccia.egg-info/PKG-INFO +72 -15
  47. traccia-0.1.6/traccia.egg-info/SOURCES.txt +113 -0
  48. {traccia-0.1.2 → traccia-0.1.6}/traccia.egg-info/requires.txt +3 -0
  49. traccia-0.1.6/traccia.egg-info/top_level.txt +1 -0
  50. traccia-0.1.6/tracer/__init__.py +15 -0
  51. traccia-0.1.6/tracer/otel_adapter.py +577 -0
  52. traccia-0.1.6/tracer/otel_utils.py +24 -0
  53. traccia-0.1.6/tracer/provider.py +155 -0
  54. traccia-0.1.6/tracer/span.py +286 -0
  55. traccia-0.1.6/tracer/span_context.py +16 -0
  56. traccia-0.1.6/tracer/tracer.py +243 -0
  57. traccia-0.1.6/utils/__init__.py +19 -0
  58. traccia-0.1.6/utils/helpers.py +95 -0
  59. traccia-0.1.2/traccia.egg-info/SOURCES.txt +0 -15
  60. traccia-0.1.2/traccia.egg-info/top_level.txt +0 -1
  61. {traccia-0.1.2 → traccia-0.1.6}/LICENSE +0 -0
  62. {traccia-0.1.2 → traccia-0.1.6}/setup.cfg +0 -0
  63. {traccia-0.1.2 → traccia-0.1.6}/tests/test_auto_start.py +0 -0
  64. {traccia-0.1.2 → traccia-0.1.6}/tests/test_backward_compat.py +0 -0
  65. {traccia-0.1.2 → traccia-0.1.6}/tests/test_config_file.py +0 -0
  66. {traccia-0.1.2 → traccia-0.1.6}/tests/test_core_functionality.py +0 -0
  67. {traccia-0.1.2 → traccia-0.1.6}/traccia.egg-info/dependency_links.txt +0 -0
  68. {traccia-0.1.2 → traccia-0.1.6}/traccia.egg-info/entry_points.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: traccia
3
- Version: 0.1.2
3
+ Version: 0.1.6
4
4
  Summary: Production-ready distributed tracing SDK for AI agents and LLM applications
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://github.com/traccia-ai/traccia
@@ -32,6 +32,8 @@ Requires-Dist: opentelemetry-semantic-conventions>=0.40b0
32
32
  Requires-Dist: tomli>=2.0.0; python_version < "3.11"
33
33
  Requires-Dist: toml>=0.10.0
34
34
  Requires-Dist: pydantic>=2.0.0
35
+ Provides-Extra: langchain
36
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
35
37
  Dynamic: license-file
36
38
 
37
39
  # Traccia
@@ -43,6 +45,7 @@ Traccia is a lightweight, high-performance Python SDK for observability and trac
43
45
  ## ✨ Features
44
46
 
45
47
  - **🔍 Automatic Instrumentation**: Auto-patch OpenAI, Anthropic, requests, and HTTP libraries
48
+ - **🤖 Framework Integrations**: Support for LangChain and OpenAI Agents SDK
46
49
  - **📊 LLM-Aware Tracing**: Track tokens, costs, prompts, and completions automatically
47
50
  - **⚡ Zero-Config Start**: Simple `init()` call with automatic config discovery
48
51
  - **🎯 Decorator-Based**: Trace any function with `@observe` decorator
@@ -101,6 +104,59 @@ def generate_text(prompt: str) -> str:
101
104
  text = generate_text("Write a haiku about Python")
102
105
  ```
103
106
 
107
+ ### LangChain
108
+
109
+ Create a callback handler and pass it to `config={"callbacks": [traccia_handler]}`. Install the optional extra: `pip install traccia[langchain]`.
110
+
111
+ ```python
112
+ from traccia import init
113
+ from traccia.integrations.langchain import CallbackHandler # or TracciaCallbackHandler
114
+ from langchain_openai import ChatOpenAI
115
+
116
+ init()
117
+
118
+ # Create Traccia handler (no args)
119
+ traccia_handler = CallbackHandler()
120
+
121
+ # Use with any LangChain runnable
122
+ llm = ChatOpenAI(model="gpt-4o-mini")
123
+ result = llm.invoke(
124
+ "Tell me a joke",
125
+ config={"callbacks": [traccia_handler]}
126
+ )
127
+ ```
128
+
129
+ Spans for LLM/chat model runs are created automatically with the same attributes as direct OpenAI instrumentation (model, prompt, usage, cost).
130
+
131
+ **Note:** `pip install traccia[langchain]` installs traccia plus `langchain-core`; you need this extra to use the callback handler. If you already have `langchain-core` (e.g. from `langchain` or `langchain-openai`), base `pip install traccia` may be enough at runtime, but `traccia[langchain]` is the supported way to get a compatible dependency.
132
+
133
+ ### OpenAI Agents SDK
134
+
135
+ Traccia **automatically** detects and instruments the OpenAI Agents SDK when installed. No extra code needed:
136
+
137
+ ```python
138
+ from traccia import init
139
+ from agents import Agent, Runner
140
+
141
+ init() # Automatically enables Agents SDK tracing
142
+
143
+ agent = Agent(
144
+ name="Assistant",
145
+ instructions="You are a helpful assistant"
146
+ )
147
+ result = Runner.run_sync(agent, "Write a haiku about recursion")
148
+ ```
149
+
150
+ **Configuration**: Auto-enabled by default when `openai-agents` is installed. To disable:
151
+
152
+ ```python
153
+ init(openai_agents=False) # Explicit parameter
154
+ # OR set environment variable: TRACCIA_OPENAI_AGENTS=false
155
+ # OR in traccia.toml under [instrumentation]: openai_agents = false
156
+ ```
157
+
158
+ **Compatibility**: If you have `openai-agents` installed but don't use it (e.g., using LangChain or pure OpenAI instead), the integration is registered but never invoked—no overhead or extra spans.
159
+
104
160
  ---
105
161
 
106
162
  ## 📖 Configuration
@@ -141,6 +197,7 @@ reset_trace_file = false # Reset file on initialization
141
197
  enable_patching = true # Auto-patch libraries (OpenAI, Anthropic, requests)
142
198
  enable_token_counting = true # Count tokens for LLM calls
143
199
  enable_costs = true # Calculate costs
200
+ openai_agents = true # Auto-enable OpenAI Agents SDK integration
144
201
  auto_instrument_tools = false # Auto-instrument tool calls (experimental)
145
202
  max_tool_spans = 100 # Max tool spans to create
146
203
  max_span_depth = 10 # Max nested span depth
@@ -470,18 +527,6 @@ init(debug=True)
470
527
  - Increase `max_queue_size` if spans are queued
471
528
  - Check `traccia doctor` output
472
529
 
473
- #### **Import errors after upgrade**
474
-
475
- If you're migrating from `traccia_sdk`:
476
-
477
- ```python
478
- # OLD (will raise helpful error)
479
- from traccia_sdk import init # ❌ ImportError with migration guide
480
-
481
- # NEW
482
- from traccia import init # ✅ Correct
483
- ```
484
-
485
530
  ---
486
531
 
487
532
  ## 📚 API Reference
@@ -537,13 +582,14 @@ Create a span context manager.
537
582
 
538
583
  ### Decorator
539
584
 
540
- #### `@observe(name=None, *, attributes=None, as_type="span", skip_args=None, skip_result=False)`
585
+ #### `@observe(name=None, *, attributes=None, tags=None, as_type="span", skip_args=None, skip_result=False)`
541
586
 
542
587
  Decorate a function to create spans automatically.
543
588
 
544
589
  **Parameters**:
545
590
  - `name` (str, optional): Span name (default: function name)
546
591
  - `attributes` (dict, optional): Initial attributes
592
+ - `tags` (list[str], optional): User-defined identifiers for the observed method
547
593
  - `as_type` (str): Span type (`"span"`, `"llm"`, `"tool"`)
548
594
  - `skip_args` (list, optional): Arguments to skip capturing
549
595
  - `skip_result` (bool): Skip capturing return value
@@ -590,6 +636,17 @@ Application Code (@observe)
590
636
  Backend (Grafana Tempo / Jaeger / Zipkin / etc.)
591
637
  ```
592
638
 
639
+ ### Instrumentation vs Integrations
640
+
641
+ - **`traccia.instrumentation.*`**: Infrastructure and vendor instrumentation.
642
+ - HTTP client/server helpers (including FastAPI middleware).
643
+ - Vendor SDK hooks and monkey patching (e.g., OpenAI, Anthropic, `requests`).
644
+ - Decorators and utilities used for auto-instrumenting arbitrary functions.
645
+
646
+ - **`traccia.integrations.*`**: AI/agent framework integrations.
647
+ - Adapters that plug into higher-level frameworks via their official extension points (e.g., LangChain callbacks).
648
+ - Work at the level of chains, tools, agents, and workflows rather than raw HTTP or SDK calls.
649
+
593
650
  ---
594
651
 
595
652
  ## 🤝 Contributing
@@ -649,7 +706,7 @@ pytest traccia/tests/ --cov=traccia --cov-report=html
649
706
 
650
707
  ## 📄 License
651
708
 
652
- MIT License - see [LICENSE](LICENSE) for details
709
+ Apache License 2.0 - see [LICENSE](LICENSE) for full terms and conditions.
653
710
 
654
711
  ---
655
712
 
@@ -7,6 +7,7 @@ Traccia is a lightweight, high-performance Python SDK for observability and trac
7
7
  ## ✨ Features
8
8
 
9
9
  - **🔍 Automatic Instrumentation**: Auto-patch OpenAI, Anthropic, requests, and HTTP libraries
10
+ - **🤖 Framework Integrations**: Support for LangChain and OpenAI Agents SDK
10
11
  - **📊 LLM-Aware Tracing**: Track tokens, costs, prompts, and completions automatically
11
12
  - **⚡ Zero-Config Start**: Simple `init()` call with automatic config discovery
12
13
  - **🎯 Decorator-Based**: Trace any function with `@observe` decorator
@@ -65,6 +66,59 @@ def generate_text(prompt: str) -> str:
65
66
  text = generate_text("Write a haiku about Python")
66
67
  ```
67
68
 
69
+ ### LangChain
70
+
71
+ Create a callback handler and pass it to `config={"callbacks": [traccia_handler]}`. Install the optional extra: `pip install traccia[langchain]`.
72
+
73
+ ```python
74
+ from traccia import init
75
+ from traccia.integrations.langchain import CallbackHandler # or TracciaCallbackHandler
76
+ from langchain_openai import ChatOpenAI
77
+
78
+ init()
79
+
80
+ # Create Traccia handler (no args)
81
+ traccia_handler = CallbackHandler()
82
+
83
+ # Use with any LangChain runnable
84
+ llm = ChatOpenAI(model="gpt-4o-mini")
85
+ result = llm.invoke(
86
+ "Tell me a joke",
87
+ config={"callbacks": [traccia_handler]}
88
+ )
89
+ ```
90
+
91
+ Spans for LLM/chat model runs are created automatically with the same attributes as direct OpenAI instrumentation (model, prompt, usage, cost).
92
+
93
+ **Note:** `pip install traccia[langchain]` installs traccia plus `langchain-core`; you need this extra to use the callback handler. If you already have `langchain-core` (e.g. from `langchain` or `langchain-openai`), base `pip install traccia` may be enough at runtime, but `traccia[langchain]` is the supported way to get a compatible dependency.
94
+
95
+ ### OpenAI Agents SDK
96
+
97
+ Traccia **automatically** detects and instruments the OpenAI Agents SDK when installed. No extra code needed:
98
+
99
+ ```python
100
+ from traccia import init
101
+ from agents import Agent, Runner
102
+
103
+ init() # Automatically enables Agents SDK tracing
104
+
105
+ agent = Agent(
106
+ name="Assistant",
107
+ instructions="You are a helpful assistant"
108
+ )
109
+ result = Runner.run_sync(agent, "Write a haiku about recursion")
110
+ ```
111
+
112
+ **Configuration**: Auto-enabled by default when `openai-agents` is installed. To disable:
113
+
114
+ ```python
115
+ init(openai_agents=False) # Explicit parameter
116
+ # OR set environment variable: TRACCIA_OPENAI_AGENTS=false
117
+ # OR in traccia.toml under [instrumentation]: openai_agents = false
118
+ ```
119
+
120
+ **Compatibility**: If you have `openai-agents` installed but don't use it (e.g., using LangChain or pure OpenAI instead), the integration is registered but never invoked—no overhead or extra spans.
121
+
68
122
  ---
69
123
 
70
124
  ## 📖 Configuration
@@ -105,6 +159,7 @@ reset_trace_file = false # Reset file on initialization
105
159
  enable_patching = true # Auto-patch libraries (OpenAI, Anthropic, requests)
106
160
  enable_token_counting = true # Count tokens for LLM calls
107
161
  enable_costs = true # Calculate costs
162
+ openai_agents = true # Auto-enable OpenAI Agents SDK integration
108
163
  auto_instrument_tools = false # Auto-instrument tool calls (experimental)
109
164
  max_tool_spans = 100 # Max tool spans to create
110
165
  max_span_depth = 10 # Max nested span depth
@@ -434,18 +489,6 @@ init(debug=True)
434
489
  - Increase `max_queue_size` if spans are queued
435
490
  - Check `traccia doctor` output
436
491
 
437
- #### **Import errors after upgrade**
438
-
439
- If you're migrating from `traccia_sdk`:
440
-
441
- ```python
442
- # OLD (will raise helpful error)
443
- from traccia_sdk import init # ❌ ImportError with migration guide
444
-
445
- # NEW
446
- from traccia import init # ✅ Correct
447
- ```
448
-
449
492
  ---
450
493
 
451
494
  ## 📚 API Reference
@@ -501,13 +544,14 @@ Create a span context manager.
501
544
 
502
545
  ### Decorator
503
546
 
504
- #### `@observe(name=None, *, attributes=None, as_type="span", skip_args=None, skip_result=False)`
547
+ #### `@observe(name=None, *, attributes=None, tags=None, as_type="span", skip_args=None, skip_result=False)`
505
548
 
506
549
  Decorate a function to create spans automatically.
507
550
 
508
551
  **Parameters**:
509
552
  - `name` (str, optional): Span name (default: function name)
510
553
  - `attributes` (dict, optional): Initial attributes
554
+ - `tags` (list[str], optional): User-defined identifiers for the observed method
511
555
  - `as_type` (str): Span type (`"span"`, `"llm"`, `"tool"`)
512
556
  - `skip_args` (list, optional): Arguments to skip capturing
513
557
  - `skip_result` (bool): Skip capturing return value
@@ -554,6 +598,17 @@ Application Code (@observe)
554
598
  Backend (Grafana Tempo / Jaeger / Zipkin / etc.)
555
599
  ```
556
600
 
601
+ ### Instrumentation vs Integrations
602
+
603
+ - **`traccia.instrumentation.*`**: Infrastructure and vendor instrumentation.
604
+ - HTTP client/server helpers (including FastAPI middleware).
605
+ - Vendor SDK hooks and monkey patching (e.g., OpenAI, Anthropic, `requests`).
606
+ - Decorators and utilities used for auto-instrumenting arbitrary functions.
607
+
608
+ - **`traccia.integrations.*`**: AI/agent framework integrations.
609
+ - Adapters that plug into higher-level frameworks via their official extension points (e.g., LangChain callbacks).
610
+ - Work at the level of chains, tools, agents, and workflows rather than raw HTTP or SDK calls.
611
+
557
612
  ---
558
613
 
559
614
  ## 🤝 Contributing
@@ -613,7 +668,7 @@ pytest traccia/tests/ --cov=traccia --cov-report=html
613
668
 
614
669
  ## 📄 License
615
670
 
616
- MIT License - see [LICENSE](LICENSE) for details
671
+ Apache License 2.0 - see [LICENSE](LICENSE) for full terms and conditions.
617
672
 
618
673
  ---
619
674
 
@@ -0,0 +1,73 @@
1
+ """Python SDK entrypoint for the agent tracing library."""
2
+
3
+ from traccia.auto import start_tracing, stop_tracing, init, trace, end_auto_trace
4
+ from traccia.tracer import TracerProvider
5
+ from traccia.instrumentation.decorator import observe
6
+
7
+ # Version exposure
8
+ try:
9
+ from importlib.metadata import version, PackageNotFoundError
10
+ try:
11
+ __version__ = version("traccia")
12
+ except PackageNotFoundError:
13
+ __version__ = "0.1.0" # Fallback version
14
+ except ImportError:
15
+ __version__ = "0.1.0" # Fallback for Python < 3.8
16
+
17
+ # Initialize global tracer provider (now uses OpenTelemetry directly)
18
+ _global_tracer_provider = TracerProvider()
19
+
20
+
21
+ def get_tracer(name: str = "default"):
22
+ """Fetch a tracer from the global provider."""
23
+ return _global_tracer_provider.get_tracer(name)
24
+
25
+
26
+ def span(name: str, attributes: dict = None):
27
+ """
28
+ Convenience function to create a span using the default tracer.
29
+
30
+ This is a simpler alternative to:
31
+ tracer = get_tracer("name")
32
+ with tracer.start_as_current_span("span_name") as span:
33
+
34
+ Usage:
35
+ from traccia import span
36
+
37
+ with span("my_operation"):
38
+ # Your code here
39
+ pass
40
+
41
+ # With attributes
42
+ with span("my_operation", {"key": "value"}) as s:
43
+ s.set_attribute("another", "attr")
44
+ # Your code here
45
+ """
46
+ tracer = get_tracer()
47
+ return tracer.start_as_current_span(name, attributes=attributes)
48
+
49
+
50
+ def set_tracer_provider(provider: TracerProvider) -> None:
51
+ """Override the global tracer provider (primarily for tests or customization)."""
52
+ global _global_tracer_provider
53
+ _global_tracer_provider = provider
54
+
55
+
56
+ def get_tracer_provider() -> TracerProvider:
57
+ return _global_tracer_provider
58
+
59
+
60
+ __all__ = [
61
+ "__version__",
62
+ "get_tracer",
63
+ "get_tracer_provider",
64
+ "set_tracer_provider",
65
+ "start_tracing",
66
+ "stop_tracing",
67
+ "init",
68
+ "trace",
69
+ "end_auto_trace",
70
+ "span",
71
+ "observe",
72
+ ]
73
+