-
Notifications
You must be signed in to change notification settings - Fork 147
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
Conversation
@@ -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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 evenenable/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 likeYesterday
orTomorrow
. - Regarding
-1
, AFAIK the general rule is that0
meansfalse
and any non-zero value meanstrue
. (not to be confused with return codes where0
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 ofif/else
withStringComparison
. I imagine that usingToUpperInvariant()
once and making several case-sensitive comparisons is also slightly faster.
else | ||
|
||
// some tags have special meaning | ||
switch (key) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added recently in C# 7.3.
6df908e
to
ce491a0
Compare
# Conflicts: # src/Datadog.Trace/Datadog.Trace.csproj
f3a5ea6
to
5468578
Compare
# Conflicts: # src/Datadog.Trace/Datadog.Trace.csproj
Allow users to override a trace's sampling priority by setting span tags.
Updates #214.