module ElasticAPM::Spies::AzureStorageTableSpy::Helpers

Constants

DEFAULT_OP_NAMES

Public Class Methods

instrument(operation_name, table_name = nil, service:) { || ... } click to toggle source
# File lib/elastic_apm/spies/azure_storage_table.rb, line 30
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

Private Class Methods

account_name_from_storage_table_host(host) click to toggle source
# File lib/elastic_apm/spies/azure_storage_table.rb, line 87
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
account_names() click to toggle source
# File lib/elastic_apm/spies/azure_storage_table.rb, line 67
def account_names
  @account_names ||= Concurrent::Map.new
end
formatted_op_name(operation_name) click to toggle source
# File lib/elastic_apm/spies/azure_storage_table.rb, line 79
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
formatted_op_names() click to toggle source
# File lib/elastic_apm/spies/azure_storage_table.rb, line 63
def formatted_op_names
  @formatted_op_names ||= Concurrent::Map.new
end
span_name(operation_name, table_name = nil) click to toggle source
# File lib/elastic_apm/spies/azure_storage_table.rb, line 71
def span_name(operation_name, table_name = nil)
  base = "AzureTable #{formatted_op_name(operation_name)}"

  return base unless table_name

  "#{base} #{table_name}"
end