From 80ce884f64e754823cc240921393c66bca300c14 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Sun, 9 Oct 2022 17:51:51 +0530 Subject: [PATCH] Logging state during building of TracerProvider --- .../Internal/OpenTelemetrySdkEventSource.cs | 7 ++++++ src/OpenTelemetry/Trace/TracerProviderSdk.cs | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs b/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs index f9f6b6f2ed8..8cbb811afa6 100644 --- a/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs +++ b/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs @@ -408,6 +408,13 @@ public void OpenTelemetryLoggerProviderForceFlushInvoked(int timeoutMilliseconds this.WriteEvent(45, timeoutMilliseconds); } + [Event(46, Message = "TracerProviderSdk event: '{0}'", Level = EventLevel.Verbose)] + public void TracerProviderSdkEvent(string message) + { + this.WriteEvent(46, message); + } + + #if DEBUG public class OpenTelemetryEventListener : EventListener { diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index 13d3d969cb0..b8b0f14919f 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -21,6 +21,7 @@ using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; +using System.Text; using OpenTelemetry.Internal; using OpenTelemetry.Resources; @@ -49,12 +50,17 @@ internal TracerProviderSdk( Debug.Assert(this.OwnedServiceProvider != null, "serviceProvider was not IDisposable"); } + OpenTelemetrySdkEventSource.Log.TracerProviderSdkEvent("Building TracerProvider."); + var state = new TracerProviderBuilderState(serviceProvider); TracerProviderBuilderServiceCollectionHelper.InvokeRegisteredConfigureStateCallbacks( serviceProvider, state); + StringBuilder processorsAdded = new StringBuilder(); + StringBuilder instrumentationFactoriesAdded = new StringBuilder(); + if (state.SetErrorStatusOnException) { state.EnableErrorStatusOnException(); @@ -79,11 +85,27 @@ internal TracerProviderSdk( foreach (var processor in state.Processors) { this.AddProcessor(processor); + processorsAdded.Append(processor.GetType()); + processorsAdded.Append(';'); } foreach (var instrumentation in state.Instrumentation) { this.instrumentations.Add(instrumentation.Instance); + instrumentationFactoriesAdded.Append(instrumentation.Name); + instrumentationFactoriesAdded.Append(';'); + } + + if (processorsAdded.Length != 0) + { + processorsAdded.Remove(processorsAdded.Length - 1, 1); + OpenTelemetrySdkEventSource.Log.TracerProviderSdkEvent($"Processors added = \"{processorsAdded}\"."); + } + + if (instrumentationFactoriesAdded.Length != 0) + { + instrumentationFactoriesAdded.Remove(instrumentationFactoriesAdded.Length - 1, 1); + OpenTelemetrySdkEventSource.Log.TracerProviderSdkEvent($"Instrumentations added = \"{instrumentationFactoriesAdded}\"."); } var listener = new ActivityListener(); @@ -264,6 +286,7 @@ internal TracerProviderSdk( ActivitySource.AddActivityListener(listener); this.listener = listener; + OpenTelemetrySdkEventSource.Log.TracerProviderSdkEvent("TracerProvider built successfully."); } internal Resource Resource { get; }