statsig 1.33.4 → 1.34.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: 6b2947b68bfada4686360dc5aab60a460129a3ca5e4c63d6f2107af68788d2a8
4
- data.tar.gz: 98e56828d1f31ec18afc0a2f46dbcab90c2a976dc95ef1db9ead5060b240952f
3
+ metadata.gz: 5311f827891ea6c944353e8752587e9fe81806d4fef1bc8a44f3f190b6b1538c
4
+ data.tar.gz: d6136d7dce23ae5533594513934581ed4ee6aca9325cca24e989dc22057d7293
5
5
  SHA512:
6
- metadata.gz: e1f11434fb5ec030500429cdfd11146fe845568498cded4917e1f412ca50a86beb03f937febcaeceaf8523dacaa550b9024384dc58b0b3c9b2619d37041e0df0
7
- data.tar.gz: d64fd8980ca648626ecdcd0095d4964aa531d24d7acaa7c07dd70013a32d0f7c5c548602e9578044c0567c0c2ac948f5dd8bd499c2178323b0ae176d0925a82c
6
+ metadata.gz: dc5efa1c0a0a8d14536685c9ebe9074fa2d705f34bc37729f028b156f7e7c9f8a6e86ea322a55855c6eb434fdf0778a4ddfc548a8c31cc8c7c4bbbc9e929e1d3
7
+ data.tar.gz: 0666ebec091e17d2f5321fb46071b05d3872c303857e79747a2d01694573b0c187732f43089a9826c1c3041b7024c89379702c5fc5562debd13a50a6b5cda6b1
@@ -26,9 +26,7 @@ module Statsig
26
26
  return res
27
27
  end
28
28
 
29
- private
30
-
31
- def log_exception(exception, tag: nil)
29
+ def log_exception(exception, tag: nil, extra: {})
32
30
  name = exception.class.name
33
31
  if @seen.include?(name)
34
32
  return
@@ -51,7 +49,8 @@ module Statsig
51
49
  'message' => exception.message
52
50
  }.to_s,
53
51
  'statsigMetadata' => meta,
54
- 'tag' => tag
52
+ 'tag' => tag,
53
+ 'extra' => extra
55
54
  }
56
55
  http.post($endpoint, body: JSON.generate(body))
57
56
  rescue StandardError
data/lib/evaluator.rb CHANGED
@@ -201,6 +201,9 @@ module Statsig
201
201
  if @spec_store.is_ready_for_checks == false
202
202
  return nil
203
203
  end
204
+ if @spec_store.last_config_sync_time == 0
205
+ return nil
206
+ end
204
207
 
205
208
  evaluated_keys = {}
206
209
  if user.user_id.nil? == false
@@ -209,8 +212,8 @@ module Statsig
209
212
 
210
213
  if user.custom_ids.nil? == false
211
214
  evaluated_keys[:customIDs] = user.custom_ids
212
- end
213
-
215
+ end
216
+ meta = Statsig.get_statsig_metadata
214
217
  {
215
218
  feature_gates: Statsig::ResponseFormatter
216
219
  .get_responses(@spec_store.gates, self, user, client_sdk_key, hash_algo, include_local_overrides: include_local_overrides),
@@ -222,9 +225,10 @@ module Statsig
222
225
  has_updates: true,
223
226
  generator: Const::STATSIG_RUBY_SDK,
224
227
  evaluated_keys: evaluated_keys,
225
- time: 0,
228
+ time: @spec_store.last_config_sync_time,
226
229
  hash_used: hash_algo,
227
- user_hash: user.to_hash_without_stable_id
230
+ user: user.serialize(false),
231
+ sdkInfo: {sdkType: meta["sdkType"], sdkVersion: meta["sdkVersion"]},
228
232
  }
229
233
  end
230
234
 
data/lib/network.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'http'
2
2
  require 'json'
3
3
  require 'securerandom'
4
+ require 'zlib'
4
5
 
5
6
  require 'uri_helper'
6
7
  require 'connection_pool'
@@ -58,11 +59,11 @@ module Statsig
58
59
  request(:GET, endpoint, nil, retries, backoff)
59
60
  end
60
61
 
61
- def post(endpoint, body, retries = 0, backoff = 1)
62
- request(:POST, endpoint, body, retries, backoff)
62
+ def post(endpoint, body, retries = 0, backoff = 1, zipped = false)
63
+ request(:POST, endpoint, body, retries, backoff, zipped)
63
64
  end
64
65
 
65
- def request(method, endpoint, body, retries = 0, backoff = 1)
66
+ def request(method, endpoint, body, retries = 0, backoff = 1, zipped = false)
66
67
  if @local_mode
67
68
  return nil, nil
68
69
  end
