You can apply different tracing configurations to different MongoDB connections using the describes option. This option accepts a connection string or a regular expression. When a connection matches a rule, the latest matching rule is applied.
If a block is provided to instrument, it yields a settings object for that specific pattern.
Datadog.configure do |c|
# Match by exact connection string
c.tracing.instrument :mongo, describes: '127.0.0.1:27017', service_name: 'mongo-primary'
# Match by regular expression
c.tracing.instrument :mongo, describes: /localhost.*/, service_name: 'mongo-secondary'
end