closeyourit-ruby 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8d2868773842804dc2c90f163ea4766ea748c59edf8adaa956f257827391e8c
4
- data.tar.gz: 7fe183c1a6c64226f341b09c7da4cd37bf58bb75409b9afc20c223efc55ffe1f
3
+ metadata.gz: 6dc227e626e4b47b931a80698aa8b2567bacb033dad2e5e42d6c8497890debe2
4
+ data.tar.gz: d012c3b1272b238e796ff7cdb1cf687276932a0c5196f14fbd0d5393edf9d938
5
5
  SHA512:
6
- metadata.gz: fc0267a4f038cd2ab3f6e0af119cacbdb368cdce3f4d07d2a01ea1b8b5f2d2c4f4753fed6d5dcc0b71c5826868c7557eab614d7b0f37f953fd586aff01147c1b
7
- data.tar.gz: 0b6e57599d21d07d4d2552331aa14d17bed514c7ed0733881d4a7ebd850051ca1271137fac7147f1e2d12c74c69e6e5e265017b256c36abf06ffd6342b458350
6
+ metadata.gz: c4cd8b4aaa3cb4ff246d2607d3f65ec71c696c37b8ccb9525979c99175bcf5f1c35f051574d034b8cb7198fb62362c2683e74e076989cf3e2ea3ae34408385a7
7
+ data.tar.gz: 0b54035901e710005c1cc45339a30f0df0277e0d0708c9faff417a536eba0000b77b2a2bbb9c7b608b8528b4ac04b65f7f16b31dbd8320ec1e2d37f9465db2a4
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "securerandom"
4
+ require "rack/utils"
4
5
 
5
6
  module CloseYourIt
6
7
  module Rails
@@ -12,6 +13,10 @@ module CloseYourIt
12
13
  # Header con prefisso non-HTTP_ in env Rack.
13
14
  RAW_HEADERS = %w[CONTENT_TYPE CONTENT_LENGTH].freeze
14
15
 
16
+ # Cookie di correlazione scritto dal browser SDK (session replay): id opaco della
17
+ # sessione di replay, trasportato da ogni richiesta same-origin.
18
+ REPLAY_COOKIE = "cyi_replay"
19
+
15
20
  def initialize(app)
16
21
  @app = app
17
22
  end
@@ -20,6 +25,9 @@ module CloseYourIt
20
25
  if enabled?
21
26
  # trace_id sempre (correlazione log↔errori), anche con capture_request OFF.
22
27
  CloseYourIt::Scope.current.trace_id = trace_id_for(env)
28
+ # Correlazione errore server ↔ session replay: l'id dal cookie finisce sullo scope
29
+ # → contexts.replay.replay_id dell'evento (stesso punto del percorso JS).
30
+ CloseYourIt::Scope.current.replay_session_id = replay_session_id_for(env)
23
31
  if CloseYourIt.configuration.capture_request
24
32
  CloseYourIt::Scope.current.request = build_request(env)
25
33
  # Riferimento all'env per l'estrazione LAZY del body (request.data) a evento costruito.
@@ -47,6 +55,14 @@ module CloseYourIt
47
55
  SecureRandom.uuid
48
56
  end
49
57
 
58
+ # Estrae `cyi_replay` dal cookie della richiesta (nil se assente). Rack puro.
59
+ def replay_session_id_for(env)
60
+ cookie = env["HTTP_COOKIE"]
61
+ return nil if cookie.nil? || cookie.empty?
62
+
63
+ Rack::Utils.parse_cookies_header(cookie)[REPLAY_COOKIE].to_s.then { |id| id.empty? ? nil : id }
64
+ end
65
+
50
66
  # Forma `request` Sentry. URL senza query string; header solo dall'allowlist (mai
51
67
  # Authorization/Cookie). query_string + IP solo con send_pii (opt-in).
52
68
  def build_request(env)
@@ -35,7 +35,7 @@ module CloseYourIt
35
35
  end
36
36
  end
37
37
 
38
- attr_accessor :request, :trace_id, :rack_env
38
+ attr_accessor :request, :trace_id, :rack_env, :replay_session_id
39
39
  attr_reader :user, :tags, :extra, :contexts, :breadcrumbs
40
40
 
41
41
  def initialize
@@ -80,6 +80,7 @@ module CloseYourIt
80
80
  @request = nil
81
81
  @rack_env = nil
82
82
  @trace_id = nil
83
+ @replay_session_id = nil
83
84
  @breadcrumbs = BreadcrumbBuffer.new(CloseYourIt.configuration.max_breadcrumbs)
84
85
  @performance_profile = nil
85
86
  end
@@ -93,7 +94,7 @@ module CloseYourIt
93
94
  "user" => serialize_user,
94
95
  "tags" => scrub(presence(@tags)),
95
96
  "extra" => scrub(presence(@extra)),
96
- "contexts" => scrub(presence(@contexts)),
97
+ "contexts" => contexts_payload,
97
98
  "request" => request_payload,
98
99
  "breadcrumbs" => breadcrumbs_payload
99
100
  }.reject { |_key, value| value.nil? }
@@ -101,6 +102,15 @@ module CloseYourIt
101
102
 
102
103
  private
103
104
 
105
+ # contexts utente + `replay.replay_id` (session replay) quando presente sullo scope: il
106
+ # backend legge contexts.replay.replay_id per legare l'errore server al video (stesso punto
107
+ # del percorso JS). replay/replay_id non sono chiavi sensibili → sopravvivono allo Scrubber.
108
+ def contexts_payload
109
+ merged = @contexts.dup
110
+ merged["replay"] = { "replay_id" => @replay_session_id } if @replay_session_id
111
+ scrub(presence(merged))
112
+ end
113
+
104
114
  # Redige i valori delle chiavi sensibili preservando la struttura (es. contexts.runtime resta
105
115
  # intatto, solo i valori sotto chiavi sensibili diventano [FILTERED]). Riusa lo Scrubber della
106
116
  # configurazione, lo stesso percorso di breadcrumb.data e degli attributi di log.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloseYourIt
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closeyourit-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessio Bussolari