module ElasticAPM::Spies::AzureStorageTableSpy::Helpers
def account_name_from_storage_table_host(host)
def account_name_from_storage_table_host(host) account_names.compute_if_absent(host) do URI(host).host.split(".").first || "unknown" end rescue Exception "unknown" end
def account_names
def account_names @account_names ||= Concurrent::Map.new end
def formatted_op_name(operation_name)
def formatted_op_name(operation_name) formatted_op_names.compute_if_absent(operation_name) do DEFAULT_OP_NAMES.fetch(operation_name) do operation_name.to_s.split("_").collect(&:capitalize).join end end end
def formatted_op_names
def formatted_op_names @formatted_op_names ||= Concurrent::Map.new end
def instrument(operation_name, table_name = nil, service:)
def instrument(operation_name, table_name = nil, service:) span_name = span_name(operation_name, table_name) action = formatted_op_name(operation_name) account_name = account_name_from_storage_table_host(service.storage_service_host[:primary]) destination = ElasticAPM::Span::Context::Destination.from_uri(service.storage_service_host[:primary]) destination.service.resource = "#{SUBTYPE}/#{account_name}" context = ElasticAPM::Span::Context.new(destination: destination) ElasticAPM.with_span(span_name, TYPE, subtype: SUBTYPE, action: action, context: context) do ElasticAPM::Spies.without_faraday do ElasticAPM::Spies.without_net_http do yield end end end end
def span_name(operation_name, table_name = nil)
def span_name(operation_name, table_name = nil) base = "AzureTable #{formatted_op_name(operation_name)}" return base unless table_name "#{base} #{table_name}" end