Description
openedon Aug 11, 2023
Current behaviour
All DB methods throw an error when DD_TRACE_ENABLED
is set to false
/app/vendor/bundle/ruby/2.6.0/bundler/gems/rails2-aae3e4374b07/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `rescue in log': TypeError: can't convert nil into Integer: SET standard_conforming_strings = on (ActiveRecord::StatementInvalid)
from /app/vendor/bundle/ruby/2.6.0/bundler/gems/rails2-aae3e4374b07/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:203:in `log'
from /app/vendor/bundle/ruby/2.6.0/bundler/gems/rails2-aae3e4374b07/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:520:in `execute'
from /app/vendor/bundle/ruby/2.6.0/bundler/gems/rails2-aae3e4374b07/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:269:in `set_standard_conforming_strings'
from /app/vendor/bundle/ruby/2.6.0/bundler/gems/rails2-aae3e4374b07/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:975:in `configure_connection'
... [snip] ...
/app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/distributed/trace_context.rb:116:in `format': can't convert nil into Integer (TypeError)
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/distributed/trace_context.rb:116:in `build_traceparent_string'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/distributed/trace_context.rb:93:in `build_traceparent'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/contrib/propagation/sql_comment.rb:32:in `prepend_comment'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/contrib/pg/instrumentation.rb:99:in `block in trace'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/tracer.rb:524:in `skip_trace'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/tracer.rb:137:in `trace'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing.rb:18:in `trace'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/contrib/pg/instrumentation.rb:86:in `trace'
from /app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/contrib/pg/instrumentation.rb:24:in `exec'
from /app/vendor/bundle/ruby/2.6.0/bundler/gems/rails2-aae3e4374b07/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:524:in `block in execute'
from /app/vendor/bundle/ruby/2.6.0/bundler/gems/rails2-aae3e4374b07/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:206:in `block in log'
... [snip] ...
Expected behaviour
build_traceparent_string
correctly handles the case where trace_id
and span_id
might be nil.
This seems pretty straightforward. We call the build_traceparent
private method directly from SqlComment
:
But in the case where tracing is disabled, trace_op
is set to dummy nil values by skip_trace
:
dd-trace-rb/lib/datadog/tracing/tracer.rb
Lines 519 to 528 in 1dc95e2
which bypasses build_span
where we set parent_trace_id to 0:
Which blows up when we try to serialize it:
/app/vendor/bundle/ruby/2.6.0/gems/ddtrace-1.11.1/lib/datadog/tracing/distributed/trace_context.rb:116:in `format': can't convert nil into Integer (TypeError)
Steps to reproduce
- Configure
c.tracing.instrument :pg, comment_propagation: 'full'
- Configure
DD_TRACE_ENABLED
to befalse
Environment
- ddtrace version: 1.11.1
- Ruby version: 2.6
- Relevant library versions: pg version 0.21.0