graphiti/graphiti_core
Daniel Chalef 6ad695186a
Add OpenTelemetry distributed tracing support (#982)
* Add OpenTelemetry distributed tracing support

- Add tracer abstraction with no-op and OpenTelemetry implementations
- Instrument add_episode and add_episode_bulk with tracing spans
- Instrument LLM client with cache-aware tracing
- Add configurable span name prefix support
- Refactor add_episode methods to improve code quality
- Add OTEL_TRACING.md documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix linting errors in tracing implementation

- Remove unused episodes_by_uuid variable
- Fix tracer type annotations for context manager support
- Replace isinstance tuple with union syntax
- Use contextlib.suppress for exception handling
- Fix import ordering and use AbstractContextManager

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Address PR review feedback on tracing implementation

Critical fixes:
- Remove flawed error span creation in graphiti.py that created orphaned spans
- Restructure LLM client tracing to create span once at start, eliminating code duplication
- Initialize LLM client tracer to NoOpTracer by default to fix type checking

Enhancements:
- Add comprehensive span attributes to add_episode: reference_time, entity/edge type counts, previous episodes count, invalidated edge count, community count
- Optimize isinstance check for better performance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add prompt name tracking to OpenTelemetry tracing spans

Add prompt_name parameter to all LLM client generate_response() methods
and set it as a span attribute in the llm.generate span. This enables
better observability by identifying which prompt template was used for
each LLM call.

Changes:
- Add prompt_name parameter to LLMClient.generate_response() base method
- Add prompt_name parameter and tracing to OpenAIBaseClient,
  AnthropicClient, GeminiClient, and OpenAIGenericClient
- Update all 14 LLM call sites across maintenance operations to include
  prompt_name:
  - edge_operations.py: 4 calls
  - node_operations.py: 6 calls (note: 7 listed but only 6 unique)
  - temporal_operations.py: 2 calls
  - community_operations.py: 2 calls

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix exception handling in add_episode to record errors in OpenTelemetry span

Moved try-except block inside the OpenTelemetry span context and added
proper error recording with span.set_status() and span.record_exception().
This ensures exceptions are captured in the distributed trace, matching
the pattern used in add_episode_bulk.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-05 12:26:14 -07:00
..
cross_encoder fix typo and model selector (#843) 2025-08-18 11:15:45 -04:00
driver remove generic aoss_client interactions for release build (#975) 2025-10-03 13:41:15 -04:00
embedder OpenSearch Integration for Neo4j (#896) 2025-09-09 10:51:46 -04:00
llm_client Add OpenTelemetry distributed tracing support (#982) 2025-10-05 12:26:14 -07:00
migrations cleanup (#894) 2025-09-05 11:30:46 -04:00
models OpenSearch Integration for Neo4j (#896) 2025-09-09 10:51:46 -04:00
prompts Refactor prompt structure: move MESSAGES after instructions (#980) 2025-10-04 19:06:32 -07:00
search Remove ensure_ascii configuration parameter (#969) 2025-10-02 15:10:57 -07:00
telemetry feat: add telemetry with PostHog and update Docker configurations (#633) 2025-06-27 12:23:30 -07:00
utils Add OpenTelemetry distributed tracing support (#982) 2025-10-05 12:26:14 -07:00
__init__.py chore: Fix packaging (#38) 2024-08-25 10:07:50 -07:00
edges.py filter out falsey values before creating embeddings (#966) 2025-10-02 15:26:51 -04:00
errors.py Add group ID validation and error handling (#618) 2025-06-24 09:33:54 -07:00
graph_queries.py Graph quality updates (#922) 2025-09-23 17:53:39 -04:00
graphiti.py Add OpenTelemetry distributed tracing support (#982) 2025-10-05 12:26:14 -07:00
graphiti_types.py Add OpenTelemetry distributed tracing support (#982) 2025-10-05 12:26:14 -07:00
helpers.py fix-fulltext-syntax-error (#914) 2025-09-23 10:52:44 -04:00
nodes.py filter out falsey values before creating embeddings (#966) 2025-10-02 15:26:51 -04:00
py.typed Add py.typed file (#105) 2024-09-11 08:44:06 -04:00
tracer.py Add OpenTelemetry distributed tracing support (#982) 2025-10-05 12:26:14 -07:00