faraday-aws-xray 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ebb77f5272e90edc60a5d0845c4f1b0ca43ec2b190083f017947c45ed898b2fa
4
+ data.tar.gz: 2021b7a4e9302c4f63d8cef8ecb0e5efeecd55b4fe85f3b767cf68b4e48adc5a
5
+ SHA512:
6
+ metadata.gz: b44716e1b2e184167a4d3f80b1a6a2c9a34eb5f8f16ee8cdc4b330efd9385b0f33e311f61332dba4f8c57c8ce15617a24c385c8c4cc5ed6cb453bae29faca5ca
7
+ data.tar.gz: 65a1744144bc36b8f18276a09868d776b5a6a8653012cdd6254933f27587fffa921568ee1bc63081db5be4f8e92f6189aa08ce865eb8e1154238b73db6ed6b5a
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ * Initial release.
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Jay Zeschin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Faraday AWS X-Ray Middleware
2
+
3
+ [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/jayzes/faraday-aws-xray/ci)](https://github.com/jayzes/faraday-aws-xray/actions?query=branch%3Amain)
4
+ [![Gem](https://img.shields.io/gem/v/faraday-aws-xray.svg?style=flat-square)](https://rubygems.org/gems/faraday-aws-xray)
5
+ [![License](https://img.shields.io/github/license/jayzes/faraday-aws-xray.svg?style=flat-square)](LICENSE.md)
6
+
7
+ Faraday 2+ middleware to instrument spans for [AWS X-Ray](https://aws.amazon.com/xray/).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'faraday-aws-xray'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```shell
20
+ bundle install
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```shell
26
+ gem install faraday-aws-xray
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ require 'faraday/aws/xray'
33
+ ```
34
+
35
+ Then wherever you configure your Faraday connection, add the middleware:
36
+
37
+ ```ruby
38
+ Faraday.new(...) do |conn|
39
+ conn.use Faraday::Aws::XRay::Middleware
40
+ end
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies.
46
+
47
+ Then, run `bin/test` to run the tests.
48
+
49
+ To install this gem onto your local machine, run `rake build`.
50
+
51
+ To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run `rake release`.
52
+ See how it works [here](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/ajayzes/faraday-aws-xray/faraday-aws-xray).
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module Aws
5
+ module XRay
6
+ class Middleware < Faraday::Middleware
7
+ def initialize(app, options = {})
8
+ super(app)
9
+ @name = options[:name] || 'external_http_request'
10
+ end
11
+
12
+ def call(env)
13
+ ::XRay.recorder.capture(@name) do |_segment|
14
+ ::XRay.recorder.capture(env.url.to_s) do |subsegment|
15
+ add_request_data(subsegment, env)
16
+
17
+ response = @app.call(env)
18
+
19
+ add_response_data(subsegment, response)
20
+ response
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def add_request_data(subsegment, env)
28
+ subsegment.merge_http_request(
29
+ request: {
30
+ method: env.method.to_s.upcase,
31
+ url: env.url.to_s,
32
+ user_agent: env.request_headers['User-Agent']
33
+ }
34
+ )
35
+ end
36
+
37
+ def add_response_data(subsegment, response)
38
+ subsegment.merge_http_response(
39
+ response: {
40
+ status: response.status,
41
+ content_length: response.headers['Content-Length']
42
+ }
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module Aws
5
+ module XRay
6
+ VERSION = '0.1.0'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-xray-sdk'
4
+ require_relative 'xray/middleware'
5
+ require_relative 'xray/version'
6
+
7
+ module Faraday
8
+ # This will be your middleware main module, though the actual middleware implementation will go
9
+ # into Faraday::Aws::Xray::Middleware for the correct namespacing.
10
+ module Aws
11
+ module XRay
12
+ # Faraday allows you to register your middleware for easier configuration.
13
+ # This step is totally optional, but it basically allows users to use a
14
+ # custom symbol (in this case, `:xray`), to use your middleware in their connections.
15
+ # After calling this line, the following are both valid ways to set the middleware in a connection:
16
+ # * conn.use Faraday::Aws::Xray::Middleware
17
+ # * conn.use :xray
18
+ # Without this line, only the former method is valid.
19
+ Faraday::Middleware.register_middleware(xray: Faraday::Aws::XRay::Middleware)
20
+
21
+ # Alternatively, you can register your middleware under Faraday::Request or Faraday::Response.
22
+ # This will allow to load your middleware using the `request` or `response` methods respectively.
23
+ #
24
+ # Load middleware with conn.request :xray
25
+ # Faraday::Request.register_middleware(xray: Faraday::Aws::Xray::Middleware)
26
+ #
27
+ # Load middleware with conn.response :xray
28
+ # Faraday::Response.register_middleware(xray: Faraday::Aws::Xray::Middleware)
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-aws-xray
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jay Zeschin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-xray-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2.9'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '2.9'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
47
+ description: 'Faraday middleware to instrument spans for AWS X-Ray.
48
+
49
+ '
50
+ email:
51
+ - jay@zeschin.org
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - CHANGELOG.md
57
+ - LICENSE.md
58
+ - README.md
59
+ - lib/faraday/aws/xray.rb
60
+ - lib/faraday/aws/xray/middleware.rb
61
+ - lib/faraday/aws/xray/version.rb
62
+ homepage: https://github.com/ajayzes/faraday-aws-xray/faraday-aws-xray
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ bug_tracker_uri: https://github.com/ajayzes/faraday-aws-xray/faraday-aws-xray/issues
67
+ changelog_uri: https://github.com/ajayzes/faraday-aws-xray/faraday-aws-xray/blob/v0.1.0/CHANGELOG.md
68
+ documentation_uri: http://www.rubydoc.info/gems/faraday-aws-xray/0.1.0
69
+ homepage_uri: https://github.com/ajayzes/faraday-aws-xray/faraday-aws-xray
70
+ rubygems_mfa_required: 'true'
71
+ source_code_uri: https://github.com/ajayzes/faraday-aws-xray/faraday-aws-xray
72
+ wiki_uri: https://github.com/ajayzes/faraday-aws-xray/faraday-aws-xray/wiki
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ - - "<"
83
+ - !ruby/object:Gem::Version
84
+ version: '4'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.4.10
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Faraday middleware to instrument spans for AWS X-Ray
95
+ test_files: []