Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
mem0 Agent Memory Tracing with OpenLIT
This example demonstrates how OpenLIT automatically instruments mem0 memory operations and exports them as OpenTelemetry spans — giving you full visibility into the memory read/write patterns of your LLM agents.
Agent memory is a growing observability need: when an agent adds, searches, and prunes memories, you want those operations to show up in your traces right alongside your LLM spans. OpenLIT's mem0 instrumentation does this automatically — no manual span creation required.
What this example demonstrates
The app.py script exercises the core mem0 memory operations,
each of which is captured as its own span by OpenLIT:
| mem0 call | Span name | What it captures |
|---|---|---|
Memory.add() |
memory add |
user id, input message count, (optional) raw input |
Memory.search() |
memory search |
search query, limit, threshold, result count |
Memory.get_all() |
memory get_all |
user id, number of memories returned |
Memory.delete() |
memory delete |
deleted memory id |
Prerequisites
Python 3.10+ (required by mem0)
An OpenTelemetry-compatible backend listening on
http://localhost:4318(for example, the OpenLIT docker-compose stack).A model backend for mem0. By default this example uses a local Ollama server so it runs without any hosted API keys:
ollama pull llama3.1 ollama pull nomic-embed-textThe default Ollama path requires the
ollamaPython package (listed inrequirements.txt), which is installed by thepip installstep below.Alternatively, set
MEM0_USE_DEFAULT=1to use mem0's default OpenAI-backed configuration, in which case you must exportOPENAI_API_KEY.
Install
pip install -r requirements.txt
Run
python app.py
The script prints each memory operation as it runs and then flushes the spans to your OTLP endpoint.
Expected OpenTelemetry attributes
Every mem0 span emitted by OpenLIT includes a common set of GenAI semantic convention attributes, for example:
gen_ai.provider.name = mem0gen_ai.operation.name = memory(user-facing memory operations)gen_ai.user.id = alex-demoservice.name = mem0-agent-demodeployment.environment = development
Operation-specific attributes are added on top, such as:
gen_ai.memory.countonmemory addgen_ai.memory.search.query,gen_ai.memory.search.limitonmemory searchgen_ai.memory.operation.result_countonmemory search/memory get_alldb.delete.idonmemory delete
If content capture is enabled in openlit.init(...), the raw input messages
(gen_ai.input.messages) and search results (gen_ai.output.messages) are
captured as well.