DataDog / dd-trace-rb

Datadog Tracing Ruby Client
https://docs.datadoghq.com/tracing/
Other
310 stars 375 forks source link

Failed to report profiling data, connection closed before message completed #3716

Open ganey opened 5 months ago

ganey commented 5 months ago

Current behaviour Intermittent errors sending traces, unsure how to debug further

E, [2024-06-13T08:29:54.066769 #28] ERROR -- ddtrace: [ddtrace] (/usr/local/bundle/gems/ddtrace-1.22.0/lib/datadog/profiling/http_transport.rb:62:in `export') Failed to report profiling data ({:agent=>"unix:///var/run/datadog/apm.socket"}): failed ddog_prof_Exporter_send: connection closed before message completed

Expected behaviour no error sending trace

Steps to reproduce Unsure, happens randomly across cluster and different pods

How does datadog help you?

Environment

ivoanjo commented 5 months ago

Hey @ganey, thanks for getting in touch.

The error message you shared is actually related to profiling, not sending of traces...

E, [2024-06-13T08:29:54.066769 #28] ERROR -- ddtrace: [ddtrace] (/usr/local/bundle/gems/ddtrace-1.22.0/lib/datadog/profiling/http_transport.rb:62:in `export') Failed to report profiling data ({:agent=>"unix:///var/run/datadog/apm.socket"}): failed ddog_prof_Exporter_send: connection closed before message completed

...so it's possible your traces are not getting affected at all.

One thing that's a bit confusing is that your configuration block and environment variables do not mention enabling profiling at all. Can you doublecheck if there's missing environment variables and/or configuration that's enabling profiling?

ganey commented 5 months ago

Hey @ivoanjo thanks for the quick response.

So i dug further into the code and one of the gems we're using is turning on profiling, here's the configure we're using from that gem:

Datadog.configure do |c|
  container_name = ENV.fetch('CONTAINER_NAME') { '' }
  pod_name = ENV.fetch('POD_NAME') { '' }
  global_tags = [
    "railsenv:#{Rails.env}",
    "service:workers",
    "container_name:#{container_name}",
    "pod_name:#{pod_name}",
  ]

  c.runtime_metrics.enabled = true

  datadog_singleton = DatadogSingleton.instance
  datadog_statsd_socket_path = ENV.fetch('DD_STATSD_SOCKET_PATH') { '' }
  datadog_singleton.statsd = if datadog_statsd_socket_path.to_s.strip.empty?
    Datadog::Statsd.new(ENV['DD_AGENT_HOST'], 8125, tags: global_tags)
  else
    Datadog::Statsd.new(socket_path: datadog_statsd_socket_path, tags: global_tags)
  end
  c.runtime_metrics.statsd = datadog_singleton.statsd

  # Trace tags API is Hash<String,String>, see https://www.rubydoc.info/gems/ddtrace/Datadog/Tracing
  # Should match the global tags, but as a Hash.
  c.tags = {
    railsenv: Rails.env,
    service: 'workers',
    container_name: container_name,
    pod_name: pod_name,
  }

  c.tracing.enabled = true
  c.profiling.enabled = true

  c.tracing.instrument(:rails, service_name: 'workers')

  c.logger.level = Logger::WARN
end
ivoanjo commented 5 months ago

Ahh, thanks, this is definitely a more through configuration.

Can I ask you to open a support ticket so we can look at your account and investigate this?

Could you include in the ticket:

Thank you!