Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the custom processor project #996

Merged
merged 8 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to take the next ActivityProcessor, and call its corresponding methods in Start/End/etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For demonstration I was trying to make it simple by not chaining the processors at all.

{
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")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adding multiple processor pipelines. I guess you wanted to add multiple processors to the same, single pipeline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I was using this to showcase how pipeline could be confusing, and I think we need to change it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fan out scenario is a separate topic, and the name should be changed #979.

.AddProcessorPipeline(p => p.AddProcessor(current => new MyActivityProcessor("B")))
.AddProcessorPipeline(p => p.AddProcessor(current => new MyActivityProcessor("C"))));

using (var activity = MyActivitySource.StartActivity("SayHello"))
{
Expand Down