Skip to content

Commit ddf1963

Browse files
committed
docs: comprehensive documentation improvements based on user feedback
Addresses all 18 feedback items systematically: **Strands Integration (3 fixes):** - Remove incorrect set_tracer_provider() requirement - auto-handled by SDK - Move example code link to top for better UX - Add integration/user code distinction with comment separators **Tutorial Fixes (11 improvements):** - Tutorial 01: Fix docstring newline issues (section 1.7) - Tutorial 02: Add tracer→instrumentor initialization order callout - Tutorial 02: Add non-instrumentor pattern section (@trace decorator) - Tutorial 03: Fix docstring newlines (section 3.12) - Tutorial 03: Remove redundant sections 3.8 & 3.9 (timing/error enrichment) - Tutorial 03: Add comprehensive enrich_session() vs enrich_span() guide - Tutorial 03: Add global vs instance method callout for enrich_span() - Tutorial 05: Fix dashboard URL to https://app.honeyhive.ai/evaluate - Tutorial 05: Fix docstring newlines (section 5.9) - Tutorial 05: Document tracer parameter for evaluation functions - Tutorial 06: Add middleware alternative (without context.attach()) **Advanced Documentation (2 additions):** - Advanced Tracing: Add session vs span enrichment with decision matrix - Delete 2,088-line advanced-setup.rst (redundant with existing docs) **Documentation Maintenance:** - Fix 6 broken cross-references to deleted advanced-setup file - Update all references to point to advanced-configuration instead **Key Improvements:** ✅ Correctness: Removed incorrect patterns, fixed URLs ✅ Clarity: Added explicit initialization requirements ✅ Completeness: Comprehensive enrich_session/enrich_span documentation ✅ Flexibility: Alternative patterns for different architectures ✅ Maintainability: Removed 2,088 lines of redundant content All code examples validated, docstring formatting fixed, cross-references updated, and integration/user code properly distinguished throughout.
1 parent 30ef480 commit ddf1963

15 files changed

Lines changed: 547 additions & 2339 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
## [Unreleased]
22

33
### Added
4+
5+
- **📚 Documentation: Comprehensive Tutorial & Integration Improvements**
6+
- **Strands Integration**: Removed incorrect `set_tracer_provider()` requirement - SDK auto-handles provider setup
7+
- **Strands Integration**: Added clear integration/user code distinction with comment separators
8+
- **Tutorial 02**: Added explicit tracer→instrumentor initialization order callout
9+
- **Tutorial 02**: Added non-instrumentor pattern section (using `@trace` decorator directly)
10+
- **Tutorial 03**: Added comprehensive `enrich_session()` vs `enrich_span()` guide with decision matrix
11+
- **Tutorial 03**: Added global vs instance method callout for `enrich_span()` patterns
12+
- **Tutorial 06**: Added middleware alternative pattern for distributed tracing (without `context.attach()`)
13+
- **Advanced Tracing**: Added session-level vs span-level enrichment documentation with complete examples
14+
415
- **📚 Documentation: Tracer Initialization Patterns Guide**
516
- New comprehensive guide: "Where Should I Initialize the Tracer?"
617
- Covers 5 scenarios: local dev, evaluate(), serverless, long-running server, testing
@@ -11,13 +22,26 @@
1122
- Location: `docs/how-to/deployment/tracer-initialization-patterns.rst`
1223

1324
### Fixed
25+
26+
- **📚 Documentation: Fixed Docstring Formatting Issues**
27+
- Fixed numerous extra newlines in tutorial docstrings (Tutorials 01, 03, 05)
28+
- Corrected dashboard URL to `https://app.honeyhive.ai/evaluate` (Tutorial 05)
29+
- Fixed broken cross-references after removing redundant advanced-setup tutorial
30+
- Updated reference docs link in Tutorial 02 to point to correct API decorator documentation
31+
1432
- **📚 README: Corrected Import Path for PyPI Display**
1533
- Fixed incorrect import `from honeyhive.tracer.decorators import trace` → `from honeyhive import trace`
1634
- Fixed documentation URL from `docs.honeyhive.ai` to `honeyhiveai.github.io/python-sdk`
1735
- Simplified Quick Start example (removed redundant comments)
1836
- Ensures PyPI package page shows correct usage examples
1937

