module Hoodoo::Monkey::Patch::DatadogTracedAMQP::InstanceExtensions

Instance methods to patch over Hoodoo::Client::Endpoint::AMQP.

Public Instance Methods

monkey_send_request( http_message, full_uri ) click to toggle source

Wrap the request with Datadog’s distributed tracing. This adds headers to the request and extracts header data from the response. It calls the original implementation via super.

http_message

Hash describing the message to send.

full_uri

URI being sent to. This is somewhat meaningless when using AMQP but useful for analytics data.

Calls superclass method
# File lib/hoodoo/monkey/patch/datadog_traced_amqp.rb, line 43
def monkey_send_request( http_message, full_uri )
  amqp_response = nil

  Datadog.tracer.trace( 'alchemy.request' ) do |span|
    span.service   = 'alchemy'
    span.span_type = 'alchemy'
    span.resource  = http_message[ 'verb' ]
    span.set_tag( 'target.path', http_message[ 'path'] )
    span.set_tag( 'interaction.id', http_message[ 'headers' ][ 'X-Interaction-ID' ] )

    # Add Datadog trace IDs to the HTTP message. For compatibility
    # with Hoodoo V1 services using a fork of DDTrace, we send both
    # old headers ("X-DDTrace...") and new ("X-DataDog-...")

    http_message[ 'headers' ][ 'X_DATADOG_TRACE_ID'        ] = span.trace_id.to_s
    http_message[ 'headers' ][ 'X_DATADOG_PARENT_ID'       ] = span.span_id.to_s

    http_message[ 'headers' ][ 'X_DDTRACE_PARENT_TRACE_ID' ] = span.trace_id.to_s
    http_message[ 'headers' ][ 'X_DDTRACE_PARENT_SPAN_ID'  ] = span.span_id.to_s

    amqp_response = super( http_message, full_uri )
  end

  return amqp_response
end