epsagon 0.0.16 → 0.0.17

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: 808ee2781331d674be9e661fdb982402a9fa118a7e530226334dac758ce80dbb
4
- data.tar.gz: 370aad1ea87d60e10ffa0b0c6777951c290aaacb2074a6556b6b77a41f9606d3
3
+ metadata.gz: cff5af42ab7df270fc1a9c645d5dc25558e03ba194e2d642694dbbeaa074ebf6
4
+ data.tar.gz: 75971b80361f7feefeb45af21074d2357eeb4cdeb82ce0bdad989493b3b1abc6
5
5
  SHA512:
6
- metadata.gz: 223f608c05ddf216c1db46709d234604af81dca746fe16d5c4f24e89618450313c6e8a972f35fa2c2f5c6aa4b5811cd97e638d625dde9a1d5b0bc9a00575cf92
7
- data.tar.gz: 5317d3432c01890de86919a5415322ed151002d12058027fa890cffa34ee32818d3e87e1d4484b5317aa1ab7c9047bf9347c2d5cf71e5718791ac6766e0163eb
6
+ metadata.gz: a71dffcee29e3039cd7be5a5bf7cd60661574b86b0cc45b1b1b55df5d1b8108f1f713ace4ccb173f5283638212798f2a7e0430fbc76f6d3f35eeec52c8008d0b
7
+ data.tar.gz: 18b465927c9dc8b8ea722b55cc8b9e896fc498b6aa02b7a6c2e628c848ffebfe3f637ae417a2361879e511311907f480bad565091e75bd94d488b1a7f90b4b51
data/lib/epsagon.rb CHANGED
@@ -12,11 +12,13 @@ require_relative 'instrumentation/faraday'
12
12
  require_relative 'instrumentation/aws_sdk'
13
13
  require_relative 'instrumentation/rails'
14
14
  require_relative 'util'
15
+ require_relative 'epsagon_constants'
15
16
 
16
17
  Bundler.require
17
18
 
18
19
  # Epsagon tracing main entry point
19
20
  module Epsagon
21
+
20
22
  DEFAULT_BACKEND = 'opentelemetry.tc.epsagon.com:443/traces'
21
23
 
22
24
  @@epsagon_config = {
@@ -24,6 +26,7 @@ module Epsagon
24
26
  debug: ENV['EPSAGON_DEBUG']&.to_s&.downcase == 'true',
25
27
  token: ENV['EPSAGON_TOKEN'],
26
28
  app_name: ENV['EPSAGON_APP_NAME'],
29
+ max_attribute_size: ENV['EPSAGON_MAX_ATTRIBUTE_SIZE'] || 5000,
27
30
  backend: ENV['EPSAGON_BACKEND'] || DEFAULT_BACKEND
28
31
  }
29
32
 
@@ -34,11 +37,18 @@ module Epsagon
34
37
  OpenTelemetry::SDK.configure
35
38
  end
36
39
 
40
+ def get_config
41
+ @@epsagon_config
42
+ end
43
+
37
44
  # config opentelemetry with epsaon extensions:
38
45
 
39
46
  def epsagon_confs(configurator)
40
47
  configurator.resource = OpenTelemetry::SDK::Resources::Resource.telemetry_sdk.merge(
41
- OpenTelemetry::SDK::Resources::Resource.create({ 'application' => @@epsagon_config[:app_name] })
48
+ OpenTelemetry::SDK::Resources::Resource.create({
49
+ 'application' => @@epsagon_config[:app_name],
50
+ 'epsagon.version' => EpsagonConstants::VERSION
51
+ })
42
52
  )
43
53
  configurator.use 'EpsagonSinatraInstrumentation', { epsagon: @@epsagon_config }
44
54
  configurator.use 'EpsagonNetHTTPInstrumentation', { epsagon: @@epsagon_config }
@@ -70,6 +80,29 @@ module Epsagon
70
80
  end
71
81
  end
72
82
 
83
+
84
+ module SpanExtension
85
+
86
+ BLANKS = [nil, [], '']
87
+
88
+ def set_attribute(key, value)
89
+ unless BLANKS.include?(value)
90
+ value = Util.trim_attr(value, Epsagon.get_config[:max_attribute_size])
91
+ super(key, value)
92
+ end
93
+ end
94
+
95
+ def initialize(*args)
96
+ super(*args)
97
+ if @attributes
98
+ @attributes = Hash[@attributes.map { |k,v|
99
+ [k, Util.trim_attr(v, Epsagon.get_config[:max_attribute_size])]
100
+ }]
101
+ end
102
+
103
+ end
104
+ end
105
+
73
106
  # monkey patch to include epsagon confs
74
107
  module OpenTelemetry
75
108
  # monkey patch inner SDK module
@@ -80,5 +113,11 @@ module OpenTelemetry
80
113
  Epsagon.epsagon_confs c
81
114
  end
82
115
  end
116
+
117
+ module Trace
118
+ class Span
119
+ prepend SpanExtension
120
+ end
121
+ end
83
122
  end
