epsagon 0.0.29 → 0.0.30

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: 25cf09d9ea5babb3e7caa3380d6b8a78365909391ec3eb84ec150e07fbd9841a
4
- data.tar.gz: bb3f2efc49e2b0930ffb677bfb5b8440fa16fe2a41a7adb96b33a35e89efdb67
3
+ metadata.gz: f8ebb5eb2134eb62b3b83fa8cbb48b9c535cf528999c55ad1b58ed161b63cd97
4
+ data.tar.gz: 1e5ac5ea5ef2d6a3ba156b89061cca64bab22b90ce27b37e128a9b62c2633526
5
5
  SHA512:
6
- metadata.gz: b179e2cf5b65329b6a7a40dec43a379fb294ddee0e58f389cd4ffc105f503265ad655cbf50067a9995b04358ddb9d9d0f8441d47e2639befcc4744c8af3c290c
7
- data.tar.gz: 5b8443325b4afadffed3f836ba9a7385cbdfbc2cd03eebfee007bb0543ddb5f2b3c279d22a614fa80ecabb7f4a18f6a1292298567d444a84c9a364ef361bb626
6
+ metadata.gz: 34adf61a4771b2e61f916a79f3e038a1b23235214d13ec9771c33e3a1be34edc843c735f2ca2fd6d1a84fc895e9ffd7f6ec4b7674b1ace141b39f193e0d7b7b0
7
+ data.tar.gz: 289999c6c4d93c3521598fc0ac30eefd29f83e46f74079d1133b50d4a459c6f8e397f6fa1cf151492308d6089b9bfda9f9ed4279aab29c0e1de787aba26e4361
data/lib/epsagon.rb CHANGED
@@ -26,8 +26,7 @@ Bundler.require
26
26
  module Epsagon
27
27
  DEFAULT_BACKEND = 'opentelemetry.tc.epsagon.com:443/traces'
28
28
  DEFAULT_IGNORE_DOMAINS = ['newrelic.com'].freeze
29
- MUTABLE_CONF_KEYS = Set.new([:metadata_only, :max_attribute_size, :ignore_domains])
30
-
29
+ MUTABLE_CONF_KEYS = Set.new([:metadata_only, :max_attribute_size, :ignore_domains, :ignored_keys])
31
30
 
32
31
  @@epsagon_config = nil
33
32
 
@@ -43,16 +42,16 @@ module Epsagon
43
42
  def validate(config)
44
43
  Util.validate_value(config, :metadata_only, 'Must be a boolean') {|v| !!v == v}
45
44
  Util.validate_value(config, :debug, 'Must be a boolean') {|v| !!v == v}
46
- Util.validate_value(config, :token, 'Must be a valid Epsagon token') {|v| v.is_a? String and v.size > 10}
47
- Util.validate_value(config, :app_name, 'Must be a String') {|v| v.is_a? String}
45
+ Util.validate_value(config, :token, 'Must be a valid Epsagon token') {|v| (v.is_a? String) && (v.size > 10) }
46
+ Util.validate_value(config, :app_name, 'Must be a String') {|v| (v.is_a? String) && (v.size > 0) }
48
47
  Util.validate_value(config, :max_attribute_size, 'Must be an Integer') {|v| v.is_a? Integer}
49
48
  Util.validate_value(config, :ignore_domains, 'Must be iterable') {|v| v.respond_to?(:each)}
50
- Util.validate_value(config, :ignore_domains, 'Must be iterable') {|v| v.respond_to?(:each)}
49
+ Util.validate_value(config, :ignored_keys, 'Must be iterable') {|v| v.respond_to?(:each)}
51
50
  end
52
51
 
53
52
  def set_config(**args)
54
53
  unless args.keys.all? {|a| MUTABLE_CONF_KEYS.include?(a)}
55
- raise ArgumentError("only #{MUTABLE_CONF_KEYS.to_a} are mutable after `Epsagon.init`")
54
+ raise ArgumentError.new("only #{MUTABLE_CONF_KEYS.to_a} are mutable after `Epsagon.init`")
56
55
  end
57
56
  Epsagon.init unless @@initialized
58
57
  new_conf = get_config.merge(args)
@@ -60,6 +59,14 @@ module Epsagon
60
59
  @@epsagon_config = new_conf
61
60
  end
62
61
 
62
+ def add_ignored_key(key)
63
+ get_config[:ignored_keys].push(key).uniq
64
+ end
65
+
66
+ def remove_ignored_key(key)
67
+ get_config[:ignored_keys].delete(key)
68
+ end
69
+
63
70
  def get_config
