Skip to content

Commit 026bdab

Browse files
solnicCodex
andcommitted
fix(rails): avoid serializing jobs for telemetry
Co-Authored-By: Codex <noreply@example.com>
1 parent eae4e97 commit 026bdab

3 files changed

Lines changed: 23 additions & 18 deletions

File tree

‎sentry-rails/lib/sentry/rails/active_job.rb‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def record_producer_span(job, &enqueue)
119119
{
120120
system: messaging_system(job),
121121
message_id: job.job_id,
122-
destination: job.queue_name,
123-
body_size: body_size { job.serialize }
122+
destination: job.queue_name
124123
}.compact
125124
},
126125
default_retry_count: -> { executions(job) },

‎sentry-rails/spec/active_job/shared_examples/tracing/producer_span.rb‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@
2424
expect(publish_span[:timestamp]).not_to be_nil
2525
end
2626

27-
it "records messaging.message.body.size as the JSON byte length of the serialized job, arguments included" do
28-
short_greeting = "hi"
29-
long_greeting = "héllo wörld"
30-
31-
within_parent_transaction do
32-
greeting_job.perform_later(short_greeting)
33-
greeting_job.perform_later(long_greeting)
34-
end
35-
36-
parent = transactions.find { |t| t.contexts.dig(:trace, :op) == "test" }
37-
body_sizes = parent.spans.select { |s| s[:op] == "queue.publish" }.map { |s| s[:data]["messaging.message.body.size"] }
38-
expect(body_sizes).to all(be_an(Integer))
39-
expect(body_sizes.last - body_sizes.first)
40-
.to eq(JSON.generate(long_greeting).bytesize - JSON.generate(short_greeting).bytesize)
41-
end
42-
4327
it "records the same messaging.system on the producer span and the consumer transaction" do
4428
within_parent_transaction do
4529
successful_job.perform_later

‎sentry-rails/spec/active_job/test_adapter_spec.rb‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@
99
it_behaves_like "a Sentry-instrumented ActiveJob backend"
1010
it_behaves_like "an ActiveJob backend that supports distributed tracing"
1111

12+
context "when a custom serializer changes the job payload" do
13+
let(:configure_sentry) { proc { |config| config.traces_sample_rate = 1.0 } }
14+
15+
it "enqueues the same custom payload with and without a sampled parent" do
16+
custom_job = job_fixture do
17+
def serialize
18+
@serialization_count = (@serialization_count || 0) + 1
19+
super.merge("serialization_count" => @serialization_count)
20+
end
21+
22+
def perform; end
23+
end
24+
25+
custom_job.perform_later
26+
untraced_count = last_enqueued_payload["serialization_count"]
27+
within_parent_transaction { custom_job.perform_later }
28+
29+
expect(untraced_count).to eq(1)
30+
expect(last_enqueued_payload["serialization_count"]).to eq(untraced_count)
31+
end
32+
end
33+
1234
context "when the job data cannot be encoded as JSON" do
1335
let(:configure_sentry) { proc { |config| config.traces_sample_rate = 1.0 } }
1436
let(:unencodable_argument) { "\xFF".dup.force_encoding(Encoding::UTF_8) }

0 commit comments

Comments
 (0)