epsagon 0.0.12 → 0.0.13

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: cfe4b588a7d3aeac7ea954338f6814c1b733cdacaab175b8ab63711a09adb849
4
- data.tar.gz: a18b237f3e75ff45e3866a4570ad4125951480366007f0700af412254e04fd5e
3
+ metadata.gz: 61ba7bcc54462d42f93ab3ef042ad54eae55b0447849ed2cb04407980d95ac5c
4
+ data.tar.gz: cbe32e9ece025429fba57e0468b9016e81ab0d291a20755b3fe4c7eb13bcfb13
5
5
  SHA512:
6
- metadata.gz: 4b0e7b5e44f8941fe647e69cb4f59c86ce144eef01fe7c96a035652c8fede98d2b781d59f495a852e1c0919fa5af40fe6413e2ef2c6c2b9c3b4a013b5ebef5c0
7
- data.tar.gz: d67ce25f32683d501729e1715e6427881f7a89fc730030ade43ca3df05402c8277237df9fb1f38c9a4e460f21863a076903c2c8f011b715b50b56d4be3e2b549
6
+ metadata.gz: d722c6363b5a2184034a8e05e43b7fc5ad20f1f4689b62f44f0287b6bfef62253765d1d71f312f49bf4d5d9698b82ba3e6507b45260b53cff3fe637f736b501f
7
+ data.tar.gz: a6d24b5d4d8de7e42e8780d936e22256c0d23618c19c7c232ea0d96c3ecbf95eed7f7e43d6bba044ded25fda965903262328f77893155718e4df8a23ddd146d8
data/lib/epsagon.rb CHANGED
@@ -17,13 +17,15 @@ Bundler.require
17
17
 
18
18
  # Epsagon tracing main entry point
19
19
  module Epsagon
20
+ DEFAULT_BACKEND = 'opentelemetry.tc.epsagon.com:443/traces'
21
+
20
22
  @@epsagon_config = {
21
- metadata_only: ENV['EPSAGON_METADATA']&.to_s&.downcase != 'false',
22
- debug: ENV['EPSAGON_DEBUG']&.to_s&.downcase == 'true',
23
- token: ENV['EPSAGON_TOKEN'],
24
- app_name: ENV['EPSAGON_APP_NAME'],
25
- backend: ENV['EPSAGON_BACKEND'] || 'localhost:55681/v1/trace'
26
- }
23
+ metadata_only: ENV['EPSAGON_METADATA']&.to_s&.downcase != 'false',
24
+ debug: ENV['EPSAGON_DEBUG']&.to_s&.downcase == 'true',
25
+ token: ENV['EPSAGON_TOKEN'],
26
+ app_name: ENV['EPSAGON_APP_NAME'],
27
+ backend: ENV['EPSAGON_BACKEND'] || DEFAULT_BACKEND
28
+ }
27
29
 
28
30
  module_function
29
31
 
@@ -47,10 +49,10 @@ module Epsagon
47
49
  if @@epsagon_config[:debug]
48
50
  configurator.add_span_processor OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
49
51
  OpenTelemetry::Exporter::OTLP::Exporter.new(headers: {
50
- 'x-epsagon-token' => @@epsagon_config[:token]
51
- },
52
- endpoint: @@epsagon_config[:backend],
53
- insecure: @@epsagon_config[:insecure] || false)
52
+ 'x-epsagon-token' => @@epsagon_config[:token]
53
+ },
54
+ endpoint: @@epsagon_config[:backend],
55
+ insecure: @@epsagon_config[:insecure] || false)
54
56
  )
55
57
 
56
58
  configurator.add_span_processor OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
@@ -66,7 +68,6 @@ module Epsagon
66
68
  )
67
69
  end
68
70
  end
69
-
70
71
  end
71
72
 
72
73
  # monkey patch to include epsagon confs
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sdk-core'
2
4
  require 'opentelemetry/common'
3
5
  require 'opentelemetry/sdk'
4
6
 
5
- def untraced
6
- OpenTelemetry::Trace.with_span(OpenTelemetry::Trace::Span.new) { yield }
7
+ def untraced(&block)
8
+ OpenTelemetry::Trace.with_span(OpenTelemetry::Trace::Span.new, &block)
7
9
  end
10
+
8
11
  # AWS SDK plugin for epsagon instrumentation
9
12
  class EpsagonAwsPlugin < Seahorse::Client::Plugin
10
13
  def add_handlers(handlers, _)
@@ -15,13 +18,13 @@ end
15
18
  # Generates Spans for all uses of AWS SDK
16
19
  class EpsagonAwsHandler < Seahorse::Client::Handler
17
20
  def call(context)
18
- tracer.in_span('') do |span|
21
+ tracer.in_span('', kind: :client) do |span|
19
22
  untraced do
20
23
  @handler.call(context).tap do
