Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API
MIT License
741 stars 494 forks source link

Traces - Options to customize trace listeners #2240

Closed ealsur closed 2 years ago

ealsur commented 3 years ago

Adding options to customize Trace listeners for our traces when running on NET Core environment would be great, and also, to disable all trace listeners (including DefaultTraceListener).

If users want to send traces to a particular sink, in NET Core, today it's extremely complex. When running in NETFX, this can be achieved by web.config/app.config.

It requires some weird hack like:

Type defaultTrace = Type.GetType("Microsoft.Azure.Cosmos.Core.Trace.DefaultTrace,Microsoft.Azure.Cosmos.Direct");
TraceSource traceSource = (TraceSource)defaultTrace.GetProperty("TraceSource").GetValue(null);
traceSource.Switch.Level = SourceLevels.All;
traceSource.Listeners.Clear();
traceSource.Listeners.Add(... my desired listener);

Ideally, we could expose some config APIs like:

For performance reasons, any application that does not want to collect traces can disable them to avoid any lock contention on the default machine-wide tracing.

bchong95 commented 3 years ago

This is similar to this issue: https://github.com/Azure/azure-cosmos-dotnet-v3/issues/1224

j82w commented 3 years ago

I think there is some confusion. This is not related to CosmosDiagnostics. This is only referring to the DefaultTrace inside the SDK as part of the .NET framework. CosmosDiagnostic levels will need to be handled separately. I think the naming will need to be clear to avoid confusion.

ealsur commented 3 years ago

Yes, this has no relationship with Diagnostics in the operations, but rather the SDK usage of DefaultTrace across the code.

j82w commented 3 years ago

I think it needs to be renamed to CosmosClientOptions.TraceOptions to avoid confusion with CosmosDiagnostics.

emyfreya commented 2 years ago

@ealsur I have a hard time to follow. I cannot find this options with the package Microsoft.Azure.Cosmos version 3.27.0.

Has this been implemented or do we still have to use reflection ?

Also has any implementation with Microsoft.Extensions.Logging.ILoggerFactory and Microsoft.Extensions.Logging.ILogger are planned ? I think this SDK is used a lot in WebServices and it would be great to have a dependency injection compatible SDK.

ealsur commented 2 years ago

@RamenTurismo not implemented. The team is working on AI (Application Insights) and Open Telemetry integration, PRs for that are in progress.