Update the custom processor project (#996)
* update the processor project * simply code Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
parent
79acec1bc6
commit
fd0cc21b39
|
|
@ -22,29 +22,37 @@ using OpenTelemetry.Trace;
|
|||
|
||||
internal class MyActivityProcessor : ActivityProcessor
|
||||
{
|
||||
public MyActivityProcessor()
|
||||
private readonly string name;
|
||||
|
||||
public MyActivityProcessor(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.GetType()}({this.name})";
|
||||
}
|
||||
|
||||
public override void OnStart(Activity activity)
|
||||
{
|
||||
Console.WriteLine($"{this.GetType()} OnStart");
|
||||
Console.WriteLine($"{this}.OnStart");
|
||||
}
|
||||
|
||||
public override void OnEnd(Activity activity)
|
||||
{
|
||||
Console.WriteLine($"{this.GetType()} OnEnd");
|
||||
Console.WriteLine($"{this}.OnEnd");
|
||||
}
|
||||
|
||||
public override Task ForceFlushAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Console.WriteLine($"{this.GetType()} ForceFlushAsync");
|
||||
Console.WriteLine($"{this}.ForceFlushAsync");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task ShutdownAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Console.WriteLine($"{this.GetType()} ShutdownAsync");
|
||||
Console.WriteLine($"{this}.ShutdownAsync");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,12 @@ public class Program
|
|||
{
|
||||
using var otel = Sdk.CreateTracerProvider(b => b
|
||||
.AddActivitySource("MyCompany.MyProduct.MyLibrary")
|
||||
.AddProcessorPipeline(pipeline =>
|
||||
{
|
||||
pipeline.AddProcessor(current => new MyActivityProcessor());
|
||||
}));
|
||||
|
||||
// TODO: seems buggy if you remove A and B here, MyActivityProcessor(C).OnEnd is not called.
|
||||
// TODO: should the dispose order be C, B, A or A, B C?
|
||||
.AddProcessorPipeline(p => p.AddProcessor(current => new MyActivityProcessor("A")))
|
||||
.AddProcessorPipeline(p => p.AddProcessor(current => new MyActivityProcessor("B")))
|
||||
.AddProcessorPipeline(p => p.AddProcessor(current => new MyActivityProcessor("C"))));
|
||||
|
||||
using (var activity = MyActivitySource.StartActivity("SayHello"))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue