txlemetry-ruby 4.0.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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +48 -0
  3. data/NOTICE +5 -0
  4. data/bin/txlemetry +110 -0
  5. data/lib/txlemetry/backoff_policy.rb +49 -0
  6. data/lib/txlemetry/client.rb +1266 -0
  7. data/lib/txlemetry/defaults.rb +50 -0
  8. data/lib/txlemetry/exception_capture.rb +246 -0
  9. data/lib/txlemetry/feature_flag.rb +85 -0
  10. data/lib/txlemetry/feature_flag_error.rb +37 -0
  11. data/lib/txlemetry/feature_flag_evaluations.rb +237 -0
  12. data/lib/txlemetry/feature_flag_result.rb +81 -0
  13. data/lib/txlemetry/feature_flags.rb +1516 -0
  14. data/lib/txlemetry/field_parser.rb +219 -0
  15. data/lib/txlemetry/flag_definition_cache.rb +88 -0
  16. data/lib/txlemetry/internal/context.rb +119 -0
  17. data/lib/txlemetry/logging.rb +77 -0
  18. data/lib/txlemetry/mcp/README.md +53 -0
  19. data/lib/txlemetry/mcp/analytics.rb +116 -0
  20. data/lib/txlemetry/mcp/client.rb +257 -0
  21. data/lib/txlemetry/mcp/constants.rb +111 -0
  22. data/lib/txlemetry/mcp/conversation_id.rb +89 -0
  23. data/lib/txlemetry/mcp/event_builder.rb +168 -0
  24. data/lib/txlemetry/mcp/exceptions.rb +112 -0
  25. data/lib/txlemetry/mcp/identity.rb +194 -0
  26. data/lib/txlemetry/mcp/ids.rb +56 -0
  27. data/lib/txlemetry/mcp/instrumentation.rb +736 -0
  28. data/lib/txlemetry/mcp/intent.rb +101 -0
  29. data/lib/txlemetry/mcp/log.rb +37 -0
  30. data/lib/txlemetry/mcp/options.rb +128 -0
  31. data/lib/txlemetry/mcp/rack_middleware.rb +112 -0
  32. data/lib/txlemetry/mcp/request_scope.rb +72 -0
  33. data/lib/txlemetry/mcp/sanitization.rb +504 -0
  34. data/lib/txlemetry/mcp/schema_mutation.rb +179 -0
  35. data/lib/txlemetry/mcp/server_extension.rb +54 -0
  36. data/lib/txlemetry/mcp/session.rb +71 -0
  37. data/lib/txlemetry/mcp/session_token.rb +106 -0
  38. data/lib/txlemetry/mcp/sink.rb +98 -0
  39. data/lib/txlemetry/mcp/tools.rb +91 -0
  40. data/lib/txlemetry/mcp/tracking_data.rb +89 -0
  41. data/lib/txlemetry/mcp/truncation.rb +326 -0
  42. data/lib/txlemetry/mcp.rb +224 -0
  43. data/lib/txlemetry/message_batch.rb +80 -0
  44. data/lib/txlemetry/noop_worker.rb +39 -0
  45. data/lib/txlemetry/response.rb +17 -0
  46. data/lib/txlemetry/send_feature_flags_options.rb +49 -0
  47. data/lib/txlemetry/send_worker.rb +218 -0
  48. data/lib/txlemetry/transport.rb +216 -0
  49. data/lib/txlemetry/utils.rb +183 -0
  50. data/lib/txlemetry/version.rb +5 -0
  51. data/lib/txlemetry.rb +16 -0
  52. metadata +105 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9604f1e77490345c7ead375c8ddcef3af341ff63a0adad91e346bc0aea5320b9
4
+ data.tar.gz: e00630e949040fdff6934dee20dbb1192c7d1b4d31e2b0d7fa3ca12ae864bd91
5
+ SHA512:
6
+ metadata.gz: c99192202aa60052535d08410efeb462909c03249c8b25062089214741ba01154e8a70c0845c9b789bd4c22dc87dc88193e524dc3542a4458bf9fa0e768398af
7
+ data.tar.gz: 977da1fdfe5d43f6f6ecf81785a806cf603c13fa952eaad667b7a44952aa6c4453551e5e8b7aad648afb64f1c8c28ecb2b104e4b8c2b350a017e5931012fbc08
data/LICENSE ADDED
@@ -0,0 +1,48 @@
1
+ Copyright (c) 2025 PostHog (part of Hiberly Inc)
2
+
3
+ Copyright (c) 2013 Segment Inc. friends@segment.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Some files in this codebase contain code from getsentry/sentry-ruby.
26
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
27
+
28
+ The MIT License (MIT)
29
+
30
+ Copyright (c) 2020 Sentry
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining a copy
33
+ of this software and associated documentation files (the "Software"), to deal
34
+ in the Software without restriction, including without limitation the rights
35
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
+ copies of the Software, and to permit persons to whom the Software is
37
+ furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in
40
+ all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
48
+ THE SOFTWARE.
data/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ Txlemetry ruby SDK sources
2
+ Derived from https://github.com/PostHog/posthog-ruby, tag posthog-rails-v3.18.9, commit 820d4bfe8aa3fb3284c4fdf3fb356530340e1c7a.
3
+ Original license files and author notices are retained.
4
+ Public names, package identity, default hosts and distribution are maintained for Txlemetry.
5
+ Candidate source migration and validation are in progress; no release has been published.
data/bin/txlemetry ADDED
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'txlemetry'
5
+ require 'rubygems'
6
+ require 'commander/import'
7
+ require 'time'
8
+ require 'json'
9
+
10
+ program :name, 'txlemetry'
11
+ program :version, '1.0.0'
12
+ program :description, 'Txlemetry API'
13
+
14
+ def json_hash(str)
15
+ JSON.parse(str) if str
16
+ end
17
+
18
+ command :capture do |c|
19
+ c.description = 'capture an event'
20
+
21
+ c.option '--api-key=<string>', String, 'The Txlemetry API Key'
22
+ c.option '--api-host=<url>',
23
+ String,
24
+ 'The Txlemetry API URL host part (scheme+domain)'
25
+ c.option '--distinct-id=<distinct_id>',
26
+ String,
27
+ 'The distinct id to send the event as'
28
+ c.option '--event=<event>', String, 'The event name to send with the event'
29
+ c.option '--properties=<properties>', 'The properties to send (JSON-encoded)'
30
+
31
+ c.action do |_args, options|
32
+ txlemetry =
33
+ Txlemetry::Client.new(
34
+ {
35
+ api_key: options.api_key,
36
+ api_host: options.api_host,
37
+ on_error: proc { |_status, msg| print msg }
38
+ }
39
+ )
40
+
41
+ txlemetry.capture(
42
+ {
43
+ distinct_id: options.distinct_id,
44
+ event: options.event,
45
+ properties: json_hash(options.properties)
46
+ }
47
+ )
48
+
49
+ txlemetry.flush
50
+ end
51
+ end
52
+
53
+ command :identify do |c|
54
+ c.description = 'identify the user'
55
+
56
+ c.option '--api-key=<api_key>', String, 'The Txlemetry API Key'
57
+ c.option '--api-host=<url>',
58
+ String,
59
+ 'The Txlemetry API URL host part (scheme+domain)'
60
+ c.option '--distinct-id=<distinct_id>',
61
+ String,
62
+ 'The distinct id to send the event as'
63
+ c.option '--properties=<properties>', 'The properties to send (JSON-encoded)'
64
+
65
+ c.action do |_args, options|
66
+ txlemetry =
67
+ Txlemetry::Client.new(
68
+ {
69
+ api_key: options.api_key,
70
+ api_host: options.api_host,
71
+ on_error: proc { |_status, msg| print msg }
72
+ }
73
+ )
74
+
75
+ txlemetry.identify(
76
+ {
77
+ distinct_id: options.distinct_id,
78
+ properties: json_hash(options.properties)
79
+ }
80
+ )
81
+
82
+ txlemetry.flush
83
+ end
84
+ end
85
+
86
+ command :alias do |c|
87
+ c.description = 'set an alias for a distinct id'
88
+
89
+ c.option '--api-key=<api_key>', String, 'The Txlemetry API Key'
90
+ c.option '--api-host=<url>',
91
+ String,
92
+ 'The Txlemetry API URL host part (scheme+domain)'
93
+ c.option '--distinct-id=<distinct_id>', String, 'The distinct id'
94
+ c.option '--alias=<alias>', 'The alias to give to the distinct id'
95
+
96
+ c.action do |_args, options|
97
+ txlemetry =
98
+ Txlemetry::Client.new(
99
+ {
100
+ api_key: options.api_key,
101
+ api_host: options.api_host,
102
+ on_error: proc { |_status, msg| print msg }
103
+ }
104
+ )
105
+
106
+ txlemetry.alias({ distinct_id: options.distinct_id, alias: options.alias })
107
+
108
+ txlemetry.flush
109
+ end
110
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'txlemetry/defaults'
4
+
5
+ module Txlemetry
6
+ # Retry backoff policy used by the SDK transport.
7
+ #
8
+ # @api private
9
+ class BackoffPolicy
10
+ include Txlemetry::Defaults::BackoffPolicy
11
+
12
+ # @param opts [Hash]
13
+ # @option opts [Numeric] :min_timeout_ms The minimum backoff timeout
14
+ # @option opts [Numeric] :max_timeout_ms The maximum backoff timeout
15
+ # @option opts [Numeric] :multiplier The value to multiply the current
16
+ # interval with for each retry attempt
17
+ # @option opts [Numeric] :randomization_factor The randomization factor
18
+ # to use to create a range around the retry interval
19
+ def initialize(opts = {})
20
+ @min_timeout_ms = opts[:min_timeout_ms] || MIN_TIMEOUT_MS
21
+ @max_timeout_ms = opts[:max_timeout_ms] || MAX_TIMEOUT_MS
22
+ @multiplier = opts[:multiplier] || MULTIPLIER
23
+ @randomization_factor =
24
+ opts[:randomization_factor] || RANDOMIZATION_FACTOR
25
+
26
+ @attempts = 0
27
+ end
28
+
29
+ # @return [Numeric] the next backoff interval, in milliseconds.
30
+ def next_interval
31
+ interval = @min_timeout_ms * (@multiplier**@attempts)
32
+ interval = add_jitter(interval, @randomization_factor)
33
+
34
+ @attempts += 1
35
+
36
+ interval.clamp(@min_timeout_ms, @max_timeout_ms)
37
+ end
38
+
39
+ private
40
+
41
+ def add_jitter(base, randomization_factor)
42
+ random_number = rand
43
+ max_deviation = base * randomization_factor
44
+ deviation = random_number * max_deviation
45
+
46
+ random_number < 0.5 ? base - deviation : base + deviation
47
+ end
48
+ end
49
+ end