epsagon 0.0.4 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8562e3fae0593320be07b191b3c23951bbdb6ee6483a766edfe44459c9e52d67
4
- data.tar.gz: 20b587b39248f027a56540b4ca438297025330f6b7587939a8332a362d823af3
3
+ metadata.gz: bbcd3ad1c94c24be608924993e0c0c6fc0455982b51f66a61e159fce8713e607
4
+ data.tar.gz: 005d41bf64026ec6918eeaa9d99a77ee8e108b8d1574391494604eb99dd76733
5
5
  SHA512:
6
- metadata.gz: 324f5a094aef1e98a4786978c3320763d9a3bab63d49967d3c3ac274141e729bb1fdf7293d3c8b7bb3785dff6a0bf29b2ccaaa25fcb4229106c0b514666d1851
7
- data.tar.gz: 51df59c2af4f2f8811d7cd57738aef836f35f05069cbca9f728a05b8dbd615fab80fce91d3f608da16265f50332ea86211c535f8e6a63c38f5d79337b7decc39
6
+ metadata.gz: ad16af491cc509358edfc44dda23c838604a33beb6d6ad25d84b183bc0e0d4f4e12f9991a92fa91d54b10f2fb0dc2ebb33f4bf75244b54a0848bc3a584915d41
7
+ data.tar.gz: 143981531b488487e9bd13bcf58d412a02a1efcd53cdff9548a4157c49041eb5305796016d941fb5e0e3446e914106aca56b94303803b99fd96d85d01d586a27
data/lib/epsagon.rb CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'rubygems'
4
4
  require 'net/http'
5
5
  require 'bundler/setup'
6
- require 'opentelemetry-sdk'
7
- require 'opentelemetry-api'
6
+ require 'opentelemetry/sdk'
7
+ require 'opentelemetry/exporter/otlp'
8
8
 
9
9
  require_relative 'instrumentation/sinatra'
10
10
  require_relative 'instrumentation/net_http'
@@ -0,0 +1,74 @@
1
+
2
+ require_relative '../util'
3
+ require 'faraday'
4
+
5
+ # Faraday middleware for epsagon instrumentaton
6
+ class EpsagonFaradayMiddleware < ::Faraday::Middleware
7
+ def config
8
+ EpsagonFaradayInstrumentation.instance.config
9
+ end
10
+
11
+ HTTP_METHODS_SYMBOL_TO_STRING = {
12
+ connect: 'CONNECT',
13
+ delete: 'DELETE',
14
+ get: 'GET',
15
+ head: 'HEAD',
16
+ options: 'OPTIONS',
17
+ patch: 'PATCH',
18
+ post: 'POST',
19
+ put: 'PUT',
20
+ trace: 'TRACE'
21
+ }.freeze
22
+
23
+ def call(env)
24
+ http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
25
+ path, path_params = env.url.path.split(';')
26
+
27
+ attributes = {
28
+ 'type' => 'http',
29
+ 'operation' => http_method,
30
+ 'http.scheme' => env.url.scheme,
31
+ 'http.request.path' => path
32
+ }
33
+
34
+ unless config[:epsagon][:metadata_only]
35
+ attributes.merge!(Util.epsagon_query_attributes(env.url.query))
36
+ attributes.merge!({
37
+ 'http.request.path_params' => path_params,
38
+ 'http.request.headers' => env.request_headers.to_json,
39
+ 'http.request.body' => env.body,
40
+ 'http.request.headers.User-Agent' => env.request_headers['User-Agent']
41
+ })
42
+ end
43
+
44
+ tracer.in_span(
45
+ env.url.host,
46
+ attributes: attributes,
47
+ kind: :client
48
+ ) do |span|
49
+ OpenTelemetry.propagation.http.inject(env.request_headers)
50
+
51
+ app.call(env).on_complete { |req| trace_response(span, req.response) }
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ attr_reader :app
58
+
59
+ def tracer
60
+ EpsagonFaradayInstrumentation.instance.tracer
61
+ end
62
+
63
+ def trace_response(span, response)
64
+ span.set_attribute('http.status_code', response.status)
65
+
66
+ unless config[:epsagon][:metadata_only]
67
+ span.set_attribute('http.response.headers', response.headers.to_json)
68
+ span.set_attribute('http.response.body', response.body)
69
+ end
70
+ span.status = OpenTelemetry::Trace::Status.http_to_status(
71
+ response.status
72
+ )
73
+ end
74
+ end
@@ -1,79 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'faraday'
4
- require_relative '../util'
5
-
6
- # Faraday middleware for epsagon instrumentaton
7
- class EpsagonFaradayMiddleware < ::Faraday::Middleware
8
- def config
9
- EpsagonFaradayInstrumentation.instance.config
10
- end
11
-
12
- HTTP_METHODS_SYMBOL_TO_STRING = {
13
- connect: 'CONNECT',
14
- delete: 'DELETE',
15
- get: 'GET',
16
- head: 'HEAD',
17
- options: 'OPTIONS',
18
- patch: 'PATCH',
19
- post: 'POST',
20
- put: 'PUT',
21
- trace: 'TRACE'
22
- }.freeze
23
-
24
- def call(env)
25
- http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
26
- path, path_params = env.url.path.split(';')
27
-
28
- attributes = {
29
- 'type' => 'http',
30
- 'operation' => http_method,
31
- 'http.scheme' => env.url.scheme,
32
- 'http.request.path' => path
33
- }
34
-
35
- unless config[:epsagon][:metadata_only]
36
- attributes.merge!(Util.epsagon_query_attributes(env.url.query))
37
- attributes.merge!({
38
- 'http.request.path_params' => path_params,
39
- 'http.request.headers' => env.request_headers.to_json,
40
- 'http.request.body' => env.body,
41
- 'http.request.headers.User-Agent' => env.request_headers['User-Agent']
42
- })
43
- end
44
-
45
- tracer.in_span(
46
- env.url.host,
47
- attributes: attributes,
48
- kind: :client
49
- ) do |span|
50
- OpenTelemetry.propagation.http.inject(env.request_headers)
51
-
52
- app.call(env).on_complete { |req| trace_response(span, req.response) }
53
- end
54
- end
55
-
56
- private
57
-
58
- attr_reader :app
59
-
60
- def tracer
61
- EpsagonFaradayInstrumentation.instance.tracer
62
- end
63
-
64
- def trace_response(span, response)
65
- span.set_attribute('http.status_code', response.status)
66
-
67
- unless config[:epsagon][:metadata_only]
68
- span.set_attribute('http.response.headers', response.headers.to_json)
69
- span.set_attribute('http.response.body', response.body)
70
- end
71
- span.status = OpenTelemetry::Trace::Status.http_to_status(
72
- response.status
73
- )
74
- end
75
- end
76
-
77
2
  # Patch faraday to include middleware
