Class: Datadog::Transport::HTTP::Traces::API::Endpoint
- Inherits:
-
API::Endpoint
- Object
- API::Endpoint
- Datadog::Transport::HTTP::Traces::API::Endpoint
- Defined in:
- lib/ddtrace/transport/http/traces.rb
Overview
Endpoint for submitting trace data
Constant Summary collapse
- HEADER_CONTENT_TYPE =
'Content-Type'.freeze
- HEADER_TRACE_COUNT =
'X-Datadog-Trace-Count'.freeze
- SERVICE_RATE_KEY =
'rate_by_service'.freeze
Instance Attribute Summary collapse
-
#encoder ⇒ Object
readonly
Returns the value of attribute encoder.
Attributes inherited from API::Endpoint
Instance Method Summary collapse
- #call(env, &block) ⇒ Object
-
#initialize(path, encoder, options = {}) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #service_rates? ⇒ Boolean
Constructor Details
#initialize(path, encoder, options = {}) ⇒ Endpoint
Returns a new instance of Endpoint.
95 96 97 98 99 |
# File 'lib/ddtrace/transport/http/traces.rb', line 95 def initialize(path, encoder, = {}) super(:post, path) @encoder = encoder @service_rates = .fetch(:service_rates, false) end |
Instance Attribute Details
#encoder ⇒ Object (readonly)
Returns the value of attribute encoder.
92 93 94 |
# File 'lib/ddtrace/transport/http/traces.rb', line 92 def encoder @encoder end |
Instance Method Details
#call(env, &block) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ddtrace/transport/http/traces.rb', line 105 def call(env, &block) # Add trace count header env.headers[HEADER_TRACE_COUNT] = env.request.parcel.count.to_s # Encode body & type env.headers[HEADER_CONTENT_TYPE] = encoder.content_type env.body = env.request.parcel.encode_with(encoder) # Query for response http_response = super(env, &block) # Process the response = {}.tap do || # Parse service rates, if configured to do so. if service_rates? && !http_response.payload.to_s.empty? body = JSON.parse(http_response.payload) if body.is_a?(Hash) && body.key?(SERVICE_RATE_KEY) [:service_rates] = body[SERVICE_RATE_KEY] end end end # Build and return a trace response Traces::Response.new(http_response, ) end |
#service_rates? ⇒ Boolean
101 102 103 |
# File 'lib/ddtrace/transport/http/traces.rb', line 101 def service_rates? @service_rates == true end |