2038
### Changed
39+
40+
- **📚 Documentation: Content Improvements**
41+
- Documented tracer instance parameter for evaluation functions (Tutorial 05)
42+
- Removed redundant Timing and Error Enrichment sections from Tutorial 03 (now shown in Complete Example)
43+
- Deleted 2,088-line advanced-setup.rst tutorial (content was redundant with advanced-configuration.rst)
44+
2145
- **Version 1.0.0-rc3**: Bumped from 0.1.0-rc3 to reflect stable API
2246
- **📚 Documentation: Strands Integration - Instance Method Pattern**
2347
- Updated all `enrich_span()` usage to use instance method pattern (`tracer.enrich_span()`)

‎docs/development/testing/lambda-testing.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,6 @@ See Also
13131313

13141314
- :doc:`performance-testing` - Performance testing strategies
13151315
- :doc:`ci-cd-integration` - CI/CD integration patterns
1316-
- :doc:`../../tutorials/advanced-setup` - Advanced Lambda configuration
1316+
- :doc:`../../tutorials/advanced-configuration` - Advanced Lambda configuration
13171317
- :doc:`../../how-to/deployment/production` - Production deployment guide
13181318
- :doc:`../../reference/configuration/environment-vars` - Environment configuration

‎docs/development/testing/performance-testing.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,5 +1258,5 @@ See Also
12581258
- :doc:`lambda-testing` - AWS Lambda performance testing
12591259
- :doc:`integration-testing` - Integration performance testing
12601260
- :doc:`ci-cd-integration` - Automated performance testing
1261-
- :doc:`../../tutorials/advanced-setup` - Performance optimization configuration
1261+
- :doc:`../../tutorials/advanced-configuration` - Performance optimization configuration
12621262
- :doc:`../../reference/configuration/environment-vars` - Performance-related settings

‎docs/explanation/architecture/diagrams.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,4 @@ See Also
608608
- :doc:`overview` - Architecture overview
609609
- :doc:`byoi-design` - BYOI design explanation
610610
- :doc:`overview` - Architecture overview
611-
- :doc:`../../tutorials/advanced-setup` - Advanced setup tutorial
611+
- :doc:`../../tutorials/advanced-configuration` - Advanced setup tutorial

‎docs/how-to/advanced-tracing/span-enrichment.rst‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,129 @@ Span Enrichment Patterns
77

88
This guide covers advanced enrichment techniques beyond the basics. For an introduction, see :doc:`/tutorials/03-enable-span-enrichment`.
99

10+
Session-Level vs Span-Level Enrichment
11+
---------------------------------------
12+
13+
HoneyHive provides two enrichment scopes: **session-level** and **span-level**.
14+
15+
**``enrich_session()`` - Apply metadata to all spans in a session:**
16+
17+
.. code-block:: python
18+
19+
from honeyhive import HoneyHiveTracer
20+
21+
tracer = HoneyHiveTracer.init(project="my-app")
22+
23+
# Apply to ALL spans in this session
24+
tracer.enrich_session({
25+
"user_id": "user_456",
26+
"user_tier": "enterprise",
27+
"environment": "production",
28+
"deployment_region": "us-east-1"
29+
})
30+
31+
# All subsequent operations inherit this metadata
32+
response1 = call_llm(...)
33+
response2 = call_llm(...)
34+
response3 = call_llm(...)
35+
# All 3 traces will have user_id, user_tier, environment, deployment_region
36+
37+
**Use ``enrich_session()`` for:**
38+
39+
- ✅ User identification (user_id, email, tier)
40+
- ✅ Session context (session_type, workflow_name)
41+
- ✅ Environment info (environment, region, version)
42+
- ✅ Business context (customer_id, account_type, plan)
43+
- ✅ Any metadata that applies to the entire user session
44+
45+
**``enrich_span()`` - Apply metadata to a single span:**
46+
47+
.. code-block:: python
48+
49+
from honeyhive import enrich_span
50+
51+
def process_query(query: str, use_cache: bool):
52+
# Apply to THIS specific span only
53+
enrich_span({
54+
"query_length": len(query),
55+
"cache_enabled": use_cache,
56+
"model": "gpt-4",
57+
"temperature": 0.7
58+
})
59+
60+
return call_llm(query)
61+
62+
**Use ``enrich_span()`` for:**
63+
64+
- ✅ Per-call parameters (model, temperature, max_tokens)
65+
- ✅ Call-specific metrics (input_length, cache_hit, latency)
66+
- ✅ Dynamic metadata (intent_classification, confidence_score)
67+
- ✅ Error details (error_type, retry_count)
68+
- ✅ Any metadata that varies per LLM call
69+
70+
**Example combining both:**
71+
72+
.. code-block:: python
73+
74+
from honeyhive import HoneyHiveTracer
75+
76+
# Session-level: Set once for the entire user session
77+
tracer = HoneyHiveTracer.init(
78+
project="customer-support",
79+
session_name="support-session-789"
80+
)
81+
82+
tracer.enrich_session({
83+
"user_id": "user_456",
84+
"support_tier": "premium",
85+
"issue_category": "billing"
86+
})
87+
88+
# Span-level: Varies per call
89+
def handle_query(query: str):
90+
intent = classify_intent(query)
91+
92+
tracer.enrich_span({
93+
"query_intent": intent,
94+
"query_length": len(query),
95+
"model": "gpt-4" if intent == "complex" else "gpt-3.5-turbo"
96+
})
97+
98+
return generate_response(query)
99+
100+
# Each call has both session + span metadata
101+
handle_query("How do I change my billing address?")
102+
handle_query("What's my current balance?")
103+
handle_query("Can I upgrade my plan?")
104+
105+
**Decision Matrix:**
106+
107+
+------------------------------+-------------------------+-------------------------+
108+
| **Metadata Type** | **Scope** | **Method** |
109+
+==============================+=========================+=========================+
110+
| User ID, email | Session (constant) | ``enrich_session()`` |
111+
+------------------------------+-------------------------+-------------------------+
112+
| Model name, temperature | Span (varies) | ``enrich_span()`` |
113+
+------------------------------+-------------------------+-------------------------+
114+
| Environment (prod/dev) | Session (constant) | ``enrich_session()`` |
115+
+------------------------------+-------------------------+-------------------------+
116+
| Cache hit/miss | Span (per-call) | ``enrich_span()`` |
117+
+------------------------------+-------------------------+-------------------------+
118+
| Customer tier | Session (constant) | ``enrich_session()`` |
119+
+------------------------------+-------------------------+-------------------------+
120+
| Prompt token count | Span (per-call) | ``enrich_span()`` |
121+
+------------------------------+-------------------------+-------------------------+
122+
| Deployment region | Session (constant) | ``enrich_session()`` |
123+
+------------------------------+-------------------------+-------------------------+
124+
| Error type/message | Span (when it occurs) | ``enrich_span()`` |
125+
+------------------------------+-------------------------+-------------------------+
126+
127+
.. tip::
128+
**Rule of Thumb:**
129+
130+
If the metadata is the same for all LLM calls in a user session, use ``enrich_session()``.
131+
If it changes per call, use ``enrich_span()``.
132+
10133
Understanding Enrichment Interfaces
11134
-----------------------------------
12135

‎docs/how-to/integrations/strands.rst‎

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ AWS Strands is an AI agent framework that:
2424
Integration Approach
2525
~~~~~~~~~~~~~~~~~~~~
2626

27-
HoneyHive integrates with AWS Strands using the **OpenTelemetry TracerProvider pattern**.
27+
HoneyHive integrates with AWS Strands using **automatic OpenTelemetry provider setup**.
2828

2929
**Key Difference from Other Integrations:**
3030

3131
Unlike OpenAI or Anthropic (which require instrumentors like OpenInference or Traceloop), **AWS Strands has built-in OpenTelemetry tracing**. This means:
3232

