Skip to content

Commit

Permalink
Logging state during building of TracerProvider (#3746)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoel committed Oct 14, 2022
1 parent 8db45a3 commit 6d5dd37
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ 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 sealed class TracerProviderSdk : TracerProvider
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 sealed class TracerProviderSdk : TracerProvider
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 sealed class TracerProviderSdk : TracerProvider

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

internal Resource Resource { get; }
Expand Down

0 comments on commit 6d5dd37

Please sign in to comment.