---
title: Set up Azure Cosmos DB instrumentation
description: How to enable Elastic APM .NET Agent instrumentation of Azure Cosmos DB operations to capture them as APM spans.
url: https://www.elastic.co/docs/reference/apm/agents/dotnet/setup-azure-cosmosdb
products:
  - APM .NET Agent
  - APM Agent
applies_to:
  - Serverless Observability projects: Generally available
  - Elastic Stack: Generally available
  - Application Performance Monitoring Agent for .NET: Generally available
---

# Set up Azure Cosmos DB instrumentation
## Supported versions


| Package                                    | Supported versions |
|--------------------------------------------|--------------------|
| `Microsoft.Azure.Cosmos`                   | ≥3.0.0 <4.0.0      |
| `Microsoft.Azure.DocumentDB.Core` (legacy) | ≥2.4.1 <3.0.0      |
| `Microsoft.Azure.DocumentDB` (legacy)      | ≥2.4.1 <3.0.0      |

For the full compatibility matrix including supported installation methods, refer to [Data access technologies](/docs/reference/apm/agents/dotnet/supported-technologies#supported-data-access-technologies).
<note>
  `Microsoft.Azure.DocumentDB.Core` and `Microsoft.Azure.DocumentDB` are deprecated. The recommended replacement is `Microsoft.Azure.Cosmos`.
</note>


## Quick start

This page assumes the core agent is already set up. If not, see [Set up the APM .NET Agent](https://www.elastic.co/docs/reference/apm/agents/dotnet/set-up-apm-net-agent) first.
Add the [`Elastic.Apm.Azure.CosmosDb`](https://www.nuget.org/packages/Elastic.Apm.Azure.CosmosDb) NuGet package to your project:
```sh
dotnet add package Elastic.Apm.Azure.CosmosDb
```

Subscribe to diagnostic events once at application startup:
```csharp
using Elastic.Apm;
using Elastic.Apm.Azure.CosmosDb;

Agent.Subscribe(new AzureCosmosDbDiagnosticsSubscriber());
```

Diagnostic events from `Microsoft.Azure.Cosmos`, `Microsoft.Azure.DocumentDb`, and `Microsoft.Azure.DocumentDb.Core` are captured as DB spans.