Class: Datadog::Tracing::Transport::HTTP::Traces::API::Endpoint
- Inherits:
-
Core::Transport::HTTP::API::Endpoint
- Object
- Core::Transport::HTTP::API::Endpoint
- Datadog::Tracing::Transport::HTTP::Traces::API::Endpoint
- 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
-
#encoder ⇒ Object
readonly
Returns the value of attribute encoder.
Attributes inherited from Core::Transport::HTTP::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.
108 109 110 111 112 |
# File 'lib/datadog/tracing/transport/http/traces.rb', line 108 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.
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 = { trace_count: env.request.parcel.trace_count }.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) [: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, ) end |
#service_rates? ⇒ Boolean
114 115 116 |
# File 'lib/datadog/tracing/transport/http/traces.rb', line 114 def service_rates? @service_rates == true end |