Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

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

## 6.3.1

Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def apply_to_telemetry(telemetry)
telemetry.attributes["sentry.release"] ||= configuration.release if configuration.release
telemetry.attributes["server.address"] ||= configuration.server_name if configuration.server_name

if configuration.send_default_pii && !user.empty?
unless user.empty?
telemetry.attributes["user.id"] ||= user[:id] if user[:id]
telemetry.attributes["user.name"] ||= user[:username] if user[:username]
telemetry.attributes["user.email"] ||= user[:email] if user[:email]
Expand Down
30 changes: 5 additions & 25 deletions sentry-ruby/spec/sentry/metric_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,12 @@
end

context "with user data" do
context "when send_default_pii is true" do
before do
Sentry.configuration.send_default_pii = true
end

it "includes user.id attribute" do
hash = metric_event_scope_applied.to_h

expect(hash[:attributes]["user.id"]).to eq({ type: "string", value: "123" })
expect(hash[:attributes]["user.name"]).to eq({ type: "string", value: "jane" })
expect(hash[:attributes]["user.email"]).to eq({ type: "string", value: "jane.doe@email.com" })
end
end

context "when send_default_pii is false" do
before do
Sentry.configuration.send_default_pii = false
end

it "does not include user attributes" do
hash = metric_event_scope_applied.to_h
it "includes user.id attribute" do
hash = metric_event_scope_applied.to_h

expect(hash[:attributes].key?("user.id")).to eq(false)
expect(hash[:attributes].key?("user.name")).to eq(false)
expect(hash[:attributes].key?("user.email")).to eq(false)
end
expect(hash[:attributes]["user.id"]).to eq({ type: "string", value: "123" })
expect(hash[:attributes]["user.name"]).to eq({ type: "string", value: "jane" })
expect(hash[:attributes]["user.email"]).to eq({ type: "string", value: "jane.doe@email.com" })
end
end
end
Expand Down
37 changes: 8 additions & 29 deletions sentry-ruby/spec/sentry/metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,38 +174,17 @@
end
end

context "when send_default_pii is true" do
before do
Sentry.configuration.send_default_pii = true
end

it "includes user attributes in the metric" do
Sentry.metrics.count("test.counter")

Sentry.get_current_client.flush

metric = sentry_metrics.first
attributes = metric[:attributes]

expect(attributes["user.id"]).to eq({ type: "integer", value: 123 })
expect(attributes["user.name"]).to eq({ type: "string", value: "jane" })
expect(attributes["user.email"]).to eq({ type: "string", value: "jane@example.com" })
end
end

context "when send_default_pii is false" do
it "does not include user attributes" do
Sentry.metrics.count("test.counter")
it "includes user attributes in the metric" do
Sentry.metrics.count("test.counter")

Sentry.get_current_client.flush
Sentry.get_current_client.flush

metric = sentry_metrics.first
attributes = metric[:attributes]
metric = sentry_metrics.first
attributes = metric[:attributes]

expect(attributes).not_to have_key("user.id")
expect(attributes).not_to have_key("user.name")
expect(attributes).not_to have_key("user.email")
end
expect(attributes["user.id"]).to eq({ type: "integer", value: 123 })
expect(attributes["user.name"]).to eq({ type: "string", value: "jane" })
expect(attributes["user.email"]).to eq({ type: "string", value: "jane@example.com" })
end
end

Expand Down
14 changes: 1 addition & 13 deletions sentry-ruby/spec/sentry/scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,30 +474,18 @@
context "with user data" do
before { subject.set_user({ id: 123, username: "john_doe", email: "john@example.com" }) }

it "adds user attributes when send_default_pii is enabled" do
Sentry.configuration.send_default_pii = true
it "adds user attributes" do
subject.apply_to_telemetry(telemetry_event)

hash = telemetry_event.to_h
expect(hash[:attributes]["user.id"]).to eq({ value: 123, type: "integer" })
expect(hash[:attributes]["user.name"]).to eq({ value: "john_doe", type: "string" })
expect(hash[:attributes]["user.email"]).to eq({ value: "john@example.com", type: "string" })
end

it "doesn't add user attributes when send_default_pii is disabled" do
Sentry.configuration.send_default_pii = false
subject.apply_to_telemetry(telemetry_event)

hash = telemetry_event.to_h
expect(hash[:attributes].key?("user.id")).to eq(false)
expect(hash[:attributes].key?("user.name")).to eq(false)
expect(hash[:attributes].key?("user.email")).to eq(false)
end
end

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

hash = telemetry_event.to_h
Expand Down
Loading