3333
- ✅ **NO instrumentor needed** - Strands instruments its own LLM calls
34+
- ✅ **NO manual provider setup** - ``HoneyHiveTracer.init()`` handles it automatically
3435
- ✅ **Built-in GenAI conventions** - All model calls automatically traced
3536
- ✅ **Don't use OpenInference/Traceloop** - Would create duplicate spans
3637
- ✅ **Zero modifications to Strands code** - Works with Strands as-is
@@ -41,10 +42,22 @@ Unlike OpenAI or Anthropic (which require instrumentors like OpenInference or Tr
4142

4243
**How It Works:**
4344

44-
1. HoneyHive provides a TracerProvider
45-
2. Set it as the global OpenTelemetry provider
46-
3. Strands automatically uses it for all its built-in tracing
47-
4. All LLM calls, agent actions, and tool executions are traced
45+
1. Call ``HoneyHiveTracer.init()`` - automatically sets up global TracerProvider
46+
2. Strands automatically uses it for all its built-in tracing
47+
3. All LLM calls, agent actions, and tool executions are traced
48+
49+
Complete Example
50+
~~~~~~~~~~~~~~~~
51+
52+
**See the full code:** `strands_integration.py <https://github.com/honeyhiveai/python-sdk/blob/main/examples/integrations/strands_integration.py>`_
53+
54+
A comprehensive working example is available in the repository at ``examples/integrations/strands_integration.py``:
55+
56+
- ✅ All 8 integration patterns shown below
57+
- ✅ Basic agent invocation, tool execution, streaming responses
58+
- ✅ Custom trace attributes, structured outputs with Pydantic
59+
- ✅ Swarm multi-agent collaboration, graph workflows with parallel processing
60+
- ✅ Copy-paste ready code for quick start
4861

4962
What Gets Traced
5063
~~~~~~~~~~~~~~~~
@@ -138,22 +151,22 @@ Minimal Setup (3 Lines of Code)
138151

139152
.. code-block:: python
140153
154+
# ============= HONEYHIVE INTEGRATION =============
141155
from honeyhive import HoneyHiveTracer
142-
from strands import Agent
143-
from strands.models import BedrockModel
144-
from opentelemetry import trace as trace_api
145156
import os
146157
147-
# 1. Initialize HoneyHive tracer
158+
# Initialize HoneyHive tracer - automatic global provider setup
148159
tracer = HoneyHiveTracer.init(
149160
api_key=os.getenv("HH_API_KEY"),
150161
project="strands-demo",
151162
)
163+
# ==================================================
152164
153-
# 2. Set as global TracerProvider (BEFORE creating agents)
154-
trace_api.set_tracer_provider(tracer.provider)
165+
# ============= YOUR STRANDS CODE ==================
166+
from strands import Agent
167+
from strands.models import BedrockModel
155168
156-
# 3. Use Strands normally - tracing is automatic!
169+
# Use Strands normally - tracing is automatic!
157170
agent = Agent(
158171
name="BasicAgent",
159172
model=BedrockModel(model_id="anthropic.claude-haiku-4-5-20251001-v1:0"),
@@ -162,29 +175,37 @@ Minimal Setup (3 Lines of Code)
162175
163176
result = agent("What is 2+2?")
164177
print(result) # "2+2 equals 4"
178+
# ==================================================
165179
166180
**That's it!** All agent activity is now automatically traced to HoneyHive.
167181

182+
.. note::
183+
**No Manual Provider Setup Required**
184+
185+
Unlike some integrations, you don't need to manually call ``trace_api.set_tracer_provider()``.
186+
The SDK automatically handles OpenTelemetry provider setup during ``HoneyHiveTracer.init()``.
187+
188+
AWS Strands has built-in OpenTelemetry support that works seamlessly with HoneyHive's automatic configuration.
189+
168190
Basic Agent Example
169191
~~~~~~~~~~~~~~~~~~~
170192

171193
.. code-block:: python
172194
195+
# ============= HONEYHIVE INTEGRATION =============
173196
from honeyhive import HoneyHiveTracer
174-
from strands import Agent
175-
from strands.models import BedrockModel
176-
from opentelemetry import trace as trace_api
177197
import os
178198
179-
# Initialize HoneyHive
180199
tracer = HoneyHiveTracer.init(
181200
api_key=os.getenv("HH_API_KEY"),
182201
project="strands-agents",
183202
session_name="basic-agent-demo"
184203
)
204+
# ==================================================
185205
186-
# Set as global provider
187-
trace_api.set_tracer_provider(tracer.provider)
206+
# ============= YOUR STRANDS CODE ==================
207+
from strands import Agent
208+
from strands.models import BedrockModel
188209
189210
# Create agent
190211
agent = Agent(
@@ -724,13 +745,11 @@ This happens if you accidentally enable LLM instrumentors (OpenInference/Tracelo
724745
from openinference.instrumentation.openai import OpenAIInstrumentor
725746
OpenAIInstrumentor().instrument() # Will create duplicate spans!
726747
727-
# ✅ DO THIS - Just use TracerProvider pattern
748+
# ✅ DO THIS - Just initialize HoneyHive
728749
from honeyhive import HoneyHiveTracer
729-
from opentelemetry import trace as trace_api
730750
731751
tracer = HoneyHiveTracer.init(...)
732-
trace_api.set_tracer_provider(tracer.provider)
733-
# That's it - Strands handles the rest!
752+
# That's it - automatic provider setup, Strands handles the rest!
734753
735754
**Issue: "Unable to locate credentials"**
736755

@@ -764,7 +783,7 @@ Use correct Bedrock model IDs (not OpenAI model names):
764783

765784
1. Verify ``HH_API_KEY`` is set correctly
766785
2. Check project name matches your HoneyHive project
767-
3. Ensure ``trace_api.set_tracer_provider()`` is called BEFORE creating agents
786+
3. Ensure ``HoneyHiveTracer.init()`` is called BEFORE creating agents
768787
4. Look for error messages in console output
769788

770789
Debugging Traces
@@ -804,20 +823,19 @@ Print session ID for manual verification:
804823
Best Practices
805824
--------------
806825

807-
1. **Set TracerProvider Early**
826+
1. **Initialize Tracer Early**
808827

809-
Always call ``trace_api.set_tracer_provider()`` before creating agents:
828+
Always call ``HoneyHiveTracer.init()`` before creating agents (automatic provider setup):
810829

811830
.. code-block:: python
812831
813832
# ✅ Correct order
814-
tracer = HoneyHiveTracer.init(...)
815-
trace_api.set_tracer_provider(tracer.provider)
833+
tracer = HoneyHiveTracer.init(...) # Automatic global provider setup
816834
agent = Agent(...) # Now traced
817835
818836
# ❌ Wrong order
819837
agent = Agent(...) # Not traced
820-
tracer = HoneyHiveTracer.init(...)
838+
tracer = HoneyHiveTracer.init(...) # Too late!
821839
822840
2. **Don't Use LLM Instrumentors**
823841

@@ -831,8 +849,7 @@ Best Practices
831849
832850
# ✅ DO THIS - Strands instruments itself
833851
tracer = HoneyHiveTracer.init(...)
834-
trace_api.set_tracer_provider(tracer.provider)
835-
# Strands' built-in tracing handles everything
852+
# Strands' built-in tracing handles everything (no manual provider setup needed)
836853
837854
3. **Use Meaningful Agent Names**
838855

@@ -894,21 +911,4 @@ Next Steps
894911
- :doc:`/reference/api/tracer` - Full tracer API reference
895912
- `AWS Strands Documentation <https://github.com/strands-agents/sdk-python>`_ - Learn more about Strands
896913

897-
Complete Example
898-
----------------
899-
900-
A comprehensive example is available in the repository:
901-
902-
**`examples/integrations/strands_integration.py`** - Full integration demo with 8 test cases:
903-
904-
- Basic agent invocation
905-
- Tool execution with calculator
906-
- Streaming responses
907-
- Custom trace attributes
908-
- Structured outputs with Pydantic
909-
- Swarm multi-agent collaboration
910-
- Graph workflows with parallel processing
911-
- All patterns shown in this guide
912-
913-
View it on GitHub: `strands_integration.py <https://github.com/honeyhiveai/python-sdk/blob/main/examples/integrations/strands_integration.py>`_
914914

0 commit comments

Comments
 (0)