class THTP::Server::Instrumentation::Metrics

A THTP::Server Server subscriber for RPC metrics reporting

Constants

ERROR_TAG
EXCEPTION_TAG
INBOUND_RPC_STAT
INTERNAL_ERROR_TAG
SUCCESS_TAG

Public Class Methods

new(statsd) click to toggle source
# File lib/thtp/server/instrumentation.rb, line 21
def initialize(statsd)
  unless defined?(Datadog::Statsd) && statsd.is_a?(Datadog::Statsd)
    raise ArgumentError, 'Only dogstatsd is supported'
  end
  @statsd = statsd
end

Public Instance Methods

internal_error(request:, error:, time:) click to toggle source

An unknown error occurred @param request [Rack::Request] The inbound HTTP request @param error [Exception] The to-be-serialized exception @param time [Integer] Milliseconds of execution wall time

# File lib/thtp/server/instrumentation.rb, line 65
def internal_error(request:, error:, time:)
  tags = [INTERNAL_ERROR_TAG, "rpc.error:#{canonical_name(error.class)}"]
  @statsd.timing(INBOUND_RPC_STAT, time, tags: tags)
end
rpc_error(request:, rpc:, args:, error:, time:) click to toggle source

Handler raised an unexpected error @param request [Rack::Request] The inbound HTTP request @param rpc [Symbol] The name of the RPC @param args [Thrift::Struct?] The deserialized thrift args @param error [THTP::ServerError] The to-be-serialized exception @param time [Integer] Milliseconds of execution wall time

# File lib/thtp/server/instrumentation.rb, line 56
def rpc_error(request:, rpc:, args:, error:, time:)
  tags = ["rpc:#{rpc}", ERROR_TAG, "rpc.error:#{canonical_name(error.class)}"]
  @statsd.timing(INBOUND_RPC_STAT, time, tags: tags)
end
rpc_exception(request:, rpc:, args:, exception:, time:) click to toggle source

Handler raised an exception defined in the schema @param request [Rack::Request] The inbound HTTP request @param rpc [Symbol] The name of the RPC @param args [Thrift::Struct] The deserialized thrift args @param exception [Thrift::Struct] The to-be-serialized thrift exception @param time [Integer] Milliseconds of execution wall time

# File lib/thtp/server/instrumentation.rb, line 45
def rpc_exception(request:, rpc:, args:, exception:, time:)
  tags = ["rpc:#{rpc}", EXCEPTION_TAG, "rpc.error:#{canonical_name(exception.class)}"]
  @statsd.timing(INBOUND_RPC_STAT, time, tags: tags)
end
rpc_success(request:, rpc:, args:, result:, time:) click to toggle source

Everything went according to plan @param request [Rack::Request] The inbound HTTP request @param rpc [Symbol] The name of the RPC @param args [Thrift::Struct] The deserialized thrift args @param result [Thrift::Struct] The to-be-serialized thrift response @param time [Integer] Milliseconds of execution wall time

# File lib/thtp/server/instrumentation.rb, line 34
def rpc_success(request:, rpc:, args:, result:, time:)
  tags = ["rpc:#{rpc}", SUCCESS_TAG]
  @statsd.timing(INBOUND_RPC_STAT, time, tags: tags)
end