epsagon 0.0.6 → 0.0.11

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: a4bed616ed52fa572f7574732c18cdc87a34a6a223f969e3a0bdf95b7a132e77
4
- data.tar.gz: b502868b35380f9187fbf2a452036060ac61ccabfae509ba4cfb66ed221a7365
3
+ metadata.gz: ab0dc77590ae9d619fa9dc901ce8af447cfa4555b3e4e2de648952add1604043
4
+ data.tar.gz: ba0e5a0589ac967734b3019e229031a345577cc44518d876228238011f3bd2a4
5
5
  SHA512:
6
- metadata.gz: 0e4ab80eab789716260eea7824800b1e6c0f193114e72b45da826f36bdefedb59cc4e01147dbe4e8bb5824d10e2c525ed085d6bf256387746967009b13e7425a
7
- data.tar.gz: cf2f072e8b3688c6988664304b06cad165fe43314aa862dae5ea4ef0ccb0a303f9b48dff56ff2913a5e86377f0186c23b13d7966bf3239c609606ab669e3fee3
6
+ metadata.gz: d383f183f674c601ef695e5b47adcaa770e8d9d6cfbe22d922b4e8785dc2b6f5c677ec0abfaab7c01df880afabe8b3c0395ffc076ff67fe3393ecc06f8a37cd5
7
+ data.tar.gz: 895b8b35143b0c232e4e3611ddf32652163a191f4d58af3283101af3f2f107f396be765931c3734f5f3aebe6cf2ec4f2d19d561b4cc033286cc1a33b4f373fd2
data/lib/epsagon.rb CHANGED
@@ -4,10 +4,12 @@ require 'rubygems'
4
4
  require 'net/http'
5
5
  require 'bundler/setup'
6
6
  require 'opentelemetry/sdk'
7
+ require 'opentelemetry/exporter/otlp'
7
8
 
8
9
  require_relative 'instrumentation/sinatra'
9
10
  require_relative 'instrumentation/net_http'
10
11
  require_relative 'instrumentation/faraday'
12
+ require_relative 'instrumentation/aws_sdk'
11
13
  require_relative 'util'
12
14
 
13
15
  Bundler.require
@@ -38,6 +40,7 @@ module Epsagon
38
40
  configurator.use 'EpsagonSinatraInstrumentation', { epsagon: @@epsagon_config }
39
41
  configurator.use 'EpsagonNetHTTPInstrumentation', { epsagon: @@epsagon_config }
40
42
  configurator.use 'EpsagonFaradayInstrumentation', { epsagon: @@epsagon_config }
43
+ configurator.use 'EpsagonAwsSdkInstrumentation', { epsagon: @@epsagon_config }
41
44
 
42
45
  if @@epsagon_config[:debug]
43
46
  configurator.add_span_processor OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
@@ -2,32 +2,6 @@
2
2
 
3
3
  require_relative '../util'
4
4
 
5
- # AWS SDK plugin for epsagon instrumentation
6
- class EpsagonAwsPlugin < Seahorse::Client::Plugin
7
- def add_handlers(handlers, _)
8
- handlers.add(EpsagonAwsHandler, step: :validate)
9
- end
10
- end
11
-
12
- # Generates Spans for all uses of AWS SDK
13
- class EpsagonAwsHandler < Seahorse::Client::Handler
14
- def call(context)
15
- tracer.in_span('') do |span|
16
- @handler.call(context).tap do
17
- span.set_attribute('aws.operation', context[:command])
18
- span.set_attribute('aws.status_code', context[:status_code])
19
- span.set_attribute('aws.service', context[:service_name])
20
- span.set_attribute('aws.account_id', context[:account_id])
21
- span.set_attribute('aws.status_code', context[:status_code])
22
- end
23
- end
24
- end
25
-
26
- def tracer
27
- EpsagonAwsSdkInstrumentation.instance.tracer
28
- end
29
- end
30
-
31
5
  # AWS SDK epsagon instrumentation
32
6
  class EpsagonAwsSdkInstrumentation < OpenTelemetry::Instrumentation::Base
33
7
  VERSION = '0.0.0'
@@ -143,6 +117,7 @@ class EpsagonAwsSdkInstrumentation < OpenTelemetry::Instrumentation::Base
143
117
  ].freeze
144
118
 
145
119
  install do |_|
120
+ require_relative 'aws_sdk_plugin'
146
121
  ::Seahorse::Client::Base.add_plugin(EpsagonAwsPlugin)
147
122
  loaded_constants.each { |klass| klass.add_plugin(EpsagonAwsPlugin) }
148
123
  end
@@ -0,0 +1,33 @@
1
+ require 'aws-sdk-core'
2
+ require 'opentelemetry/common'
3
+ require 'opentelemetry/sdk'
4
+
5
+ def untraced
6
+ OpenTelemetry::Trace.with_span(OpenTelemetry::Trace::Span.new) { yield }
7
+ end
8
+ # AWS SDK plugin for epsagon instrumentation
9
+ class EpsagonAwsPlugin < Seahorse::Client::Plugin
10
+ def add_handlers(handlers, _)
11
+ handlers.add(EpsagonAwsHandler, step: :validate)
12
+ end
13
+ end
14
+
15
+ # Generates Spans for all uses of AWS SDK
16
+ class EpsagonAwsHandler < Seahorse::Client::Handler
17
+ def call(context)
18
+ tracer.in_span('') do |span|
19
+ untraced do
20
+ @handler.call(context).tap do
21
+ span.set_attribute('aws.service', context.client.class.to_s.split('::')[1].downcase)
22
+ span.set_attribute('aws.aws.operation', context.operation.name)
23
+ span.set_attribute('aws.region', context.client.config.region)
24
+ span.set_attribute('aws.status_code', context.http_response.status_code)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def tracer
31
+ EpsagonAwsSdkInstrumentation.instance.tracer
32
+ end
33
+ end
@@ -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'
@@ -49,7 +48,7 @@ class EpsagonTracerMiddleware
49
48
  tracer.in_span(
50
49
  env['HTTP_HOST'],
51
50
  attributes: attributes,
52
- kind: :Server,
51
+ kind: :server,
53
52
  with_parent: parent_context(env)
54
53
  ) do |http_span|
55
54
  tracer.in_span('sinatra') do |framework_span|
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.6
4
+ version: 0.0.11
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
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
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
41
  - !ruby/object:Gem::Dependency
56
42
  name: opentelemetry-instrumentation-sinatra
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +66,6 @@ dependencies:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  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'
97
69
  description: 'Epsagon provides tracing to Ruby applications for the collection of
98
70
  distributed tracing and performance metrics to simplify complex architectures, eliminate
99
71
  manual work, visualize and correlate data to identify and fix problems fast.
@@ -105,8 +77,9 @@ extensions: []
105
77
  extra_rdoc_files: []
106
78
  files:
107
79
  - lib/epsagon.rb
108
- - lib/epsagon_opentelemetry.rb
109
80
  - lib/instrumentation/aws_sdk.rb
81
+ - lib/instrumentation/aws_sdk_plugin.rb
82
+ - lib/instrumentation/epsagon_faraday_middleware.rb
110
83
  - lib/instrumentation/faraday.rb
111
84
  - lib/instrumentation/net_http.rb
112
85
  - 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