Class: Datadog::Tracing::Transport::HTTP::Traces::API::Endpoint

Inherits:
Core::Transport::HTTP::API::Endpoint show all
Defined in:
lib/datadog/tracing/transport/http/traces.rb

Overview

Endpoint for submitting trace data

Constant Summary collapse

HEADER_CONTENT_TYPE =
'Content-Type'
HEADER_TRACE_COUNT =
'X-Datadog-Trace-Count'
SERVICE_RATE_KEY =
'rate_by_service'

Instance Attribute Summary collapse

Attributes inherited from Core::Transport::HTTP::API::Endpoint

#path, #verb

Instance Method Summary collapse

Constructor Details

#initialize(path, encoder, options = {}) ⇒ Endpoint



79
80
81
82
83
# File 'lib/datadog/tracing/transport/http/traces.rb', line 79

def initialize(path, encoder, options = {})
  super(:post, path)
  @encoder = encoder
  @service_rates = options.fetch(:service_rates, false)
end

Instance Attribute Details

#encoderObject (readonly)

Returns the value of attribute encoder.



76
77
78
# File 'lib/datadog/tracing/transport/http/traces.rb', line 76

def encoder
  @encoder
end

Instance Method Details

#call(env, &block) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/datadog/tracing/transport/http/traces.rb', line 89

def call(env, &block)
  # Check Cloudwise probe state - if suspended, don't send traces
  if cloudwise_probe_suspended?
    Datadog.logger.debug { 'Cloudwise: Probe suspended, skipping trace submission' }
    # Return a mock successful response to avoid errors
    return build_mock_response(env)
  end

  # Add trace count header
  env.headers[HEADER_TRACE_COUNT] = env.request.parcel.trace_count.to_s

  # Add routing key header
  env.headers['routingKey'] = 'rubyTopic'

  env.headers['AccountId'] = DATADOG_ENV['CLOUDWISE_ACCOUNT_ID'] || '110'

  # Encode body & type
  env.headers[HEADER_CONTENT_TYPE] = encoder.content_type
  env.body = env.request.parcel.data

  # Query for response
  http_response = super

  # Process the response
  response_options = {trace_count: env.request.parcel.trace_count}.tap do |options|
    # Parse service rates, if configured to do so.
    if service_rates? && !http_response.payload.to_s.empty?
      body = JSON.parse(http_response.payload)
      options[:service_rates] = body[SERVICE_RATE_KEY] if body.is_a?(Hash) && body.key?(SERVICE_RATE_KEY)
    end
  end

  # Build and return a trace response
  Traces::Response.new(http_response, response_options)
end

#service_rates?Boolean



85
86
87
# File 'lib/datadog/tracing/transport/http/traces.rb', line 85

def service_rates?
  @service_rates == true
end