Skip to content

Commit

Permalink
Fixed automatically created CompositeProcessor missing ParentProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Jun 15, 2022
1 parent 8b29b34 commit e9e4379
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ internal OpenTelemetryLoggerProvider AddProcessor(BaseProcessor<LogRecord> proce
}
else
{
this.Processor = new CompositeProcessor<LogRecord>(new[]
var newCompositeProcessor = new CompositeProcessor<LogRecord>(new[]
{
this.Processor,
processor,
});
newCompositeProcessor.SetParentProvider(this);
newCompositeProcessor.AddProcessor(processor);
this.Processor = newCompositeProcessor;
}

return this;
Expand Down
6 changes: 4 additions & 2 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ internal TracerProviderSdk AddProcessor(BaseProcessor<Activity> processor)
}
else
{
this.processor = new CompositeProcessor<Activity>(new[]
var newCompositeProcessor = new CompositeProcessor<Activity>(new[]
{
this.processor,
processor,
});
newCompositeProcessor.SetParentProvider(this);
newCompositeProcessor.AddProcessor(processor);
this.processor = newCompositeProcessor;
}

return this;
Expand Down
14 changes: 11 additions & 3 deletions test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,11 @@ public void SdkProcessesLegacyActivityEvenAfterAddingNewProcessor()

// AddLegacyOperationName chained to TracerProviderBuilder
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddProcessor(testActivityProcessor)
.AddLegacySource(operationNameForLegacyActivity)
.Build();
.AddProcessor(testActivityProcessor)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

Assert.Equal(tracerProvider, testActivityProcessor.ParentProvider);

Activity activity = new Activity(operationNameForLegacyActivity);
activity.Start();
Expand Down Expand Up @@ -736,6 +738,12 @@ public void SdkProcessesLegacyActivityEvenAfterAddingNewProcessor()

tracerProvider.AddProcessor(testActivityProcessorNew);

var sdkProvider = (TracerProviderSdk)tracerProvider;

Assert.True(sdkProvider.Processor is CompositeProcessor<Activity>);
Assert.Equal(tracerProvider, sdkProvider.Processor.ParentProvider);
Assert.Equal(tracerProvider, testActivityProcessorNew.ParentProvider);

Activity activityNew = new Activity(operationNameForLegacyActivity); // Create a new Activity with the same operation name
activityNew.Start();
activityNew.Stop();
Expand Down

0 comments on commit e9e4379

Please sign in to comment.