feat: Add Mem0 memory operation instrumentation#4252
Draft
nagkumar91 wants to merge 6 commits intoopen-telemetry:mainfrom
Draft
feat: Add Mem0 memory operation instrumentation#4252nagkumar91 wants to merge 6 commits intoopen-telemetry:mainfrom
nagkumar91 wants to merge 6 commits intoopen-telemetry:mainfrom
Conversation
Implement PR 3250 memory operation coverage in openai-agents-v2 and langchain, including memory span attributes and retriever memory search telemetry tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…conv-genai # Conflicts: # instrumentation-genai/opentelemetry-instrumentation-langchain/CHANGELOG.md
…ch_memory' LangChain's retriever abstraction is generic — it covers both RAG/vector DB search and memory retrieval. Defaulting all retrievers to search_memory was incorrect for non-memory retrievers. Now: - Default operation is 'retrieval' for all retrievers - Only use 'search_memory' when metadata explicitly indicates memory (memory_store_name, memory_store_id, or is_memory_retriever flag) - Memory attributes (gen_ai.memory.*) are still attached when present Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds opentelemetry-instrumentation-mem0 package that traces Mem0 Memory class operations (add, search, update, delete, delete_all, get_all) with GenAI memory semantic convention attributes. Operations mapped: - Memory.add() → update_memory - Memory.search() → search_memory - Memory.update() → update_memory - Memory.delete() → delete_memory - Memory.delete_all() → delete_memory - Memory.get_all() → search_memory Attributes emitted: - gen_ai.operation.name, gen_ai.system (mem0) - gen_ai.memory.scope (user/agent/session inferred from kwargs) - gen_ai.memory.namespace, gen_ai.memory.id - gen_ai.memory.query, gen_ai.memory.content (opt-in) - gen_ai.memory.search.result.count Related: open-telemetry/semantic-conventions#3250 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add gen_ai.provider.name attribute on all spans - Add gen_ai.memory.update.strategy (merge for add, overwrite for update) - Add gen_ai.client.operation.duration histogram metric - Add error.type attribute on error spans - Add content capture for update() operations - Add opentelemetry-util-genai dependency for shared metric helpers - Duration metrics recorded in finally block (both success/error) - 12 tests covering all operations, metrics, error handling Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
opentelemetry-instrumentation-mem0— a new GenAI instrumentation package that traces Mem0 memory operations using OpenTelemetry, aligned with the GenAI memory semantic conventions proposed in open-telemetry/semantic-conventions#3250.What changed
instrumentation-genai/opentelemetry-instrumentation-mem0/mem0.memory.main.Memorymethods viawrapt:Memory.add()→update_memoryspanMemory.search()→search_memoryspanMemory.update()→update_memoryspanMemory.delete()→delete_memoryspanMemory.delete_all()→delete_memoryspanMemory.get_all()→search_memoryspanAttributes emitted
gen_ai.operation.name— memory operation typegen_ai.system—mem0gen_ai.memory.scope— inferred from kwargs (user/agent/session)gen_ai.memory.namespace— user/agent identifiergen_ai.memory.id— memory record ID (when available)gen_ai.memory.query— search query (opt-in viaOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT)gen_ai.memory.content— memory content (opt-in)gen_ai.memory.search.result.count— number of search resultsRelated PRs
How has this been tested?
11 tests covering all 6 wrapped methods, content capture toggle, error handling.
Type of change
Does This PR Require a Core Repo Change?
Checklist