Skip to content

Comments

feat: Add Mem0 memory operation instrumentation#4252

Draft
nagkumar91 wants to merge 6 commits intoopen-telemetry:mainfrom
nagkumar91:nag/mem0-memory-instrumentation
Draft

feat: Add Mem0 memory operation instrumentation#4252
nagkumar91 wants to merge 6 commits intoopen-telemetry:mainfrom
nagkumar91:nag/mem0-memory-instrumentation

Conversation

@nagkumar91
Copy link
Contributor

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

  • New package: instrumentation-genai/opentelemetry-instrumentation-mem0/
  • Wraps mem0.memory.main.Memory methods via wrapt:
    • Memory.add()update_memory span
    • Memory.search()search_memory span
    • Memory.update()update_memory span
    • Memory.delete()delete_memory span
    • Memory.delete_all()delete_memory span
    • Memory.get_all()search_memory span

Attributes emitted

  • gen_ai.operation.name — memory operation type
  • gen_ai.systemmem0
  • gen_ai.memory.scope — inferred from kwargs (user/agent/session)
  • gen_ai.memory.namespace — user/agent identifier
  • gen_ai.memory.id — memory record ID (when available)
  • gen_ai.memory.query — search query (opt-in via OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT)
  • gen_ai.memory.content — memory content (opt-in)
  • gen_ai.memory.search.result.count — number of search results

Related PRs

How has this been tested?

pytest instrumentation-genai/opentelemetry-instrumentation-mem0/tests/ -v

11 tests covering all 6 wrapped methods, content capture toggle, error handling.

Type of change

  • New feature (non-breaking change which adds functionality)

Does This PR Require a Core Repo Change?

  • No.

Checklist

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added

nagkumar91 and others added 4 commits February 18, 2026 13:19
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>
@nagkumar91 nagkumar91 requested a review from a team as a code owner February 23, 2026 20:52
@nagkumar91 nagkumar91 marked this pull request as draft February 23, 2026 20:53
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants