Skip to content

Commit

Permalink
This time actually use the path group in the resource name
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sulami committed Jan 31, 2024
1 parent 1f653b7 commit b3e22c9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/degica_datadog/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.path")
.split("/")
.map { |segment| segment =~ /\d/ ? "?" : segment }
.join("/")
span.resource = "#{span.get_tag("http.method")} #{path_group}"
end
end
)
Expand Down

0 comments on commit b3e22c9

Please sign in to comment.