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

implement client sampling #74

Merged
merged 1 commit into from
Mar 6, 2017
Merged

implement client sampling #74

merged 1 commit into from
Mar 6, 2017

Conversation

galdor
Copy link
Contributor

@galdor galdor commented Feb 8, 2017

No description provided.

@galdor galdor force-pushed the nicolas/client-sampling branch 2 times, most recently from 91f4c20 to 778821f Compare February 8, 2017 17:04
@palazzem palazzem self-assigned this Mar 1, 2017
@palazzem palazzem added core Involves Datadog core libraries enhancement labels Mar 1, 2017
Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

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

Something that we should address before the merge.

module Datadog
# \Sampler performs client-side trace sampling.
class Sampler
def sample(span); end
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this class as a kind of interface? I assume users can do Datadog::Sampler.new().sample(span) (which is wrong) so I think it should raise an error like:

class Sampler
  def sample(span);
    raise 'You have to implement this method' # or whatever
  end
end

Obviously if it's Ruby-idiomatic.

# sampled.
def initialize(sample_rate = 1.0)
unless sample_rate > 0.0 && sample_rate <= 1.0
raise ArgumentError,
Copy link
Contributor

Choose a reason for hiding this comment

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

this exception is handled somewhere? does it crash users code? an alternative is to ignore the sample_rate value, disabling the Sampler and logging the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I already explained, raising an exception is not a crash. ArgumentError exceptions are designed very precisely for this kind of problem. Logging errors and disabling the sampler is very bad because people miss errors, and then believe the code works as they intended to... even though it does not. If they use an invalid sample rate, the code will raise an exception, which they won't be able to miss, and they will be able to fix it before going to prod. In C you would use an assertion, with the exact same purpose.

Copy link
Contributor

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

While I agree with raising an error in the context of an important/business piece of code, we should shoot for something more conservative as an monitoring/instrumentation lib.

The same way as we don't raise exceptions if the Agent endpoint is wrong, if one does something wrong with a span, ... we should behave as a 0-footprint best-effort lib.

And in general, as a user I'd be worried if my APM solution can break my app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@metrics[key] = value
end

# Return the metric wth the given key, nil if it doesn't exist.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: with

@@ -40,9 +40,11 @@ def initialize(tracer, name, options = {})
@trace_id = options.fetch(:trace_id, @span_id)

@meta = {}
@metrics = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

That was missing so good to have it!

In that case you should update all our tests so that we have both unittests and integration tests with a real agent. We should check also what happens if we put strings, nil values, integers, etc...

@palazzem
Copy link
Contributor

palazzem commented Mar 6, 2017

Tests will be part of another PR, merging in the meantime.

@palazzem palazzem merged commit e8154e3 into master Mar 6, 2017
@palazzem palazzem deleted the nicolas/client-sampling branch March 6, 2017 11:11
@palazzem palazzem modified the milestone: 0.5.0 Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants