logjam_agent 0.32.1 → 0.33.0

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: b5c6ecbf3ed8bc61db07e66fb6d5626e1734e6765781a29ad4bbafb261ccf890
4
- data.tar.gz: 67a2ef0e834278c2241aafceac7805a72457a1cb68348a48bb0ec95f99658924
3
+ metadata.gz: dbd400c4a9aedda3d5659a550bd2da21e9a29696cd1e5c77c14cb1f15d8e7e50
4
+ data.tar.gz: d71e179fd331b16c0b2117a31a15e45278477b8f4709ffaf93d91c2a859d9a44
5
5
  SHA512:
6
- metadata.gz: '08137b0a31ce7054b3965ffea84c267d45e08752234f93ad4e2777ac28a0e4954dc4bf0f9dd2e6f1fd02f8979fd5a39a28e5dfa00138f4a6ca8f3a0ac21ba354'
7
- data.tar.gz: e0405de81c09f70eecfe77842d25bd150c0fe6a13f028c0cdcbc7d01c029ec786da1b722774a6c4a162112dd1dda04bed0de918469810f3da965241f7d38e322
6
+ metadata.gz: d5fbde19a0225c1859940ab1add7a690ef67109f861154e7a9d80bbc33834ae18fc415d1ab90ca891d7c245c20761c96ab92d07e99ca011ac5866a740ba37376
7
+ data.tar.gz: ff9c7d40001b7902f5fbccb8db57b32d57f23760e74225412be354d046967c97c7e0eafec4bc31b7cd2c961920d31fbc2645671091081e441100001ce82c1d40
data/lib/logjam_agent.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "socket"
2
2
  require "time_bandits"
3
+ require "logjam_agent/monkey_patches/ffi-rzmq-patch"
3
4
 
4
5
  module LogjamAgent
5
6
  module RequestHandling
@@ -76,12 +77,9 @@ module LogjamAgent
76
77
  self.parameter_filters = []
77
78
 
78
79
  def self.get_hostname
79
- n = Socket.gethostname
80
- if n.split('.').size > 1
81
- n
82
- else
83
- Socket.gethostbyname(n).first rescue n
84
- end
80
+ name = Socket.gethostname
81
+ host = name.split('.').first
82
+ Addrinfo.getaddrinfo(host, nil, nil, :STREAM, nil, Socket::AI_CANONNAME).first.canonname rescue name
85
83
  end
86
84
 
87
85
  mattr_accessor :hostname
@@ -50,9 +50,11 @@ module LogjamAgent
50
50
  env_name = env["logjam_agent.environment_name"] || LogjamAgent.environment_name
51
51
  caller_id = env["HTTP_X_LOGJAM_CALLER_ID"] || ""
52
52
  caller_action = env["HTTP_X_LOGJAM_ACTION"] || ""
53
+ trace_id = env["HTTP_X_LOGJAM_TRACE_ID"] || ""
53
54
  extra_fields = {}
54
55
  extra_fields[:caller_id] = caller_id if caller_id.present?
55
56
  extra_fields[:caller_action] = caller_action if caller_action.present?
57
+ extra_fields[:trace_id] = trace_id if trace_id.present?
56
58
  LogjamAgent.start_request(app_name, env_name, extra_fields)
57
59
  end
58
60
 
@@ -0,0 +1,19 @@
1
+ # see https://github.com/chuckremes/ffi-rzmq/pull/133
2
+
3
+ require 'ffi-rzmq'
4
+ require 'ffi-rzmq/message'
5
+
6
+ module ZMQ
7
+ class Message
8
+ def copy_in_bytes bytes, len
9
+ data_buffer = LibC.malloc len
10
+ # writes the exact number of bytes, no null byte to terminate string
11
+ data_buffer.put_bytes 0, bytes, 0, len
12
+
13
+ # use libC to call free on the data buffer; earlier versions used an
14
+ # FFI::Function here that called back into Ruby, but Rubinius won't
15
+ # support that and there are issues with the other runtimes too
16
+ LibZMQ.zmq_msg_init_data @pointer, data_buffer, len, LibC::Free, nil
17
+ end
18
+ end
19
+ end
@@ -90,9 +90,9 @@ module LogjamAgent
90
90
  # Rails 5 fires on_load events multiple times, so we need to protect against endless recursion
91
91
  next if ActionController::TestCase::Behavior.instance_methods.include?(:process_without_logjam)
92
92
  module ActionController::TestCase::Behavior
93
- def process_with_logjam(*args)
93
+ def process_with_logjam(action, **opts)
94
94
  LogjamAgent.start_request
95
- process_without_logjam(*args)
95
+ process_without_logjam(action, **opts)
96
96
  ensure
97
97
  LogjamAgent.finish_request
98
98
  end
@@ -17,6 +17,7 @@ module LogjamAgent
17
17
  @uuid = LogjamAgent.generate_uuid
18
18
  @fields = initial_fields.merge(:request_id => @uuid, :host => LogjamAgent.hostname,
19
19
  :process_id => Process.pid, :lines => @lines)
20
+ @fields[:trace_id] ||= @uuid
20
21
  unless (revision = LogjamAgent.application_revision).blank?
21
22
  @fields[:revision] = revision
22
23
  end
@@ -70,6 +71,10 @@ module LogjamAgent
70
71
  @fields[:caller_action]
71
72
  end
72
73
 
74
+ def trace_id
75
+ @fields[:trace_id]
76
+ end
77
+
73
78
  def add_line(severity, timestamp, message)
74
79
  @mutex.synchronize do
75
80
  if @bytes_all_lines > @max_bytes_all_lines
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.32.1"
2
+ VERSION = "0.33.0"
3
3
  end
data/test/request_test.rb CHANGED
@@ -44,6 +44,16 @@ module LogjamAgent
44
44
  assert_equal TRUNCATED_LINE, lines(@request)[1][2]
45
45
  end
46
46
 
47
+ def test_sets_trace_id_to_request_id_if_not_passed_in
48
+ assert_equal @request.uuid, @request.fields[:trace_id]
49
+ end
50
+
51
+ def test_sets_trace_id_to_passed_in_field_value
52
+ trace_id = "murks"
53
+ request = Request.new("app", "env", {trace_id: trace_id})
54
+ assert_equal trace_id, request.fields[:trace_id]
55
+ end
56
+
47
57
  private
48
58
 
49
59
  def lines(request)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logjam_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.1
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2021-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -236,6 +236,7 @@ files:
236
236
  - lib/logjam_agent/buffered_logger.rb
237
237
  - lib/logjam_agent/forwarders.rb
238
238
  - lib/logjam_agent/middleware.rb
239
+ - lib/logjam_agent/monkey_patches/ffi-rzmq-patch.rb
239
240
  - lib/logjam_agent/rack/logger.rb
240
241
  - lib/logjam_agent/rack/rails_support.rb
241
242
  - lib/logjam_agent/rack/sinatra_request.rb
@@ -274,16 +275,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
275
  - !ruby/object:Gem::Version
275
276
  version: '0'
276
277
  requirements: []
277
- rubygems_version: 3.1.4
278
+ rubygems_version: 3.2.24
278
279
  signing_key:
279
280
  specification_version: 4
280
281
  summary: Logjam client library to be used with logjam
281
282
  test_files:
283
+ - test/request_test.rb
282
284
  - test/sinatra_app.rb
283
- - test/sinatra_classic_test.rb
284
285
  - test/sinatra_classic_app.rb
285
- - test/request_test.rb
286
- - test/zmq_forwarder_test.rb
287
- - test/util_test.rb
288
- - test/test_helper.rb
286
+ - test/sinatra_classic_test.rb
289
287
  - test/sinatra_test.rb
288
+ - test/test_helper.rb
289
+ - test/util_test.rb
290
+ - test/zmq_forwarder_test.rb