78
3
  module EpsagonFaradayPatch
79
4
  def adapter(*args)
@@ -90,6 +15,7 @@ class EpsagonFaradayInstrumentation < OpenTelemetry::Instrumentation::Base
90
15
  VERSION = '0.0.0'
91
16
 
92
17
  install do |_config|
18
+ require_relative 'epsagon_faraday_middleware'
93
19
  ::Faraday::Middleware.register_middleware(
94
20
  epsagon_open_telemetry: EpsagonFaradayMiddleware
95
21
  )
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sinatra'
4
3
  require 'opentelemetry'
5
4
 
6
5
  require_relative '../util'
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epsagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Epsagon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opentelemetry-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.11.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.11.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: opentelemetry-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.11.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.11.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: opentelemetry-instrumentation-sinatra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.11.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: opentelemetry-exporter-otlp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.0
13
69
  description: 'Epsagon provides tracing to Ruby applications for the collection of
14
70
  distributed tracing and performance metrics to simplify complex architectures, eliminate
15
71
  manual work, visualize and correlate data to identify and fix problems fast.
@@ -21,8 +77,8 @@ extensions: []
21
77
  extra_rdoc_files: []
22
78
  files:
23
79
  - lib/epsagon.rb
24
- - lib/epsagon_opentelemetry.rb
25
80
  - lib/instrumentation/aws_sdk.rb
81
+ - lib/instrumentation/epsagon_faraday_middleware.rb
26
82
  - lib/instrumentation/faraday.rb
27
83
  - lib/instrumentation/net_http.rb
28
84
  - lib/instrumentation/sinatra.rb
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems'
4
- require 'net/http'
5
- require 'bundler/setup'
6
- require 'opentelemetry'
7
-
8
- require_relative 'instrumentation/sinatra'
9
- require_relative 'instrumentation/net_http'
10
- require_relative 'instrumentation/faraday'
11
- require_relative 'util'
12
-
13
- Bundler.require
14
-
15
- def metadata_only?
16
- ENV['EPSAGON_METADATA']&.to_s&.downcase != 'false'
17
- end
18
-
19
- def debug?
20
- ENV['EPSAGON_DEBUG']&.to_s&.downcase == 'true'
21
- end
22
-
23
- # #config opentelemetry with epsaon extensions:
24
- OpenTelemetry::SDK.configure do |c|
25
- c.use 'EpsagonSinatraInstrumentation'
26
- c.use 'EpsagonNetHTTPInstrumentation'
27
- c.use 'EpsagonFaradayInstrumentation'
28
- if debug?
29
- c.add_span_processor OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
30
- OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new
31
- )
32
- else
33
- c.add_span_processor OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
34
- EpsagonExporter.new(headers: {
35
- epasgon_token: ENV['EPSAGON_TOKEN'],
36
- epasgon_app_name: ENV['EPSAGON_APP_NAME']
37
- },
38
- endpoint: '7fybd5lgpc.execute-api.us-east-2.amazonaws.com:443/dev/trace',
39
- insecure: false)
40
- )
41
- end
42
- end