Skip to content

Commit

Permalink
Logging state during building of TracerProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoel committed Oct 13, 2022
1 parent 73f8d3c commit 12611f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
23 changes: 23 additions & 0 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using OpenTelemetry.Internal;
using OpenTelemetry.Resources;

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -264,6 +286,7 @@ internal TracerProviderSdk(

ActivitySource.AddActivityListener(listener);
this.listener = listener;
OpenTelemetrySdkEventSource.Log.TracerProviderSdkEvent("TracerProvider built successfully.");
}

internal Resource Resource { get; }
Expand Down

0 comments on commit 12611f6

Please sign in to comment.