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

Two wishes: Send only some requests & Easier Rails invocation #351

Open
sandstrom opened this issue Jan 5, 2022 · 3 comments
Open

Two wishes: Send only some requests & Easier Rails invocation #351

sandstrom opened this issue Jan 5, 2022 · 3 comments
Assignees
Labels
ruby Issues related to our Ruby SDK

Comments

@sandstrom
Copy link

sandstrom commented Jan 5, 2022

Skipping requests

We'd like to skip requests on a per-request basis. Basically, only requests from our customers sandbox accounts should be sent, for privacy reasons.

If we could return false from the block, or send e.g. { :ignore => true } that would be great.

config.middleware.use Readme::Metrics, options do |env|
  current_user = env['warden'].authenticate

  if current_user && current_user.sandbox?
    {
      api_key: current_user.api_key,
    }
  else
    false # or { :ignore => true }
  end
end

Easier Rails Integration

We have a bunch of logic in our Rails ApplicationController, that will run authentication, etc. We'll lookup the company based on the API key, and only after we've checked which account it is, do we know if we want to sent this to Readme.

More specifically, we only want to send Metrics for certain sandbox accounts (for privacy and contractual reasons we cannot send any production data).

With the middleware approach this gets complicated.

We'd rather do something like this:

class ApplicationController < ActionController::Base

  # our actual controller contains more code, this is a simplified example

  before_action :run_auth
  before_action :send_to_readme

  def run_auth
    # …
  end

  def send_to_readme
    if current_company.sandbox? && request_type == 'api'
      Readme::Metrics.send(request, api_key: current_api_key)
    end
  end

end

This would also solve the first item, sending only some requests, since in this example sending a request is opt-in.

@sandstrom sandstrom changed the title Two wishes (send only some requests & easier invocation from Rails) Two wishes: Send only some requests & Easier Rails invocation Jan 5, 2022
@Dashron
Copy link
Contributor

Dashron commented Jan 5, 2022

Hi @sandstrom,

We've been working on improving our metrics SDKs and are going to slip the first request into the upcoming update. I think it's a great idea.

The second request, a direct API call without middleware, is one we will eventually be adding to all of our SDKs. We've already added it to the node sdk but I don't have a timeline on when we'll get to it for the ruby sdk.

Let me know if this unblocks you, or if the second request is necessary to move forward.

ilias-t pushed a commit that referenced this issue Jan 5, 2022
@sandstrom
Copy link
Author

@Dashron Thanks for a quick reply!

We'll probably wait for the direct call. But great to know that it's on the horizon!

Hopefully there will still be the batching + some mechanism such that failed submission of metrics won't interfere with the ruby process in any way. Always an important thing with stuff running in-memory like this.

In case it's helpful, the Ruby tracing product Skylight has a gem which does something similar to you. They send trace data for basically every request (they are not a competitor, but their product is very similar in that it will ingest request data from running Ruby applications).

Maybe their gem has something interesting that could be of use to you:
https://github.com/skylightio/skylight-ruby

@ilias-t ilias-t mentioned this issue Jan 5, 2022
5 tasks
@Dashron
Copy link
Contributor

Dashron commented Jan 6, 2022

Thanks for the tip, we'll keep it in mind!

ilias-t pushed a commit that referenced this issue Jan 6, 2022
* fix: add platform and version to log creator comment

* feat: respect forwarded headers on incoming requests

* feat: accept more json mime types and better handle form_urlencoded bodies

* feat: allow custom uuid to be set; otherwise, generate one

* docs: update docs

* fix: update validation logic to make input options less strict

* feat: support an ignore option #351
@erunion erunion added ruby Issues related to our Ruby SDK and removed area:ruby labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Issues related to our Ruby SDK
Projects
None yet
Development

No branches or pull requests

4 participants