Skip to content

allow users to set sampling priority #284

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

Merged
merged 6 commits into from
Apr 4, 2019

Conversation

lucaspimentel
Copy link
Member

@lucaspimentel lucaspimentel commented Mar 14, 2019

Allow users to override a trace's sampling priority by setting span tags.

Updates #214.

@lucaspimentel lucaspimentel added this to the vNext milestone Mar 14, 2019
@lucaspimentel lucaspimentel self-assigned this Mar 14, 2019
@lucaspimentel lucaspimentel marked this pull request as ready for review March 14, 2019 15:02
@lucaspimentel lucaspimentel requested a review from a team as a code owner March 14, 2019 15:02
@lucaspimentel lucaspimentel added the status:do-not-merge Work is done. Can review, but do not merge yet. label Mar 14, 2019
@lucaspimentel lucaspimentel modified the milestones: vNext, 0.10.0-beta, 0.9.0-beta Mar 20, 2019
@@ -8,7 +8,7 @@
<Title>Datadog APM</Title>
<Description>Manual instrumentation library for Datadog APM</Description>
<Authors>lucas.pimentel.datadog;bmermet</Authors>
<LangVersion>7.1</LangVersion>
<LangVersion>7.3</LangVersion>
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this intentional? I don't really care much, but I seem to recall something about not using latest vs. specific versions

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I was interested in using the Enum generic type constraint. I was going to go without, but noticed that Datadog.Trace.ClrProfiler.Managed was already at 7.3, anyway.

{
if (value == null) { throw new ArgumentNullException(nameof(value)); }

switch (value.ToUpperInvariant())
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure where this is used, so this may just be nothing to worry about, and if so just ignore the rest, I'm assuming I'll find out later in this PR.

In the past I've also done something like this and ran into cases including "Y", "N", "T", "F", any non-1 numeric value to indicate false (-1 is popular it seems)....there are also cases with FLAG like cases (i.e. command line args that are implicitly true/false just by being present or not) where a value of "" or whitespace could/should be implied to be true vs. the default of false...again, entirely dependent on where it's used I suppose.

If it's only for our internal use, not a big deal, if it's for trying to cover those, might want to reconsider a logic flow that accounts for these in as performant a way as possible.

I'd also favor just a string comparison strategy over ToUpperInvariant-ing the source, which would be difficult to do in a switch format.

Something that in order does:

  • source.StartsWith("t", StringComparison.OrdinalIgnoreCase) (or source[0] == 't' || source[0] == 'T')
  • source.StartsWith("f", StringComparison.OrdinalIgnoreCase) ...
  • Same for y/n
  • Maybe next check if it is a known 1/0/-1 common value
  • Then convert to int and compare vs. 0

Copy link
Member Author

Choose a reason for hiding this comment

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

This extension method is internal only. I'm using it to convert tags values like span.SetSpan("force.keep", "true") because Span.SetSpan() only allows string values. (Strongly-typed tags is something I would like to revisit later, but we need to support the OpenTracing convention regardless.) In the future, I plan to use the extension method to convert settings from string-typed sources like environment variables. In all cases, there will be only one correct documented value, but I wanted to give users a little margin for error by allowing more values aside from true/false when their intent is obvious. It is not meant to be exhaustive.

  • I thought about allowing Y/N, T/F, and even enable/disable, but we have to draw the line somewhere. Once they are out there and people are using them, it will be harder to change or remove without breaking existing code.
  • We shouldn't use StartsWith() because that would allow clearly invalid values like Yesterday or Tomorrow.
  • Regarding -1, AFAIK the general rule is that 0 means false and any non-zero value means true. (not to be confused with return codes where 0 means success and non-zero values are error codes)
  • The switch is effectively doing ordinal comparisons ignoring case, and in this case is much easier to read and maintain than a chain of if/else with StringComparison. I imagine that using ToUpperInvariant() once and making several case-sensitive comparisons is also slightly faster.

else

// some tags have special meaning
switch (key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar feedback here as to other PRs - we seem to just really want to keep piling the logic/responsibilities inside a single class (Span in this case) when the responsibility here is external, and could easily be separated away. I would particularly at this point start pulling this stuff out into an external tagging service(s) that handle this....also starts/moves us down a path towards making a span a dumb dto that is managed by a external composable things....

@@ -91,22 +91,25 @@ private static ulong ParseUInt64(IHeadersCollection headers, string headerName)
}

private static T? ParseEnum<T>(IHeadersCollection headers, string headerName)
where T : struct
where T : struct, Enum
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, look at that, I wasn't aware you could constrain a type by Enum

Copy link
Member Author

@lucaspimentel lucaspimentel Mar 26, 2019

Choose a reason for hiding this comment

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

@lucaspimentel lucaspimentel changed the base branch from develop to release/v0.9.0-beta March 28, 2019 12:42
@lucaspimentel lucaspimentel changed the base branch from release/v0.9.0-beta to develop March 28, 2019 14:52
@lucaspimentel lucaspimentel requested a review from a team April 4, 2019 20:13
@lucaspimentel lucaspimentel force-pushed the lpimentel/set-sampling-priority-tag branch from f3a5ea6 to 5468578 Compare April 4, 2019 20:43
@lucaspimentel lucaspimentel removed the status:do-not-merge Work is done. Can review, but do not merge yet. label Apr 4, 2019
# Conflicts:
#	src/Datadog.Trace/Datadog.Trace.csproj
@lucaspimentel lucaspimentel merged commit 9c463f8 into develop Apr 4, 2019
@lucaspimentel lucaspimentel deleted the lpimentel/set-sampling-priority-tag branch April 4, 2019 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants