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

Refactor TracerProvider to make configuration easy. #1027

Merged
merged 7 commits into from
Aug 9, 2020
Merged

Refactor TracerProvider to make configuration easy. #1027

merged 7 commits into from
Aug 9, 2020

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas commented Aug 8, 2020

Major refactoring in TracerProvider creation, incorporating feedback from #1008, #1008 (comment), and offline feedbacks.

The examples are modified to show the new usage.

Note: This is fairly big change affecting 50 files so want to submit separate PRs for major feedbacks.

For significant contributions please make sure you have completed the following items:

  • Design discussion issue #
  • Changes in public API reviewed

@@ -102,18 +101,6 @@ internal static object Run(ConsoleOptions options)

internal class MyProcessor : ActivityProcessor
{
Copy link
Member Author

Choose a reason for hiding this comment

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

Writing own Processor is also greatly simplified now. No need of worrying about "next".

ActivityProcessor = this.ActivityProcessor,
};

var activitySource = new ActivitySourceAdapter(provider.Sampler, provider.ActivityProcessor, provider.Resource);
Copy link
Member Author

Choose a reason for hiding this comment

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

activitysourceadapter won't fech ActiivtyProcessors added after building the provider. its a TODO on my list.

new string[]
{
"MyCompany.MyProduct.MyLibrary",
})
.AddMyExporter();
.Build().AddMyExporter();
Copy link
Member

Choose a reason for hiding this comment

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

I know you can add exporter after build, but hey 😺

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, for builder, it makes more sense to add everything before Build().

@@ -24,12 +24,13 @@ public class Program

public static void Main()
{
using var tracerProvider = Sdk.CreateTracerProvider(
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddActivitySources(
Copy link
Member

Choose a reason for hiding this comment

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

Trying to get more ideas - which one is more idiomatic? - AddActivitySource overload (singular form) or AddActivitySources (plural form).

Copy link
Contributor

Choose a reason for hiding this comment

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

Should people know that what we did so far is based on Activity? What if in the future it changes to something else? Should we remove the name Activity from it?

Copy link
Member

Choose a reason for hiding this comment

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

I feel like singular but with an overload for plural?

void Add[Activity]Source(this TraceProviderBuilder builder, string sourceName);
void Add[Activity]Source(this TraceProviderBuilder builder, params string[] sourceNames);

@codecov
Copy link

codecov bot commented Aug 8, 2020

Codecov Report

Merging #1027 into master will increase coverage by 1.50%.
The diff coverage is 94.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1027      +/-   ##
==========================================
+ Coverage   75.53%   77.03%   +1.50%     
==========================================
  Files         221      221              
  Lines        6208     6166      -42     
==========================================
+ Hits         4689     4750      +61     
+ Misses       1519     1416     -103     
Impacted Files Coverage Δ
src/OpenTelemetry/Trace/TracerProviderBuilder.cs 93.04% <92.30%> (-1.56%) ⬇️
...Exporter.Jaeger/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...lemetryProtocol/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...Exporter.ZPages/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...Exporter.Zipkin/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...ensions.Hosting/OpenTelemetryServicesExtensions.cs 78.37% <100.00%> (+5.04%) ⬆️
src/OpenTelemetry/Sdk.cs 94.73% <100.00%> (+30.95%) ⬆️
src/OpenTelemetry/Trace/TracerProviderSdk.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/Trace/ActivityProcessor.cs 68.42% <0.00%> (-5.27%) ⬇️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 86.76% <0.00%> (+1.47%) ⬆️
... and 5 more

@cijothomas cijothomas marked this pull request as ready for review August 8, 2020 19:54
@cijothomas cijothomas requested a review from a team August 8, 2020 19:54
new MySampler())
.AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions())));
})
.SetSampler(new MySampler())
Copy link
Member

Choose a reason for hiding this comment

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

"SetSampler" not "UseSampler"?

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:.

// and use a custom MyProcessor, along with Console exporter.
using var tracerProvider = Sdk.CreateTracerProviderBuilder().AddActivitySource("MyCompany.MyProduct.MyWebServer")
.SetResource(Resources.CreateServiceResource("MyServiceName"))
.AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter
Copy link
Member

Choose a reason for hiding this comment

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

What happens if it isn't added before ConsoleExporter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Any enrichments done by MyProcessor will not be visible to ConsoleExporter. Spec says processors are called in order they are added.

@cijothomas cijothomas merged commit 47a6fe7 into open-telemetry:master Aug 9, 2020
@cijothomas cijothomas deleted the cijothomas/refactortracerprovider branch August 9, 2020 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants