Skip to content

Commit

Permalink
Modify console example to show activityprocessor (#1755)
Browse files Browse the repository at this point in the history
* Modify console example to show activityprocessor

* revert change
  • Loading branch information
cijothomas authored Jan 30, 2021
1 parent 568fbd7 commit d724634
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/Console/TestConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private static object RunWithActivitySource()
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddSource("Samples.SampleClient", "Samples.SampleServer")
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("console-test"))
.AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter
.AddConsoleExporter()
.Build();

Expand All @@ -58,5 +59,27 @@ private static object RunWithActivitySource()

return null;
}

/// <summary>
/// An example of custom processor which
/// can be used to add more tags to an activity.
/// </summary>
internal class MyProcessor : BaseProcessor<Activity>
{
public override void OnStart(Activity activity)
{
if (activity.IsAllDataRequested)
{
if (activity.Kind == ActivityKind.Server)
{
activity.SetTag("customServerTag", "Custom Tag Value for server");
}
else if (activity.Kind == ActivityKind.Client)
{
activity.SetTag("customClientTag", "Custom Tag Value for Client");
}
}
}
}
}
}

0 comments on commit d724634

Please sign in to comment.