diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a8653cdf..1d1c324a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sentry-ruby/lib/sentry/scope.rb b/sentry-ruby/lib/sentry/scope.rb index 2d77b289e..62744a1ee 100644 --- a/sentry-ruby/lib/sentry/scope.rb +++ b/sentry-ruby/lib/sentry/scope.rb @@ -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] diff --git a/sentry-ruby/spec/sentry/metric_event_spec.rb b/sentry-ruby/spec/sentry/metric_event_spec.rb index f15b51224..5806aab16 100644 --- a/sentry-ruby/spec/sentry/metric_event_spec.rb +++ b/sentry-ruby/spec/sentry/metric_event_spec.rb @@ -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 diff --git a/sentry-ruby/spec/sentry/metrics_spec.rb b/sentry-ruby/spec/sentry/metrics_spec.rb index 874c1e8d0..fe9739793 100644 --- a/sentry-ruby/spec/sentry/metrics_spec.rb +++ b/sentry-ruby/spec/sentry/metrics_spec.rb @@ -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 diff --git a/sentry-ruby/spec/sentry/scope_spec.rb b/sentry-ruby/spec/sentry/scope_spec.rb index a31dda16f..f9c80e1f0 100644 --- a/sentry-ruby/spec/sentry/scope_spec.rb +++ b/sentry-ruby/spec/sentry/scope_spec.rb @@ -474,8 +474,7 @@ 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 @@ -483,21 +482,10 @@ 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