Skip to content

Commit f2bc2be

Browse files
committed
Only expose keys on span data if is on
1 parent 8108ddb commit f2bc2be

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGELOG.md

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

55
- Add new sidekiq config `report_only_dead_jobs` ([#2581](https://github.com/getsentry/sentry-ruby/pull/2581))
66
- Add `max_nesting` of 10 to breadcrumbs data serialization ([#2583](https://github.com/getsentry/sentry-ruby/pull/2583))
7+
- Only expose `active_storage` keys on span data if `send_default_pii` is on ([#2589](https://github.com/getsentry/sentry-ruby/pull/2589))
78

89
### Bug Fixes
910

sentry-rails/lib/sentry/rails/tracing/active_storage_subscriber.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def self.subscribe!
3333
duration: duration
3434
) do |span|
3535
payload.each do |key, value|
36-
span.set_data(key, value) unless key == START_TIMESTAMP_NAME
36+
next if key == START_TIMESTAMP_NAME
37+
next if key == :key && !Sentry.configuration.send_default_pii
38+
39+
span.set_data(key, value)
3740
end
3841
end
3942
end

sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,34 @@
4848
expect(span[:op]).to eq("file.service_upload.active_storage")
4949
expect(span[:origin]).to eq("auto.file.rails")
5050
expect(span[:description]).to eq("Disk")
51-
expect(span.dig(:data, :key)).to eq(p.cover.key)
51+
expect(span.dig(:data, :key)).to be_nil
5252
expect(span[:trace_id]).to eq(request_transaction.dig(:contexts, :trace, :trace_id))
5353
end
54+
55+
context "with send_default_pii = true" do
56+
before do
57+
make_basic_app do |config|
58+
config.traces_sample_rate = 1.0
59+
config.send_default_pii = true
60+
config.rails.tracing_subscribers = [described_class]
61+
end
62+
end
63+
64+
it "records the :key in span.data" do
65+
# make sure AnalyzeJob will be executed immediately
66+
ActiveStorage::AnalyzeJob.queue_adapter.perform_enqueued_jobs = true
67+
68+
p = Post.create!
69+
get "/posts/#{p.id}/attach"
70+
71+
request_transaction = transport.events.last.to_hash
72+
expect(request_transaction[:type]).to eq("transaction")
73+
expect(request_transaction[:spans].count).to eq(2)
74+
75+
span = request_transaction[:spans][1]
76+
expect(span.dig(:data, :key)).to eq(p.cover.key)
77+
end
78+
end
5479
end
5580

5681
context "when transaction is not sampled" do

0 commit comments

Comments
 (0)