Skip to content

Commit 620047f

Browse files
authored
Always include scope user data in telemetry (#2866)
1 parent df6c90c commit 620047f

File tree

5 files changed

+16
-68
lines changed

5 files changed

+16
-68
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
- Fix `MetricEvent` timestamp serialization to float ([#2862](https://github.com/getsentry/sentry-ruby/pull/2862))
3030
- Fix CGI imports for ruby 4.x ([#2863](https://github.com/getsentry/sentry-ruby/pull/2863))
31+
- Always include scope user data in telemetry ([#2866](https://github.com/getsentry/sentry-ruby/pull/2866))
3132

3233
## 6.3.1
3334

sentry-ruby/lib/sentry/scope.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def apply_to_telemetry(telemetry)
9898
telemetry.attributes["sentry.release"] ||= configuration.release if configuration.release
9999
telemetry.attributes["server.address"] ||= configuration.server_name if configuration.server_name
100100

101-
if configuration.send_default_pii && !user.empty?
101+
unless user.empty?
102102
telemetry.attributes["user.id"] ||= user[:id] if user[:id]
103103
telemetry.attributes["user.name"] ||= user[:username] if user[:username]
104104
telemetry.attributes["user.email"] ||= user[:email] if user[:email]

sentry-ruby/spec/sentry/metric_event_spec.rb

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -134,32 +134,12 @@
134134
end
135135

136136
context "with user data" do
137-
context "when send_default_pii is true" do
138-
before do
139-
Sentry.configuration.send_default_pii = true
140-
end
141-
142-
it "includes user.id attribute" do
143-
hash = metric_event_scope_applied.to_h
144-
145-
expect(hash[:attributes]["user.id"]).to eq({ type: "string", value: "123" })
146-
expect(hash[:attributes]["user.name"]).to eq({ type: "string", value: "jane" })
147-
expect(hash[:attributes]["user.email"]).to eq({ type: "string", value: "jane.doe@email.com" })
148-
end
149-
end
150-
151-
context "when send_default_pii is false" do
152-
before do
153-
Sentry.configuration.send_default_pii = false
154-
end
155-
156-
it "does not include user attributes" do
157-
hash = metric_event_scope_applied.to_h
137+
it "includes user.id attribute" do
138+
hash = metric_event_scope_applied.to_h
158139

159-
expect(hash[:attributes].key?("user.id")).to eq(false)
160-
expect(hash[:attributes].key?("user.name")).to eq(false)
161-
expect(hash[:attributes].key?("user.email")).to eq(false)
162-
end
140+
expect(hash[:attributes]["user.id"]).to eq({ type: "string", value: "123" })
141+
expect(hash[:attributes]["user.name"]).to eq({ type: "string", value: "jane" })
142+
expect(hash[:attributes]["user.email"]).to eq({ type: "string", value: "jane.doe@email.com" })
163143
end
164144
end
165145
end

sentry-ruby/spec/sentry/metrics_spec.rb

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -174,38 +174,17 @@
174174
end
175175
end
176176

177-
context "when send_default_pii is true" do
178-
before do
179-
Sentry.configuration.send_default_pii = true
180-
end
181-
182-
it "includes user attributes in the metric" do
183-
Sentry.metrics.count("test.counter")
184-
185-
Sentry.get_current_client.flush
186-
187-
metric = sentry_metrics.first
188-
attributes = metric[:attributes]
189-
190-
expect(attributes["user.id"]).to eq({ type: "integer", value: 123 })
191-
expect(attributes["user.name"]).to eq({ type: "string", value: "jane" })
192-
expect(attributes["user.email"]).to eq({ type: "string", value: "jane@example.com" })
193-
end
194-
end
195-
196-
context "when send_default_pii is false" do
197-
it "does not include user attributes" do
198-
Sentry.metrics.count("test.counter")
177+
it "includes user attributes in the metric" do
178+
Sentry.metrics.count("test.counter")
199179

200-
Sentry.get_current_client.flush
180+
Sentry.get_current_client.flush
201181

202-
metric = sentry_metrics.first
203-
attributes = metric[:attributes]
182+
metric = sentry_metrics.first
183+
attributes = metric[:attributes]
204184

205-
expect(attributes).not_to have_key("user.id")
206-
expect(attributes).not_to have_key("user.name")
207-
expect(attributes).not_to have_key("user.email")
208-
end
185+
expect(attributes["user.id"]).to eq({ type: "integer", value: 123 })
186+
expect(attributes["user.name"]).to eq({ type: "string", value: "jane" })
187+
expect(attributes["user.email"]).to eq({ type: "string", value: "jane@example.com" })
209188
end
210189
end
211190

sentry-ruby/spec/sentry/scope_spec.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -474,30 +474,18 @@
474474
context "with user data" do
475475
before { subject.set_user({ id: 123, username: "john_doe", email: "john@example.com" }) }
476476

477-
it "adds user attributes when send_default_pii is enabled" do
478-
Sentry.configuration.send_default_pii = true
477+
it "adds user attributes" do
479478
subject.apply_to_telemetry(telemetry_event)
480479

481480
hash = telemetry_event.to_h
482481
expect(hash[:attributes]["user.id"]).to eq({ value: 123, type: "integer" })
483482
expect(hash[:attributes]["user.name"]).to eq({ value: "john_doe", type: "string" })
484483
expect(hash[:attributes]["user.email"]).to eq({ value: "john@example.com", type: "string" })
485484
end
486-
487-
it "doesn't add user attributes when send_default_pii is disabled" do
488-
Sentry.configuration.send_default_pii = false
489-
subject.apply_to_telemetry(telemetry_event)
490-
491-
hash = telemetry_event.to_h
492-
expect(hash[:attributes].key?("user.id")).to eq(false)
493-
expect(hash[:attributes].key?("user.name")).to eq(false)
494-
expect(hash[:attributes].key?("user.email")).to eq(false)
495-
end
496485
end
497486

498487
context "without user data" do
499488
it "does not add user attributes when user is empty" do
500-
Sentry.configuration.send_default_pii = true
501489
subject.apply_to_telemetry(telemetry_event)
502490

503491
hash = telemetry_event.to_h

0 commit comments

Comments
 (0)