64
71
  @@epsagon_config ||= {
65
72
  metadata_only: ENV['EPSAGON_METADATA']&.to_s&.downcase != 'false',
@@ -68,7 +75,8 @@ module Epsagon
68
75
  app_name: ENV['EPSAGON_APP_NAME'] || '',
69
76
  max_attribute_size: ENV['EPSAGON_MAX_ATTRIBUTE_SIZE'] || 5000,
70
77
  backend: ENV['EPSAGON_BACKEND'] || DEFAULT_BACKEND,
71
- ignore_domains: ENV['EPSAGON_IGNORE_DOMAINS'] || DEFAULT_IGNORE_DOMAINS
78
+ ignore_domains: ENV['EPSAGON_IGNORE_DOMAINS']&.split(',') || DEFAULT_IGNORE_DOMAINS,
79
+ ignored_keys: ENV['EPSAGON_IGNORED_KEYS']&.split(',') || []
72
80
  }
73
81
  end
74
82
 
@@ -135,10 +143,15 @@ module SpanExtension
135
143
 
136
144
  BLANKS = [nil, [], '']
137
145
 
146
+ def set_mapping_attribute(key, value)
147
+ value = Util.prepare_attr(key, value, Epsagon.get_config[:max_attribute_size], Epsagon.get_config[:ignored_keys])
148
+ set_attribute(key, value) if value
149
+ end
150
+
138
151
  def set_attribute(key, value)
139
152
  unless BLANKS.include?(value)
140
- value = Util.trim_attr(value, Epsagon.get_config[:max_attribute_size])
141
- super(key, value)
153
+ value = Util.prepare_attr(key, value, Epsagon.get_config[:max_attribute_size], Epsagon.get_config[:ignored_keys])
154
+ super(key, value) if value
142
155
  end
143
156
  end
144
157
 
@@ -146,8 +159,9 @@ module SpanExtension
146
159
  super(*args)
147
160
  if @attributes
148
161
  @attributes = Hash[@attributes.select {|k,v| not BLANKS.include? v}.map { |k,v|
149
- [k, Util.trim_attr(v, Epsagon.get_config[:max_attribute_size])]
150
- }]
162
+ v = Util.prepare_attr(k, v, Epsagon.get_config[:max_attribute_size], Epsagon.get_config[:ignored_keys])
163
+ [k, v] if v
164
+ }.compact]
151
165
  end
152
166
  end
153
167
  end
@@ -1,3 +1,3 @@
1
1
  module EpsagonConstants
2
- VERSION = '0.0.29'
2
+ VERSION = '0.0.30'
3
3
  end
@@ -59,10 +59,10 @@ class EpsagonAwsHandler < Seahorse::Client::Handler
59
59
  'message_body' => m[:message_body],
60
60
  }
61
61
  end
62
- attributes['aws.sqs.record'] = JSON.dump(messages_attributes) if messages_attributes
62
+ attributes['aws.sqs.record'] = messages_attributes if messages_attributes
63
63
  end
64
64
  attributes['aws.sqs.record.message_body'] = context.params[:message_body]
65
- attributes['aws.sqs.record.message_attributes'] = JSON.dump(context.params[:message_attributes]) if context.params[:message_attributes]
65
+ attributes['aws.sqs.record.message_attributes'] = context.params[:message_attributes] if context.params[:message_attributes]
66
66
  end
67
67
  elsif attributes['aws.service'] == 'sns'
68
68
  topic_arn = context.params[:topic_arn]
@@ -71,7 +71,7 @@ class EpsagonAwsHandler < Seahorse::Client::Handler
71
71
  unless config[:epsagon][:metadata_only]
72
72
  attributes['aws.sns.subject'] = context.params[:subject]
73
73
  attributes['aws.sns.message'] = context.params[:message]
74
- attributes['aws.sns.message_attributes'] = JSON.dump(context.params[:message_attributes]) if context.params[:message_attributes]
74
+ attributes['aws.sns.message_attributes'] = context.params[:message_attributes] if context.params[:message_attributes]
75
75
  end
76
76
  end
77
77
  tracer.in_span(span_name, kind: span_kind, attributes: attributes) do |span|
@@ -105,7 +105,7 @@ class EpsagonAwsHandler < Seahorse::Client::Handler
105
105
  end
106
106
  record
107
107
  end
108
- span.set_attribute('aws.sqs.record', JSON.dump(messages_attributes)) if messages_attributes
108
+ span.set_mapping_attribute('aws.sqs.record', messages_attributes) if messages_attributes
109
109
  end
110
110
  if context.operation.name == 'ReceiveMessage'
111
111
  messages_attributes = result.messages.map do |m|
@@ -123,7 +123,7 @@ class EpsagonAwsHandler < Seahorse::Client::Handler
123
123
  end
