Skip to content

Errors in send_stats #259

Open
Open

Description

@aniruddhb

Hey all,

Firstly, thanks for making such a wonderful piece of software. Appreciate it :)

I'm wondering about the error behavior of send_stats in lib/datadog/statsd.rb, which is called by count, distribution, gauge, histogram, set, and timing.

Specifically, I was wondering whether calling this function can result in an error being raised.

I looked at the implementation of send_stats and noticed that it calls some functions that could raise. For example, send_stats calls forwarder.send_message(full_stat), which calls sender.add(message). The implementation of sender.add seems like it could raise the following error.

def add(message)
  raise ArgumentError, 'Start sender first' unless message_queue
  ... continued ...
end

This issue from 2016 seems to indicate that send_stats is safe (i.e. does not raise an error or call any functions that raise errors), but I wanted to re-confirm the answer.

Thanks!

Activity

  1. remeh commented on May 31, 2022

    @remeh
    Contributor

    Hi @aniruddhb,

    You are right that following the code path it looks like it has changed recently (since 5.0.0 I think). How much of this is an issue to you? Do you think that adding this information to methods documentation would be enough?

    If this is an issue to you right now, you can use the single thread sender implementation (using single_thread: true on statsd constructor) which should never raise an error while using count, gauge and others.

  2. aniruddhb commented on Jun 1, 2022

    @aniruddhb
    Author

    Hi @remeh

    Firstly, thanks for the response. I appreciate your help :)

    I don't think its too much of an issue. I am working around it by rescuing errors on the caller side. I was mainly curious whether I could remove this layer of rescuing around the caller or not.

    When I get some free time this week, I'll raise a PR to add this information to the method documentation.

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions