Skip to content

comment_propagation: 'full' throws an error when DD_TRACE_ENABLED is false #3047

Open

Description

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:

Tracing::Distributed::TraceContext.new(fetcher: nil).send(:build_traceparent, trace_op.to_digest)

But in the case where tracing is disabled, trace_op is set to dummy nil values by skip_trace:

def skip_trace(name)
span = SpanOperation.new(name)
if block_given?
trace = TraceOperation.new
yield(span, trace)
else
span
end
end

which bypasses build_span where we set parent_trace_id to 0:

parent_id = parent ? parent.id : @parent_span_id || 0

Which blows up when we try to serialize it:

"00-#{format('%032x', trace_id)}-#{format('%016x', parent_id)}-#{format('%02x', trace_flags)}"

/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

  1. Configure c.tracing.instrument :pg, comment_propagation: 'full'
  2. Configure DD_TRACE_ENABLED to be false

Environment

  • ddtrace version: 1.11.1
  • Ruby version: 2.6
  • Relevant library versions: pg version 0.21.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugInvolves a bugcommunityWas opened by a community member

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions