Skip to content

Commit

Permalink
Update the custom processor project (#996)
Browse files Browse the repository at this point in the history
* update the processor project

* simply code

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
  • Loading branch information
reyang and cijothomas committed Aug 5, 2020
1 parent 79acec1 commit fd0cc21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 13 additions & 5 deletions docs/trace/building-your-own-processor/MyActivityProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,37 @@

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;
}
}
10 changes: 6 additions & 4 deletions docs/trace/building-your-own-processor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public static void Main()
{
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"))
{
Expand Down

0 comments on commit fd0cc21

Please sign in to comment.