Observability with OpenTelemetry
LangChain.Databases includes built-in distributed tracing via System.Diagnostics.ActivitySource. All vector store operations emit activities that can be collected by any OpenTelemetry-compatible exporter.
Activity sources
| Source name | Package |
|---|---|
LangChain.Databases.Postgres |
LangChain.Databases.Postgres |
LangChain.Databases.OpenSearch |
LangChain.Databases.OpenSearch |
Operations traced
Both VectorStore and VectorStoreCollection operations are instrumented:
| Activity name | Description |
|---|---|
{system}.list_collections |
List all collection/index names |
{system}.collection_exists |
Check if a collection exists |
{system}.create_collection |
Create a collection (table/index) |
{system}.delete_collection |
Delete a collection |
{system}.get |
Retrieve a record by key |
{system}.upsert |
Insert or update a single record |
{system}.upsert_batch |
Batch insert or update records |
{system}.delete |
Delete a single record |
{system}.delete_batch |
Batch delete records |
{system}.search |
Vector similarity search |
Where {system} is postgresql or opensearch.
Tags (attributes)
Each activity includes OpenTelemetry Database semantic convention tags:
| Tag | Description | Example |
|---|---|---|
db.system.name |
Database system identifier | postgresql, opensearch |
db.namespace |
Database name or host | mydb, localhost |
db.collection.name |
Table or index name | documents |
Setup with .NET OpenTelemetry SDK
Install the OpenTelemetry packages:
1 2 3 4 | |
Configure tracing in your application:
1 2 3 4 5 6 7 8 | |
Or with ASP.NET Core dependency injection:
1 2 3 4 5 | |
Example output
With the console exporter, you'll see traces like:
1 2 3 4 5 6 7 | |
Metadata via GetService
Both stores expose metadata through the MEVA GetService pattern:
1 2 3 4 5 6 7 8 9 10 | |