posthog-ruby 3.42.0 → 3.43.0
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 +4 -4
- data/lib/posthog/client.rb +77 -9
- data/lib/posthog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a791a6ebcdb4519473dbb91fd1b37022551c77b35bd14693ca24f80dfb355ab
|
|
4
|
+
data.tar.gz: 49f1cb8b7a7b0c3a342ef07116e56fba635fcabdda17e9e44a39a223c2be1214
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1bbe084dd4402912361700172d64969f6160fda2b832ff1e7d4368fa41eeddc07277c8ef0a3542a24411aab4acb4b6e02b70c28a47614588656ab52062d424f9
|
|
7
|
+
data.tar.gz: a01be3bb9446f1739000a2178810c8546d6bfc1df60f89a6e729062d9c3c17fd6e008988436c0d12b5857171ef665979de30d0b24a0e97962a4ae126f1bc9f42
|
data/lib/posthog/client.rb
CHANGED
|
@@ -139,6 +139,16 @@ module PostHog
|
|
|
139
139
|
# @option opts [Boolean] :is_server +true+ to stamp captured events with `$is_server => true` so PostHog
|
|
140
140
|
# attributes them as server-side. Defaults to +true+. Set to +false+ when running posthog-ruby as a
|
|
141
141
|
# client/CLI so the device OS is attributed normally and `$is_server` is omitted.
|
|
142
|
+
# @option opts [Hash] :error_tracking Error tracking configuration. +:release+ is the release that
|
|
143
|
+
# `$exception` events report, as one of two forms:
|
|
144
|
+
# - +{ id: release_id }+, the id that `posthog-cli release resolve` prints.
|
|
145
|
+
# - +{ name: name, version: version, build: build }+, the `--release-name`, `--release-version`
|
|
146
|
+
# and optional `--build` that the release was created with. A Git commit SHA can be the version.
|
|
147
|
+
# The release must already exist in the project, because this option does not create it. Values are
|
|
148
|
+
# strings, and surrounding whitespace is trimmed. An option that matches neither form is ignored with a
|
|
149
|
+
# warning. A release that the exception or the request context already sets has precedence over this
|
|
150
|
+
# option, and this option has precedence over +POSTHOG_RELEASE_ID+. Other events do not get it.
|
|
151
|
+
# e.g. `error_tracking: { release: { name: 'my-app', version: ENV.fetch('GIT_SHA') } }`.
|
|
142
152
|
def initialize(opts = {})
|
|
143
153
|
symbolize_keys!(opts)
|
|
144
154
|
|
|
@@ -251,7 +261,9 @@ module PostHog
|
|
|
251
261
|
|
|
252
262
|
@before_send = opts[:before_send]
|
|
253
263
|
@is_server = opts.fetch(:is_server, true) != false
|
|
254
|
-
|
|
264
|
+
release_id = normalize_string_option(ENV.fetch(RELEASE_ID_ENV_VAR, nil), blank_as_nil: true)
|
|
265
|
+
@env_release_properties = ({ '$release_id' => release_id }.freeze if release_id)
|
|
266
|
+
@error_tracking_release_properties = error_tracking_release_properties(opts[:error_tracking])
|
|
255
267
|
@deprecation_emitted_for = Concurrent::Set.new
|
|
256
268
|
end
|
|
257
269
|
|
|
@@ -1304,8 +1316,8 @@ module PostHog
|
|
|
1304
1316
|
def enqueue(action)
|
|
1305
1317
|
return false if @disabled || shutdown?
|
|
1306
1318
|
|
|
1307
|
-
# Every event type passes through here, and before_send still sees the
|
|
1308
|
-
action =
|
|
1319
|
+
# Every event type passes through here, and before_send still sees the release.
|
|
1320
|
+
action = add_release(action)
|
|
1309
1321
|
action = process_before_send(action)
|
|
1310
1322
|
return false if action.nil? || action.empty?
|
|
1311
1323
|
|
|
@@ -1334,15 +1346,71 @@ module PostHog
|
|
|
1334
1346
|
end
|
|
1335
1347
|
end
|
|
1336
1348
|
|
|
1337
|
-
# A `$release_id` the caller or the request context
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1349
|
+
# A `$release_id` key that the caller or the request context set wins on every event, even with a nil
|
|
1350
|
+
# value. An exception also keeps app properties that name a release. Otherwise an exception gets the
|
|
1351
|
+
# `error_tracking` release, and any event gets the POSTHOG_RELEASE_ID release. An exception with an
|
|
1352
|
+
# `error_tracking` name and version does not also get the env id, because Cymbal reads `$release_id`
|
|
1353
|
+
# before the app properties.
|
|
1354
|
+
def add_release(action)
|
|
1341
1355
|
properties = action[:properties]
|
|
1342
1356
|
return action unless properties.is_a?(Hash)
|
|
1343
|
-
return action if properties.key?('$release_id') || properties.key?(:$release_id)
|
|
1344
1357
|
|
|
1345
|
-
action
|
|
1358
|
+
exception = action[:event] == '$exception'
|
|
1359
|
+
release = (@error_tracking_release_properties if exception) || @env_release_properties
|
|
1360
|
+
return action if release.nil?
|
|
1361
|
+
return action if property_key?(properties, '$release_id')
|
|
1362
|
+
return action if exception && app_release_set?(properties)
|
|
1363
|
+
|
|
1364
|
+
# Replaces a symbol key with the string key, because json 3 refuses to serialize both.
|
|
1365
|
+
action.merge(properties: Internal::Context.merge_properties(properties, release))
|
|
1366
|
+
end
|
|
1367
|
+
|
|
1368
|
+
# Without `$release_id`, Cymbal finds the release from `$app_namespace` with `$app_version` or `$app_build`.
|
|
1369
|
+
def app_release_set?(properties)
|
|
1370
|
+
property_set?(properties, '$app_namespace') &&
|
|
1371
|
+
(property_set?(properties, '$app_version') || property_set?(properties, '$app_build'))
|
|
1372
|
+
end
|
|
1373
|
+
|
|
1374
|
+
def property_set?(properties, key)
|
|
1375
|
+
!properties[key].nil? || !properties[key.to_sym].nil?
|
|
1376
|
+
end
|
|
1377
|
+
|
|
1378
|
+
# Returns the properties that the `error_tracking` release adds to an exception, or nil.
|
|
1379
|
+
def error_tracking_release_properties(error_tracking)
|
|
1380
|
+
release = error_tracking.is_a?(Hash) ? symbolize_keys(error_tracking)[:release] : error_tracking
|
|
1381
|
+
return nil if release.nil?
|
|
1382
|
+
|
|
1383
|
+
properties = release_properties(release) if release.is_a?(Hash)
|
|
1384
|
+
if properties.nil?
|
|
1385
|
+
logger.warn(
|
|
1386
|
+
'Ignoring the error_tracking option: give it as { release: { id: release_id } } or as ' \
|
|
1387
|
+
'{ release: { name: name, version: version } } with an optional build, with non-blank string values.'
|
|
1388
|
+
)
|
|
1389
|
+
end
|
|
1390
|
+
properties
|
|
1391
|
+
end
|
|
1392
|
+
|
|
1393
|
+
def release_properties(release)
|
|
1394
|
+
id, name, version, build = symbolize_keys(release).values_at(:id, :name, :version, :build)
|
|
1395
|
+
if id.nil?
|
|
1396
|
+
name = release_value(name)
|
|
1397
|
+
version = release_value(version)
|
|
1398
|
+
return nil if name.nil? || version.nil? || !(build.nil? || build.is_a?(String))
|
|
1399
|
+
|
|
1400
|
+
properties = { '$app_namespace' => name, '$app_version' => version }
|
|
1401
|
+
build = release_value(build)
|
|
1402
|
+
properties['$app_build'] = build if build
|
|
1403
|
+
properties.freeze
|
|
1404
|
+
else
|
|
1405
|
+
id = release_value(id)
|
|
1406
|
+
return nil if id.nil? || !name.nil? || !version.nil? || !build.nil?
|
|
1407
|
+
|
|
1408
|
+
{ '$release_id' => id }.freeze
|
|
1409
|
+
end
|
|
1410
|
+
end
|
|
1411
|
+
|
|
1412
|
+
def release_value(value)
|
|
1413
|
+
normalize_string_option(value, blank_as_nil: true) if value.is_a?(String)
|
|
1346
1414
|
end
|
|
1347
1415
|
|
|
1348
1416
|
def normalize_string_option(value, blank_as_nil: false)
|
data/lib/posthog/version.rb
CHANGED