124
124
  record
125
125
  end
126
- span.set_attribute('aws.sqs.record', JSON.dump(messages_attributes)) if messages_attributes
126
+ span.set_mapping_attribute('aws.sqs.record', messages_attributes) if messages_attributes
127
127
  end
128
128
  elsif attributes['aws.service'] == 'sns'
129
129
  span.set_attribute('aws.sns.message_id', result.message_id) if context.operation.name == 'Publish'
@@ -38,7 +38,7 @@ class EpsagonFaradayMiddleware < ::Faraday::Middleware
38
38
  attributes.merge!(Util.epsagon_query_attributes(env.url.query))
39
39
  attributes.merge!({
40
40
  'http.request.path_params' => path_params,
41
- 'http.request.headers' => env.request_headers.to_json,
41
+ 'http.request.headers' => Hash[env.request_headers],
42
42
  'http.request.body' => env.body,
43
43
  'http.request.headers.User-Agent' => env.request_headers['User-Agent']
44
44
  })
@@ -67,7 +67,7 @@ class EpsagonFaradayMiddleware < ::Faraday::Middleware
67
67
  span.set_attribute('http.status_code', response.status)
68
68
 
69
69
  unless config[:epsagon][:metadata_only]
70
- span.set_attribute('http.response.headers', response.headers.to_json)
70
+ span.set_attribute('http.response.headers', Hash[env.response.headers])
71
71
  span.set_attribute('http.response.body', response.body)
72
72
  end
73
73
  span.status = OpenTelemetry::Trace::Status.http_to_status(
@@ -28,7 +28,7 @@ module EpsagonResqueModule
28
28
  }
29
29
  unless epsagon_conf[:metadata_only]
30
30
  attributes.merge!({
31
- 'messaging.resque.args' => JSON.dump(item)
31
+ 'messaging.resque.args' => item
32
32
  })
33
33
  end
34
34
 
@@ -80,7 +80,7 @@ module EpsagonResqueJob
80
80
 
81
81
  unless epsagon_conf[:metadata_only]
82
82
  attributes.merge!({
83
- 'messaging.resque.args' => JSON.dump(args)
83
+ 'messaging.resque.args' => args
84
84
  })
85
85
  end
86
86
  tracer.in_span(
@@ -34,7 +34,7 @@ module EpsagonNetHTTPExtension
34
34
  attributes.merge!({
35
35
  'http.request.path_params' => path_params,
36
36
  'http.request.body' => body,
37
- 'http.request.headers' => headers.to_json,
37
+ 'http.request.headers' => Hash[headers],
38
38
  'http.request.headers.User-Agent' => headers['user-agent']
39
39
  })
40
40
  attributes.merge!(Util.epsagon_query_attributes(query))
@@ -62,7 +62,7 @@ module EpsagonNetHTTPExtension
62
62
 
63
63
  span.set_attribute('http.status_code', status_code)
64
64
  unless config[:epsagon][:metadata_only]
65
- span.set_attribute('http.response.headers', Hash[response.each_header.to_a].to_json)
65
+ span.set_attribute('http.response.headers', Hash[response.each_header.to_a])
66
66
  span.set_attribute('http.response.body', response.body)
67
67
  end
68
68
  span.status = OpenTelemetry::Trace::Status.http_to_status(
data/lib/util.rb CHANGED
@@ -16,6 +16,30 @@ module Util
16
16
  end
17
17
  end
18
18
 
19
+
20
+ def self.remove_key_recursive(h, key)
21
+ dot_idx = key.index('.')
22
+ if not dot_idx.nil?
23
+ next_hash = h[key[0..dot_idx - 1]]
24
+ self.remove_key_recursive(next_hash, key[dot_idx + 1..-1]) if next_hash
25
+ else
26
+ h.delete(key)
27
+ end
28
+ end
29
+
30
+ def self.prepare_attr(key, value, max_size, excluded_keys)
31
+ return nil if excluded_keys.include? key
32
+ return self.trim_attr(value, max_size) unless value.instance_of? Hash
33
+ value = value.dup
34
+ excluded_keys.each do |ekey|
35
+ if ekey.start_with? (key + '.')
36
+ rest_of_key = ekey[key.size + 1..-1]
37
+ self.remove_key_recursive(value, rest_of_key)
38
+ end
39
+ end
40
+ return self.trim_attr(JSON.dump(value), max_size)
41
+ end
42
+
19
43
  def self.trim_attr(value, max_size)
20
44
  if value.instance_of? Array then
21
45
  current_size = 2
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.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Epsagon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-01 00:00:00.000000000 Z
11
+ date: 2021-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api