Skip to content

Commit

Permalink
dup string if frozen in trilogy query
Browse files Browse the repository at this point in the history
  • Loading branch information
plantfansam committed Feb 9, 2024
1 parent c048b14 commit 246db37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def query(sql)
),
kind: :client
) do |_span, context|
sql = sql.dup unless !sql.frozen? || propagator.is_a?(OpenTelemetry::Instrumentation::Trilogy::NoopPropagator)
propagator.inject(sql, context: context)
super(sql)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,14 @@
let(:config) { { propagator: 'vitess' } }

it 'does inject context' do
sql = +'SELECT * from users where users.id = 1 and users.email = "test@test.com"'
original_sql = sql.dup
sql = 'SELECT * from users where users.id = 1 and users.email = "test@test.com"'.freeze
propagator = double("propagator")
allow(propagator).to receive(:inject)
allow(client).to receive(:propagator).and_return(propagator)
expect do
client.query(sql)
end.must_raise Trilogy::Error
encoded = Base64.strict_encode64("{\"uber-trace-id\":\"#{span.hex_trace_id}:#{span.hex_span_id}:0:1\"}")
_(sql).must_equal "/*VT_SPAN_CONTEXT=#{encoded}*/#{original_sql}"
expect(propagator).to have_received(:inject).with(sql, context: instance_of(OpenTelemetry::Context)).once
end
end

Expand Down

0 comments on commit 246db37

Please sign in to comment.