21
24
  span.set_attribute('aws.service', context.client.class.to_s.split('::')[1].downcase)
22
- span.set_attribute('aws.aws.operation', context.operation.name)
25
+ span.set_attribute('aws.operation', context.operation.name)
23
26
  span.set_attribute('aws.region', context.client.config.region)
24
- span.set_attribute('aws.status_code', context.http_response.status_code)
27
+ span.set_attribute('http.status_code', context.http_response.status_code)
25
28
  end
26
29
  end
27
30
  end
@@ -30,4 +33,4 @@ class EpsagonAwsHandler < Seahorse::Client::Handler
30
33
  def tracer
31
34
  EpsagonAwsSdkInstrumentation.instance.tracer
32
35
  end
33
- end
36
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require_relative '../util'
3
4
  require 'faraday'
@@ -1,41 +1,42 @@
1
- require 'opentelemetry/trace/status'
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'opentelemetry/trace/status'
3
4
 
4
5
  module QueueTime
5
- REQUEST_START = 'HTTP_X_REQUEST_START'
6
- QUEUE_START = 'HTTP_X_QUEUE_START'
7
- MINIMUM_ACCEPTABLE_TIME_VALUE = 1_000_000_000
8
-
9
- module_function
10
-
11
- def get_request_start(env, now = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
12
- header = env[REQUEST_START] || env[QUEUE_START]
13
- return unless header
14
-
15
- # nginx header is seconds in the format "t=1512379167.574"
16
- # apache header is microseconds in the format "t=1570633834463123"
17
- # heroku header is milliseconds in the format "1570634024294"
18
- time_string = header.to_s.delete('^0-9')
19
- return if time_string.nil?
20
-
21
- # Return nil if the time is clearly invalid
22
- time_value = "#{time_string[0, 10]}.#{time_string[10, 6]}".to_f
23
- return if time_value.zero? || time_value < MINIMUM_ACCEPTABLE_TIME_VALUE
24
-
25
- # return the request_start only if it's lesser than
26
- # current time, to avoid significant clock skew
27
- request_start = Time.at(time_value)
28
- now ||= Time.now.utc
29
- request_start.utc > now ? nil : request_start
30
- rescue StandardError => e
31
- # in case of an Exception we don't create a
32
- # `request.queuing` span
33
- OpenTelemetry.logger.debug("[rack] unable to parse request queue headers: #{e}")
34
- nil
35
- end
6
+ REQUEST_START = 'HTTP_X_REQUEST_START'
7
+ QUEUE_START = 'HTTP_X_QUEUE_START'
8
+ MINIMUM_ACCEPTABLE_TIME_VALUE = 1_000_000_000
9
+
10
+ module_function
11
+
12
+ def get_request_start(env, now = nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
13
+ header = env[REQUEST_START] || env[QUEUE_START]
14
+ return unless header
15
+
16
+ # nginx header is seconds in the format "t=1512379167.574"
17
+ # apache header is microseconds in the format "t=1570633834463123"
18
+ # heroku header is milliseconds in the format "1570634024294"
19
+ time_string = header.to_s.delete('^0-9')
20
+ return if time_string.nil?
21
+
22
+ # Return nil if the time is clearly invalid
23
+ time_value = "#{time_string[0, 10]}.#{time_string[10, 6]}".to_f
24
+ return if time_value.zero? || time_value < MINIMUM_ACCEPTABLE_TIME_VALUE
25
+
26
+ # return the request_start only if it's lesser than
27
+ # current time, to avoid significant clock skew
28
+ request_start = Time.at(time_value)
29
+ now ||= Time.now.utc
30
+ request_start.utc > now ? nil : request_start
31
+ rescue StandardError => e
32
+ # in case of an Exception we don't create a
33
+ # `request.queuing` span
34
+ OpenTelemetry.logger.debug("[rack] unable to parse request queue headers: #{e}")
35
+ nil
36
+ end
36
37
  end
37
38
 
38
- class EpsagonRackMiddleware # rubocop:disable Metrics/ClassLength
39
+ class EpsagonRackMiddleware
39
40
  class << self
40
41
  def allowed_rack_request_headers
41
42
  @allowed_rack_request_headers ||= Array(config[:allowed_request_headers]).each_with_object({}) do |header, memo|
@@ -72,7 +73,7 @@ class EpsagonRackMiddleware # rubocop:disable Metrics/ClassLength
72
73
  @app = app
73
74
  end
74
75
 
75
- def call(env) # rubocop:disable Metrics/AbcSize
76
+ def call(env)
76
77
  original_env = env.dup
77
78
  extracted_context = OpenTelemetry.propagation.http.extract(env)
78
79
  frontend_context = create_frontend_span(env, extracted_context)
@@ -181,7 +182,7 @@ class EpsagonRackMiddleware # rubocop:disable Metrics/ClassLength
181
182
  end
182
183
  end
183
184
 
184
- def set_attributes_after_request(http_span, framework_span, status, headers, response)
185
+ def set_attributes_after_request(http_span, _framework_span, status, headers, response)
185
186
  unless config[:epsagon][:metadata_only]
186
187
  http_span.set_attribute('http.response.headers', JSON.generate(headers))
187
188
  http_span.set_attribute('http.response.body', response.join)
@@ -269,7 +270,6 @@ end
269
270
  # end
270
271
  # end
271
272
 
272
-
273
273
  class EpsagonRailtie < ::Rails::Railtie
274
274
  config.before_initialize do |app|
275
275
  # EpsagonRackInstrumentation.instance.install({})
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Patch faraday to include middleware
3
4
  module EpsagonFaradayPatch
4
5
  def adapter(*args)
@@ -40,7 +40,7 @@ module EpsagonNetHTTPExtension
40
40
  tracer.in_span(
41
41
  @address,
42
42
  attributes: attributes,
43
- kind: :Client
43
+ kind: :client
44
44
  ) do |span|
45
45
  OpenTelemetry.propagation.http.inject(req)
46
46
 
@@ -1,12 +1,13 @@
1
-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'opentelemetry'
3
4
  require 'rails'
4
- require "action_controller/railtie"
5
+ require 'action_controller/railtie'
5
6
 
6
7
  require_relative '../util'
7
8
 
8
9
  module RackExtension
9
- extend self
10
+ module_function
10
11
 
11
12
  CURRENT_SPAN_KEY = OpenTelemetry::Context.create_key('current-span')
12
13
 
@@ -41,7 +42,7 @@ module RackExtension
41
42
  OpenTelemetry::Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
42
43
  end
43
44
  end
44
-
45
+
45
46
  module MetalPatch
46
47
  def dispatch(name, request, response)
47
48
  rack_span = RackExtension.current_span
@@ -50,15 +51,13 @@ module MetalPatch
50
51
  end
51
52
  end
52
53
 
53
-
54
-
55
54
  class EpsagonRailsInstrumentation < OpenTelemetry::Instrumentation::Base
56
- install do |_config|
57
- require_relative 'epsagon_rails_middleware'
58
- ::ActionController::Metal.prepend(MetalPatch)
59
- end
55
+ install do |_config|
56
+ require_relative 'epsagon_rails_middleware'
57
+ ::ActionController::Metal.prepend(MetalPatch)
58
+ end
60
59
 
61
- present do
62
- defined?(::Rails)
63
- end
64
- end
60
+ present do
61
+ defined?(::Rails)
62
+ end
63
+ end
@@ -26,7 +26,7 @@ class EpsagonTracerMiddleware
26
26
  attributes = {
27
27
  'operation' => env['REQUEST_METHOD'],
28
28
  'type' => 'http',
29
- 'http.scheme' => env['PATH_INFO'],
29
+ 'http.scheme' => env['rack.url_scheme'],
30
30
  'http.request.path' => path,
31
31
  'http.request.headers' => request_headers
32
32
  }
@@ -51,7 +51,11 @@ class EpsagonTracerMiddleware
51
51
  kind: :server,
52
52
  with_parent: parent_context(env)
53
53
  ) do |http_span|
54
- tracer.in_span('sinatra') do |framework_span|
54
+ tracer.in_span(
55
+ env['HTTP_HOST'],
56
+ kind: :server,
57
+ attributes: { type: 'sinatra' }
58
+ ) do |framework_span|
55
59
  app.call(env).tap { |resp| trace_response(http_span, framework_span, env, resp) }
56
60
  end
57
61
  end
@@ -78,7 +82,7 @@ class EpsagonTracerMiddleware
78
82
  end
79
83
 
80
84
  http_span.set_attribute('http.status_code', status)
81
- framework_span.set_attribute('http.route', env['sinatra.route'].split.last) if env['sinatra.route']
85
+ http_span.set_attribute('http.route', env['sinatra.route'].split.last) if env['sinatra.route']
82
86
  http_span.status = OpenTelemetry::Trace::Status.http_to_status(status)
83
87
  end
84
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epsagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
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-13 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.11.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: opentelemetry-sdk
28
+ name: opentelemetry-exporter-otlp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.11.1
33
+ version: 0.11.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.11.1
40
+ version: 0.11.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: opentelemetry-instrumentation-sinatra
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.11.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: opentelemetry-exporter-otlp
56
+ name: opentelemetry-sdk
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.11.0
61
+ version: 0.11.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.11.0
68
+ version: 0.11.1
69
69
  description: 'Epsagon provides tracing to Ruby applications for the collection of
70
70
  distributed tracing and performance metrics to simplify complex architectures, eliminate
71
71
  manual work, visualize and correlate data to identify and fix problems fast.