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

Optimize the flow #1032

Closed
wants to merge 1 commit into from
Closed

Optimize the flow #1032

wants to merge 1 commit into from

Conversation

reyang
Copy link
Member

@reyang reyang commented Aug 10, 2020

Changes

  • Allow setting sampler as null to bypass the entire sampling logic.
  • Move majority of the logic to the TracerProviderSdk class, builder will only validate the input and call Build() (partially done).
  • Renamed AddActivitySources.
  • Added regex support, superseded Add support for regex #1023.

Please provide a brief description of the changes here. Update the
CHANGELOG.md for non-trivial changes.

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

  • Design discussion issue #
  • Changes in public API reviewed

@reyang reyang requested a review from a team August 10, 2020 17:11

if (this.InstrumentationFactories != null)
{
foreach (var instrumentation in this.InstrumentationFactories)
{
provider.Instrumentations.Add(instrumentation.Factory(activitySource));
this.instrumentations.Add(instrumentation.Factory(adapter));
Copy link
Member

Choose a reason for hiding this comment

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

give it to the provider, let it deal with 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 made this change in #1035

@reyang reyang mentioned this pull request Aug 10, 2020
@@ -47,7 +48,7 @@ internal TracerProviderBuilder()
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public TracerProviderBuilder SetSampler(Sampler sampler)
{
this.Sampler = sampler ?? throw new ArgumentNullException(nameof(sampler));
this.sampler = sampler;
Copy link
Member

Choose a reason for hiding this comment

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

Double-checking, we want to allow users to set sampler to null?

Copy link
Member Author

Choose a reason for hiding this comment

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

At least for now as we're seeing big memory allocation/perf difference here.

With sampler == null, allocation is 656 bytes.
With sampler != null, allocation is 1248 bytes.

Once we solved the allocation issue in sampler, we can explore if we want to add the validation back (and remove all the sampler? logic from the SDK).

Copy link
Member

Choose a reason for hiding this comment

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

yes.

if (this.ActivitySourceNames == null)
{
this.ActivitySourceNames = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
public TracerProviderBuilder AddActivitySource(IEnumerable<string> names)
Copy link
Member

Choose a reason for hiding this comment

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

Advantages/disadvantages to make this:

public TracerProviderBuilder AddActivitySource(params string[] names)

I guess one disadvantage would be that the use of .ToArray() may be required.

Copy link
Member Author

Choose a reason for hiding this comment

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

@CodeBlanch mentioned it here.
This is a micro-improvement (together with AddActivitySource vs. AddSource) that can be addressed in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

It's too bad C# doesn't let us do params IEnumerable<string> eh? Personally in this case I would do params string[] because this is initialization code. I feel like users will prefer the convenience and it's unlikely they'll have an IEnumerable<string> from some other source in the init phase they'll want to pass us. The 99% case is it's a fixed list set during init. In more general APIs, probably the IEnumerable<string> is better.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes, I thought I had seen this suggestion, and thinking "yea, I like this" 😄. Agreed separate PR makes sense, and also agreed the context of this being initialization code makes params seem natural here.

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

@cijothomas
Copy link
Member

#1035 supercedes this as it already was branched off of this branch from Reiley.

@cijothomas cijothomas closed this Aug 10, 2020
@reyang reyang deleted the reyang/optimize branch August 10, 2020 19:56
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.

4 participants