posthog-ruby 3.35.3 → 3.35.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fed46c74a26496136d6908703f3f192ce91837e9f502fb02deaf83b5354232a
4
- data.tar.gz: 5ced8452e1f1af068a6f77af09a62cec70e688e5522299f31abbc1a2b0bcf76f
3
+ metadata.gz: ca76b03cf9cdedacc3fc41f55b03b28798b0f59c8a01fa11faa41de546b62c69
4
+ data.tar.gz: 626d764865453ddc624e5162b7b569357c620ff1a490befa401ba723d0f4269b
5
5
  SHA512:
6
- metadata.gz: 0515cd1eac8cc9ea97969f6cdeb7476ca2e3cbed7001a70de3328fded754c5480c63676006754d62dda2d3c4e436f647b7dad49cdde19d004631890fb7fcb498
7
- data.tar.gz: 0a51664f44f72c80270a6a8e4efab20111541191c6a8d33f0d04370df197777acef808105cddf00f12f6f04dc92a3e763f610af801a963ceee093c68bff2dfbc
6
+ metadata.gz: 2e47a74d83e5226ade1d686670a93ebda829894c74850efc23f0112a22b63666eeda41df1cd9c09aaa445d4e48454c2e263d95832b30339bef0a638edeecae7d
7
+ data.tar.gz: f02e2e8188e821ddf662f2ea539889a5c34a403deb9ee9d8c1cd6a29325483607f7338762f5d8e96804518126df6dd2d860c72b53903460903dae2748609da2d
@@ -262,8 +262,8 @@ module PostHog
262
262
  # @return [PostHog::Emails]
263
263
  attr_reader :emails
264
264
 
265
- # When sync_mode is enabled, blocks until in-flight requests are complete
266
- # and returns true. Timeout parameter has no effect.
265
+ # When sync_mode is enabled, waits until any in-flight request completes or
266
+ # timeout is hit.
267
267
  #
268
268
  # Otherwise, waits until the worker has cleared the queue or timeout is hit.
269
269
  # Note: The asynchronous wait polls and can be starved if another thread is
@@ -274,19 +274,14 @@ module PostHog
274
274
  # @return [Boolean] +true+ if all pending events were sent, +false+ if the
275
275
  # timeout elapsed first.
276
276
  def flush(timeout: nil)
277
- if @sync_mode
278
- # Wait for any in-flight sync send to complete
279
- @sync_lock.synchronize {} # rubocop:disable Lint/EmptyBlock
280
- return true
281
- end
277
+ deadline = timeout && (monotonic_time + timeout)
278
+ return synchronized_within?(deadline) {} if @sync_mode # rubocop:disable Lint/EmptyBlock
282
279
 
283
280
  if @worker.is_a?(NoopWorker)
284
281
  clear
285
282
  return true
286
283
  end
287
284
 
288
- deadline = timeout && (monotonic_time + timeout)
289
-
290
285
  while !@queue.empty? || @worker.is_requesting?
291
286
  ensure_worker_running
292
287
  @worker.request_flush
@@ -965,9 +960,11 @@ module PostHog
965
960
  # sent. After the timeout, this method may wait up to one additional second
966
961
  # for worker and transport cleanup, which may continue after it returns.
967
962
  #
963
+ # When sync_mode is set and the timeout elapses while a request is in
964
+ # flight, the connection is closed once that request completes.
965
+ #
968
966
  # @param timeout [Numeric, nil] Maximum seconds to wait for pending events
969
- # to be sent, or +nil+ to wait indefinitely. Has no effect when sync_mode
970
- # is true.
967
+ # to be sent, or +nil+ to wait indefinitely.
971
968
  # @return [Boolean] +true+ if all pending events were sent, +false+ if the
972
969
  # timeout elapsed first.
973
970
  def shutdown(timeout: nil)
@@ -1000,8 +997,9 @@ module PostHog
1000
997
  if @sync_mode
1001
998
  # Waiting for @sync_lock lets any in-flight sync send finish before
1002
999
  # the connection is closed.
1003
- @sync_lock.synchronize { @transport&.shutdown }
1004
- true
1000
+ closed = synchronized_within?(deadline) { @transport&.shutdown }
1001
+ Thread.new { @sync_lock.synchronize { @transport&.shutdown } } unless closed
1002
+ closed
1005
1003
  else
1006
1004
  drained = flush(timeout: timeout)
1007
1005
  @worker&.shutdown
@@ -1316,6 +1314,30 @@ module PostHog
1316
1314
  end
1317
1315
  end
1318
1316
 
1317
+ # Mutex has no timed lock, so a deadline polls try_lock.
1318
+ def synchronized_within?(deadline, &)
1319
+ unless deadline
1320
+ @sync_lock.synchronize(&)
1321
+ return true
1322
+ end
1323
+ return false if @sync_lock.owned?
1324
+
1325
+ locked = false
1326
+ begin
1327
+ # Deferring interrupts until locked is set keeps the ensure from missing a held lock.
1328
+ until Thread.handle_interrupt(Object => :never) { locked = @sync_lock.try_lock }
1329
+ remaining = deadline - monotonic_time
1330
+ return false if remaining <= 0
1331
+
1332
+ sleep(remaining.clamp(0, 0.01))
1333
+ end
1334
+ yield
1335
+ true
1336
+ ensure
1337
+ @sync_lock.unlock if locked
1338
+ end
1339
+ end
1340
+
1319
1341
  def worker_running?
1320
1342
  @worker_thread&.alive?
1321
1343
  end
@@ -49,7 +49,7 @@ module PostHog
49
49
  if defined?(::Rails)
50
50
  ::Rails.logger
51
51
  else
52
- logger = Logger.new $stdout
52
+ logger = Logger.new $stderr
53
53
  logger.progname = 'PostHog'
54
54
  logger.level = Logger::WARN
55
55
  logger
@@ -32,8 +32,9 @@ These are the few things that differ from what the docs describe for the other S
32
32
  * **Composed schemas are left alone.** A tool whose `input_schema` is `oneOf`/`allOf`/`anyOf` or a
33
33
  `$ref` has nothing injected into it and nothing stripped from its calls.
34
34
  * **stdio servers own `$stdout`.** The integration's own messages go only to the `logger:` you pass
35
- (default: nowhere); the experimental notice and misconfiguration warnings go to stderr. Point the
36
- core SDK's logger away from stdout too: `PostHog::Logging.logger = Logger.new($stderr)`.
35
+ (default: nowhere). The experimental notice goes to stderr, and outside Rails so do misconfiguration
36
+ warnings and the core SDK's default logger. Under Rails, warnings and SDK errors go to `Rails.logger`,
37
+ so keep it (and any custom `PostHog::Logging.logger`) off stdout.
37
38
 
38
39
  ## Layout
39
40
 
@@ -5,8 +5,8 @@ module PostHog
5
5
  # Logging for the MCP integration.
6
6
  #
7
7
  # Debug-level chatter goes only to the `logger:` option (a no-op by default),
8
- # because a stdio MCP server owns `$stdout` for the protocol and the core
9
- # SDK's default logger writes there. Warnings additionally reach the app's
8
+ # because a stdio MCP server owns `$stdout` for the protocol and an
9
+ # app-configured logger may write there. Warnings additionally reach the app's
10
10
  # logger when Rails is loaded (where {PostHog::Logging.logger} wraps
11
11
  # `Rails.logger`) and stderr otherwise, so misconfiguration is never silent
12
12
  # and never corrupts a stdio transport.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.35.3'
4
+ VERSION = '3.35.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.35.3
4
+ version: 3.35.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - PostHog