New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

qs-request-tracker

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qs-request-tracker

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Qs::Request::Tracker

Build Status

Manages a Request-Id for each HTTP request. Hooks transparently into Faraday and service-client to pass request ids on to subsequent calls to other services. This way errors can be tracked through all layers and apps of your infrastructure easily.

Use as a Rack middleware

The easiest way to add request ids to your system is to add the Qs::Request::Tracker::Middleware as a middleware to your app.

require 'qs/request/tracker'

Rack::Builder.new do
  use Qs::Request::Tracker::Middleware
  run YourApp.new
end

This will add the request id to the response. If there is no Request-Id HTTP header set in the request it will also set that. Please note that all middlewares that are included before it will not have that header set!

Use the Faraday middleware

If you are using Faraday you transparently add the request id to all outgoing HTTP calls, too.

require 'faraday'
# make sure to require this middleware after faraday itself
require 'qs/request/tracker/faraday_middleware'

conn = Faraday.new(:url => 'http://example.com') do |faraday|
  # it is important to have the request_id middleware inserted before any Faraday adapter
  faraday.request :request_id
end

All requests done by that connection will now have a Request-Id http header set that equal the one from the request that came into your system. If this is used not within a request context that header will just not get set.

Imporant: This feature relies on thread local variables and will not work if you deal with more than one request per thread at a time!

This approach is inspired by Andy's talk on debugging large scale systems.

Use the service-client extension

This extension will automatically use the Faraday middleware for service-client connections that use the Service::Client::Adapter::Faraday adapter.

require 'service-client'
# make sure to require this extension after service-client itself
require 'qs/request/tracker/service_client_extension'

client = Service::Client.new('http://example.com/')
client.urls.add(:root, :get, "/")
client.get(client.urls.root, oauth_token)

This will then heave the Request-Id http header set through the Faraday middleware.

FAQs

Package last updated on 12 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc