epsagon 0.0.3 → 0.0.8

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: 282076e11b814e7a0dcc8daef8beb8abd248553865e170743b0b838712686b54
4
- data.tar.gz: d611c7033a0d976288c5beb2c9d1617a3ffd368d126ab80ee357180f848ebe15
3
+ metadata.gz: a7b3206724c319044ec03107de40ed46798b935d85e6aba2a5cadadfe777e86c
4
+ data.tar.gz: cd515cf0bcd75faba2d3153f456c44441fa9df5e511f7a8b4aea5dc95178a3c1
5
5
  SHA512:
6
- metadata.gz: eb7f4a38dff50370948001c5f37409402c3ea82840b159dd3c12cb6145a56274f40f85d6fd8560b019843e804a71d99ad40c84ed070246d7709970e2f826bcc3
7
- data.tar.gz: eea173e740ca5a0e82bb6ffcdaab64d102399669f5310691c7b61c785f53f55001c011b6ccb48993bdb482a7297f27ef93541f3080ee3f6c8974138c68339b6a
6
+ metadata.gz: fa0bc9dcc5710f2498a9c39f3d86ebc43ed825b4fa23a8532457a6770ed9834de2ca2fab3e37c7324902ac38f0f426ea0de0ca2f1272a73c56ad35ff7afe1458
7
+ data.tar.gz: 00b78e433d7cfea98710f6f641123727a3b44edcfab51da0039363c1db135401166ea4d35f2d4e935f54d78de1434130ea33b092e83cd85d1ba56d3bead9e847
data/lib/epsagon.rb CHANGED
@@ -3,7 +3,8 @@
3
3
  require 'rubygems'
4
4
  require 'net/http'
5
5
  require 'bundler/setup'
6
- require 'opentelemetry'
6
+ require 'opentelemetry/sdk'
7
+ require 'opentelemetry/exporter/otlp'
7
8
 
8
9
  require_relative 'instrumentation/sinatra'
9
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,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epsagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.8
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: sinatra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: opentelemetry-instrumentation-sinatra
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
69
+ - !ruby/object:Gem::Dependency
70
+ name: opentelemetry-exporter-otlp
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
13
97
  description: 'Epsagon provides tracing to Ruby applications for the collection of
14
98
  distributed tracing and performance metrics to simplify complex architectures, eliminate
15
99
  manual work, visualize and correlate data to identify and fix problems fast.
@@ -21,8 +105,8 @@ extensions: []
21
105
  extra_rdoc_files: []
22
106
  files:
23
107
  - lib/epsagon.rb
24
- - lib/epsagon_opentelemetry.rb
25
108
  - lib/instrumentation/aws_sdk.rb
109
+ - lib/instrumentation/epsagon_faraday_middleware.rb
26
110
  - lib/instrumentation/faraday.rb
27
111
  - lib/instrumentation/net_http.rb
28
112
  - 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