Skip to content

Add CosmosClientTelemetryOptions.DisableDistributedTracing #37615

@filipmhpersson

Description

@filipmhpersson

Question

I'm currently looking at moving some services that use entity framework core with the cosmos db provider to open telemetry.

But my big blocker is that I cannot get traces / dependencies (in application insights) to be registered for any database calls that uses entity framework.

So I'm writing this question to understand which of the questions below are true:
Am I missing something?
Is it intentional?
Is something missing in ef cores cosmos client options wrapper?

With how heavily dotnet aspire and open telemetry is being pushed right now this seems like an important feature to have.

Below follows my investigation of what I have tried and found out about configuring tracing for the cosmos db client and how it works with ef core's cosmos dk provider:

The Cosmos DB SDK has this particular flag to be able to see cosmos db dependencies and I cannot find a way to get dependencies working without this flag turned on.

The flag is called:
CosmosClientOptions.CosmosClientTelemetryOptions. DisableDistributedTracing

And I cannot find a way in ef core to either change the flag or configure the underlying cosmos db provider.

The only way I have found to get traces from cosmos db request to work together with entity framework in both aspire and our own services is to force preview versions of the Microsoft.Azure.Cosmos package. And the reason this works can be found here:

https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs#L

        public bool DisableDistributedTracing { get; set; } =
#if PREVIEW
        false;
#else
        true;
#endif

To sanity check myself I have made a minimal lab with dotnet aspire, let me know if you want it published.

But following the guides for dotnet aspire and looking at howdotnet aspire registers the cosmos client their own example doesn't work.

In aspires own code here:
https://github.com/dotnet/aspire/blob/main/src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs

They are registering the Azure.Cosmos.Operation source. But this source doesn't do anything without the DistributedTracing flag switched in the cosmos client.

 builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>
            {
                tracerProviderBuilder.AddSource("Azure.Cosmos.Operation");
            });

If I instead as I suggested above use the preview version of the underlying Microsoft.Azure.Cosmos nuget package the tracing works flawlessly in dotnet aspire.

But I want the possibility for distributed tracing in services running in production so I don't see forcing preview packages as a reasonable workaround.

Your code

Stack traces


Verbose output


EF Core version

10.0.2

Database provider

Microsoft.EntityFrameworkCore.Cosmos

Target framework

.NET 10

Operating system

No response

IDE

No response

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions