From 6b24d2cf0b8800094e722b6b1550851645a6e23f Mon Sep 17 00:00:00 2001 From: Robin Schroer Date: Wed, 31 Jan 2024 14:40:51 +0900 Subject: [PATCH] This time actually use the path group in the resource name This is fixing up the previous commit, because upon closer inspection it turns out that there is no path_group tag on these spans, because that tag is generated later on in the Datadog Agent. We can generate this tag ourselves though, at least roughly, so this should fix the issue. --- lib/degica_datadog/tracing.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/degica_datadog/tracing.rb b/lib/degica_datadog/tracing.rb index 59351c6..f302c53 100644 --- a/lib/degica_datadog/tracing.rb +++ b/lib/degica_datadog/tracing.rb @@ -4,10 +4,10 @@ module DegicaDatadog # Tracing related functionality. - module Tracing + module Tracing # rubocop:disable Metrics/ModuleLength class << self # Initialize Datadog tracing. Call this in from config/application.rb. - def init(rake_tasks: []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength + def init(rake_tasks: []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity return unless Config.enabled? require "ddtrace/auto_instrument" @@ -63,7 +63,17 @@ def init(rake_tasks: []) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength # Use method + path as the resource name for outbound HTTP requests. Datadog::Tracing::Pipeline::SpanProcessor.new do |span| if %w[ethon faraday net/http httpclient httprb].include?(span.get_tag("component")) - span.resource = "#{span.get_tag("http.method")} #{span.get_tag("http.path_group")}" + # The path group is normally generated in the agent, later on. We + # don't want to use the raw path in the resource name, as that + # would create a lot of resources for any path that contains an + # ID. The logic seems to be at least vaguely to replace any path + # segment that contains a digit with a ?, so we're reproducing + # that here. + path_group = span.get_tag("http.url") + .split("/") + .map { |segment| segment =~ /\d/ ? "?" : segment } + .join("/") + span.resource = "#{span.get_tag("http.method")} #{path_group}" end end )