Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracing code has a number of circular references during require #1999

Closed
ivoanjo opened this issue May 3, 2022 · 6 comments
Closed

Tracing code has a number of circular references during require #1999

ivoanjo opened this issue May 3, 2022 · 6 comments

Comments

@ivoanjo
Copy link
Member

ivoanjo commented May 3, 2022

We've recently fixed a number of circular references during require...

But there are quite a few remaining. These almost all caused by the following loop: datadog/core requires datadog/core/configuration/components which requires a bunch of tracing components directly:

require 'datadog/tracing/tracer'
require 'datadog/tracing/flush'
require 'datadog/tracing/sync_writer'

and then indirectly quite a few of these components require datadog/core in some of their files.

These are the warnings we get right now:

$ bundle exec ruby -W2 -e 'require "ddtrace"'
.../lib/datadog/tracing/tracer.rb:3: warning: .../lib/datadog/tracing/tracer.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:3:in  `require'

.../lib/datadog/tracing/correlation.rb:3: warning: .../lib/datadog/tracing/correlation.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:7:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:7:in  `require'
  from .../lib/datadog/tracing/correlation.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/correlation.rb:3:in  `require'

.../lib/datadog/tracing/event.rb:3: warning: .../lib/datadog/tracing/event.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:8:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:8:in  `require'
  from .../lib/datadog/tracing/event.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/event.rb:3:in  `require'

.../lib/datadog/tracing/sampling/rule_sampler.rb:5: warning: .../lib/datadog/tracing/sampling/rule_sampler.rb:5: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:12:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:12:in  `require'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:5:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:5:in  `require'

.../lib/datadog/tracing/sampling/rule.rb:5: warning: .../lib/datadog/tracing/sampling/rule.rb:5: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:12:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:12:in  `require'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:9:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:9:in  `require'
  from .../lib/datadog/tracing/sampling/rule.rb:5:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rule.rb:5:in  `require'

.../lib/datadog/tracing/sampling/rate_sampler.rb:3: warning: .../lib/datadog/tracing/sampling/rate_sampler.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:12:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:12:in  `require'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:9:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:9:in  `require'
  from .../lib/datadog/tracing/sampling/rule.rb:8:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rule.rb:8:in  `require'
  from .../lib/datadog/tracing/sampling/rate_sampler.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rate_sampler.rb:3:in  `require'

.../lib/datadog/core/utils.rb:4: warning: .../lib/datadog/core/utils.rb:4: warning: loading in progress, circular require considered harmful - .../lib/datadog/tracing/span.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:12:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:12:in  `require'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:9:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rule_sampler.rb:9:in  `require'
  from .../lib/datadog/tracing/sampling/rule.rb:8:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rule.rb:8:in  `require'
  from .../lib/datadog/tracing/sampling/rate_sampler.rb:6:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rate_sampler.rb:6:in  `require'
  from .../lib/datadog/tracing/span.rb:5:in  `<top (required)>'
  from .../lib/datadog/tracing/span.rb:5:in  `require'
  from .../lib/datadog/core/utils.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/utils.rb:4:in  `require'

.../lib/datadog/tracing/sampling/rate_by_service_sampler.rb:3: warning: .../lib/datadog/tracing/sampling/rate_by_service_sampler.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:13:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:13:in  `require'
  from .../lib/datadog/tracing/sampling/priority_sampler.rb:8:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/priority_sampler.rb:8:in  `require'
  from .../lib/datadog/tracing/sampling/rate_by_service_sampler.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/sampling/rate_by_service_sampler.rb:3:in  `require'

.../lib/datadog/tracing/span_operation.rb:6: warning: .../lib/datadog/tracing/span_operation.rb:6: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:14:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:14:in  `require'
  from .../lib/datadog/tracing/span_operation.rb:6:in  `<top (required)>'
  from .../lib/datadog/tracing/span_operation.rb:6:in  `require'

.../lib/datadog/tracing/trace_operation.rb:3: warning: .../lib/datadog/tracing/trace_operation.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:16:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:16:in  `require'
  from .../lib/datadog/tracing/trace_operation.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/trace_operation.rb:3:in  `require'

.../lib/datadog/tracing/writer.rb:3: warning: .../lib/datadog/tracing/writer.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:17:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:17:in  `require'
  from .../lib/datadog/tracing/writer.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/writer.rb:3:in  `require'

.../lib/datadog/tracing/runtime/metrics.rb:3: warning: .../lib/datadog/tracing/runtime/metrics.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:17:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:17:in  `require'
  from .../lib/datadog/tracing/writer.rb:6:in  `<top (required)>'
  from .../lib/datadog/tracing/writer.rb:6:in  `require'
  from .../lib/datadog/tracing/runtime/metrics.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/runtime/metrics.rb:3:in  `require'

.../lib/datadog/tracing/workers.rb:3: warning: .../lib/datadog/tracing/workers.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:17:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:17:in  `require'
  from .../lib/datadog/tracing/writer.rb:7:in  `<top (required)>'
  from .../lib/datadog/tracing/writer.rb:7:in  `require'
  from .../lib/datadog/tracing/workers.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/workers.rb:3:in  `require'

.../lib/datadog/tracing/buffer.rb:3: warning: .../lib/datadog/tracing/buffer.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:17:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:17:in  `require'
  from .../lib/datadog/tracing/writer.rb:7:in  `<top (required)>'
  from .../lib/datadog/tracing/writer.rb:7:in  `require'
  from .../lib/datadog/tracing/workers.rb:5:in  `<top (required)>'
  from .../lib/datadog/tracing/workers.rb:5:in  `require'
  from .../lib/datadog/tracing/buffer.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/buffer.rb:3:in  `require'

.../lib/datadog/tracing/pipeline.rb:3: warning: .../lib/datadog/tracing/pipeline.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:10:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:10:in  `require'
  from .../lib/datadog/tracing/tracer.rb:17:in  `<top (required)>'
  from .../lib/datadog/tracing/tracer.rb:17:in  `require'
  from .../lib/datadog/tracing/writer.rb:7:in  `<top (required)>'
  from .../lib/datadog/tracing/writer.rb:7:in  `require'
  from .../lib/datadog/tracing/workers.rb:6:in  `<top (required)>'
  from .../lib/datadog/tracing/workers.rb:6:in  `require'
  from .../lib/datadog/tracing/pipeline.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/pipeline.rb:3:in  `require'

.../lib/datadog/tracing/sync_writer.rb:3: warning: .../lib/datadog/tracing/sync_writer.rb:3: warning: loading in progress, circular require considered harmful - .../lib/datadog/core.rb
  from -e:1:in  `<main>'
  from -e:1:in  `require'
  from .../lib/ddtrace.rb:4:in  `<top (required)>'
  from .../lib/ddtrace.rb:4:in  `require'
  from .../lib/datadog/tracing.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing.rb:3:in  `require'
  from .../lib/datadog/core.rb:57:in  `<top (required)>'
  from .../lib/datadog/core.rb:57:in  `require'
  from .../lib/datadog/core/extensions.rb:3:in  `<top (required)>'
  from .../lib/datadog/core/extensions.rb:3:in  `require'
  from .../lib/datadog/core/configuration.rb:4:in  `<top (required)>'
  from .../lib/datadog/core/configuration.rb:4:in  `require'
  from .../lib/datadog/core/configuration/components.rb:12:in  `<top (required)>'
  from .../lib/datadog/core/configuration/components.rb:12:in  `require'
  from .../lib/datadog/tracing/sync_writer.rb:3:in  `<top (required)>'
  from .../lib/datadog/tracing/sync_writer.rb:3:in  `require'

I suspect the solution here will be for individual tracing components to stop requiring datadog/core, and assuming that whoever requires them has taken care of that. Nowadays that's inside datadog/core/configuration/components but in the future that would probably be datadog/tracing directly.

@delner
Copy link
Contributor

delner commented May 3, 2022

I suspect the solution here will be for individual tracing components to stop requiring datadog/core

I think this might be the opposite. Tracing should reference datadog/core, but nothing in datadog/core should reference anything in the other datadog namespaces. Ideally, core/components has its responsibilities significantly reduced, and the startup/bootstrapping of things like the tracer is done within the datadog/tracing namespace.

That should eliminate these circular references, which are holdovers from internal 1.0 related namespace refactors.

@marcotc
Copy link
Member

marcotc commented May 4, 2022

datadog/core is, today, confusingly both a leaf of our dependency graph (core doesn't depend on anything) and the product aggregator node of the graph (aggregates all products into one system).

datadog/core/configuration/components is a case of the latter.

We ideally would like it to be a leaf, no depending on anything, like @delner mentioned, but it's kind of messy today.

For this specific ticket, we either have to move some of the core files that aggregate products to a different namespace or at least document these core files as future candidates to be extracted to a different namespace.

@ioquatix
Copy link
Contributor

ioquatix commented Jul 7, 2022

Running into this same problem, I always try to have warnings turned on in tests:

/home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/tracing/sync_writer.rb:3: warning: /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/tracing/sync_writer.rb:3: warning: loading in progress, circular require considered harmful - /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core.rb
... snip stuff that doesn't matter ...
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/tracing.rb:3:in  `<top (required)>'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/tracing.rb:3:in  `require'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core.rb:57:in  `<top (required)>'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core.rb:57:in  `require'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core/extensions.rb:3:in  `<top (required)>'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core/extensions.rb:3:in  `require'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core/configuration.rb:3:in  `<top (required)>'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core/configuration.rb:3:in  `require'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core/configuration/components.rb:12:in  `<top (required)>'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/core/configuration/components.rb:12:in  `require'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/tracing/sync_writer.rb:3:in  `<top (required)>'
	from /home/samuel/.gem/ruby/3.1.2/gems/ddtrace-1.1.0/lib/datadog/tracing/sync_writer.rb:3:in  `require'

@jdongelmans
Copy link

Just for folks passing by here: I was encountering the same problem in one of our applications. Just this error when running the RSpecs.

Eventually in our case it was a duplicate require 'ddtrace' somewhere, so just removing one fixed the issue.

@marcotc
Copy link
Member

marcotc commented Feb 24, 2023

We have cleaned up the main offender here, lib/datadog/core.rb, and now it only require what it needs, instead of loading most of the ddtrace namespace:

require_relative 'core/extensions'

There have been no reports of circular require since the core.rb changes.

I'm going to close this issue as solved.

@marcotc marcotc closed this as completed Feb 24, 2023
@ioquatix
Copy link
Contributor

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants