diff --git a/lib/degica_datadog/tracing.rb b/lib/degica_datadog/tracing.rb index dced530..24e157e 100644 --- a/lib/degica_datadog/tracing.rb +++ b/lib/degica_datadog/tracing.rb @@ -49,6 +49,19 @@ def init(rake_tasks: []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength c.tracing.instrument :httpclient, split_by_domain: true c.tracing.instrument :httprb, split_by_domain: true end + + # This block is called before traces are sent to the agent, and allows + # us to modify or filter them. + Datadog::Tracing.before_flush do |trace| + Datadog::Tracing::Pipeline::SpanProcessor.new do |span| + # Group subdomains in service tags together. + span.service = "myshopify.com" if span.service.end_with?("myshopify.com") + span.service = "ngrok.io" if span.service.end_with?("ngrok.io") + span.service = "ngrok-free.app" if span.service.end_with?("ngrok-free.app") + end + + trace + end end # Start a new span.