@@ -78,7 +79,7 @@ module Statsig
78
79
  url = URIHelper.build_url(endpoint)
79
80
  begin
80
81
  res = @connection_pool.with do |conn|
81
- request = conn.headers('STATSIG-CLIENT-TIME' => (Time.now.to_f * 1000).to_i.to_s)
82
+ request = conn.headers('STATSIG-CLIENT-TIME' => (Time.now.to_f * 1000).to_i.to_s, 'CONTENT-ENCODING' => zipped ? 'gzip' : nil)
82
83
  case method
83
84
  when :GET
84
85
  request.get(url)
@@ -91,7 +92,7 @@ module Statsig
91
92
  return nil, e unless retries.positive?
92
93
 
93
94
  sleep backoff_adjusted
94
- return request(method, endpoint, body, retries - 1, backoff * @backoff_multiplier)
95
+ return request(method, endpoint, body, retries - 1, backoff * @backoff_multiplier, zipped)
95
96
  end
96
97
  return res, nil if res.status.success?
97
98
 
@@ -102,12 +103,14 @@ module Statsig
102
103
 
103
104
  ## status code retry
104
105
  sleep backoff_adjusted
105
- request(method, endpoint, body, retries - 1, backoff * @backoff_multiplier)
106
+ request(method, endpoint, body, retries - 1, backoff * @backoff_multiplier, zipped)
106
107
  end
107
108
 
108
109
  def post_logs(events)
109
110
  json_body = JSON.generate({ events: events, statsigMetadata: Statsig.get_statsig_metadata })
110
- post('log_event', json_body, @post_logs_retry_limit)
111
+ gzip = Zlib::GzipWriter.new(StringIO.new)
112
+ gzip << json_body
113
+ post('log_event', gzip.close.string, @post_logs_retry_limit, 1, true)
111
114
  rescue StandardError
112
115
 
113
116
  end
data/lib/statsig.rb CHANGED
@@ -363,7 +363,7 @@ module Statsig
363
363
  def self.get_statsig_metadata
364
364
  {
365
365
  'sdkType' => 'ruby-server',
366
- 'sdkVersion' => '1.33.4',
366
+ 'sdkVersion' => '1.34.0',
367
367
  'languageVersion' => RUBY_VERSION
368
368
  }
369
369
  end
@@ -56,7 +56,7 @@ class StatsigDriver
56
56
  return FeatureGate.new(gate_name) if gate.nil?
57
57
  return FeatureGate.new(gate.name, target_app_ids: gate.target_app_ids)
58
58
  end
59
-
59
+
60
60
  user = verify_inputs(user, gate_name, 'gate_name')
61
61
  return Statsig::Memo.for(user.get_memo(), :get_gate_impl, gate_name) do
62
62
 
@@ -87,7 +87,7 @@ class StatsigDriver
87
87
 
88
88
  def check_gate(user, gate_name, options = nil)
89
89
  @err_boundary.capture(caller: __method__, recover: -> {false}) do
90
- run_with_diagnostics(caller: :check_gate) do
90
+ run_with_diagnostics(caller: :check_gate) do
91
91
  get_gate_impl(
92
92
  user,
93
93
  gate_name,
@@ -309,7 +309,11 @@ class StatsigDriver
309
309
  @err_boundary.capture(caller: __method__, recover: -> { nil }) do
310
310
  validate_user(user)
311
311
  normalize_user(user)
312
- @evaluator.get_client_initialize_response(user, hash, client_sdk_key, include_local_overrides)
312
+ response = @evaluator.get_client_initialize_response(user, hash, client_sdk_key, include_local_overrides)
313
+ if response.nil?
314
+ @err_boundary.log_exception(Statsig::ValueError.new('Failed to get client initialize response'), tag: 'getClientInitializeResponse', extra: {hash: hash, clientKey: client_sdk_key})
315
+ end
316
+ response
313
317
  end
314
318
  end
315
319
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.33.4
4
+ version: 1.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Statsig, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -288,6 +288,20 @@ dependencies:
288
288
  - - "~>"
289
289
  - !ruby/object:Gem::Version
290
290
  version: '1.1'
291
+ - !ruby/object:Gem::Dependency
292
+ name: zlib
293
+ requirement: !ruby/object:Gem::Requirement
294
+ requirements:
295
+ - - "~>"
296
+ - !ruby/object:Gem::Version
297
+ version: 3.1.0
298
+ type: :runtime
299
+ prerelease: false
300
+ version_requirements: !ruby/object:Gem::Requirement
301
+ requirements:
302
+ - - "~>"
303
+ - !ruby/object:Gem::Version
304
+ version: 3.1.0
291
305
  description: Statsig server SDK for feature gates and experimentation in Ruby
292
306
  email: support@statsig.com
293
307
  executables: []