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

Returns a new instance of Endpoint.



108
109
110
111
112
# File 'lib/datadog/tracing/transport/http/traces.rb', line 108

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.



105
106
107
# File 'lib/datadog/tracing/transport/http/traces.rb', line 105

def encoder
  @encoder
end

Instance Method Details

#call(env, &block) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/datadog/tracing/transport/http/traces.rb', line 118

def call(env, &block)
  # Add trace count header
  env.headers[HEADER_TRACE_COUNT] = env.request.parcel.trace_count.to_s

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

  # Query for response
  http_response = super(env, &block)

  # 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

Returns:

  • (Boolean)


114
115
116
# File 'lib/datadog/tracing/transport/http/traces.rb', line 114

def service_rates?
  @service_rates == true
end