84
123
  end
@@ -0,0 +1,3 @@
1
+ module EpsagonConstants
2
+ VERSION = '0.0.17'
3
+ end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../util'
4
+ require_relative '../epsagon_constants'
4
5
 
5
6
  # AWS SDK epsagon instrumentation
6
7
  class EpsagonAwsSdkInstrumentation < OpenTelemetry::Instrumentation::Base
7
- VERSION = '0.0.0'
8
+ VERSION = EpsagonConstants::VERSION
8
9
  SERVICES = %w[
9
10
  ACM
10
11
  APIGateway
@@ -31,6 +31,6 @@ class EpsagonAwsHandler < Seahorse::Client::Handler
31
31
  end
32
32
 
33
33
  def tracer
34
- EpsagonAwsSdkInstrumentation.instance.tracer
34
+ EpsagonAwsSdkInstrumentation.instance.tracer()
35
35
  end
36
36
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../util'
4
+ require_relative '../epsagon_constants'
5
+
4
6
  require 'faraday'
5
7
 
6
8
  # Faraday middleware for epsagon instrumentaton
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  # Faraday epsagon instrumentaton
15
15
  class EpsagonFaradayInstrumentation < OpenTelemetry::Instrumentation::Base
16
- VERSION = '0.0.0'
16
+ VERSION = EpsagonConstants::VERSION
17
17
 
18
18
  install do |_config|
19
19
  require_relative 'epsagon_faraday_middleware'
@@ -3,6 +3,7 @@
3
3
  require 'opentelemetry'
4
4
 
5
5
  require_relative '../util'
6
+ require_relative '../epsagon_constants'
6
7
 
7
8
  # Net::HTTP patch for epsagon instrumentaton
8
9
  module EpsagonNetHTTPExtension
@@ -74,7 +75,7 @@ end
74
75
 
75
76
  # Net::HTTP epsagon instrumentaton
76
77
  class EpsagonNetHTTPInstrumentation < OpenTelemetry::Instrumentation::Base
77
- VERSION = '0.0.0'
78
+ VERSION = EpsagonConstants::VERSION
78
79
 
79
80
  install do |_|
80
81
  ::Net::HTTP.prepend(EpsagonNetHTTPExtension)
@@ -5,6 +5,8 @@ require 'rails'
5
5
  require 'action_controller/railtie'
6
6
 
7
7
  require_relative '../util'
8
+ require_relative '../epsagon_constants'
9
+
8
10
 
9
11
  module RackExtension
10
12
  module_function
@@ -3,6 +3,7 @@
3
3
  require 'opentelemetry'
4
4
 
5
5
  require_relative '../util'
6
+ require_relative '../epsagon_constants'
6
7
 
7
8
  # Sinatra middleware for epsagon instrumentation
8
9
  class EpsagonTracerMiddleware
@@ -111,7 +112,7 @@ end
111
112
 
112
113
  # Sinatra epsagon instrumentation
113
114
  class EpsagonSinatraInstrumentation < OpenTelemetry::Instrumentation::Base
114
- VERSION = '0.0.0'
115
+ VERSION = EpsagonConstants::VERSION
115
116
 
116
117
  install do |_|
117
118
  ::Sinatra::Base.register EpsagonTracerExtension
File without changes
data/lib/util.rb CHANGED
@@ -11,4 +11,23 @@ module Util
11
11
  { 'http.request.query' => query_string }
12
12
  end
13
13
  end
14
+
15
+ def self.trim_attr(value, max_size)
16
+ if value.instance_of? Array then
17
+ current_size = 2
18
+ value.each_with_index do |el, i|
19
+ el_size = el.to_s.size + (i==0 ? 0 : 2)
20
+ if current_size + el_size > max_size then
21
+ return value[0,i] + [Util.trim_attr(el, max_size - current_size)]
22
+ else
23
+ current_size += el_size
24
+ end
25
+ end
26
+ return value
27
+ elsif value.instance_of? String then
28
+ value[0, max_size]
29
+ else
30
+ value
31
+ end
32
+ end
14
33
  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.16
4
+ version: 0.0.17
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-19 00:00:00.000000000 Z
11
+ date: 2021-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -77,6 +77,7 @@ extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
79
  - lib/epsagon.rb
80
+ - lib/epsagon_constants.rb
80
81
  - lib/instrumentation/aws_sdk.rb
81
82
  - lib/instrumentation/aws_sdk_plugin.rb
82
83
  - lib/instrumentation/epsagon_faraday_middleware.rb
@@ -85,6 +86,7 @@ files:
85
86
  - lib/instrumentation/net_http.rb
86
87
  - lib/instrumentation/rails.rb
87
88
  - lib/instrumentation/sinatra.rb
89
+ - lib/instrumentation/version.rb
88
90
  - lib/util.rb
89
91
  homepage: https://github.com/epsagon/epsagon-ruby
90
92
  licenses: