class Object

Constants

CURB_MIN_VERSION
EXCON_MIDDLEWARE_MIN_VERSION
EXCON_MIN_VERSION

Public Class Methods

route(verb, path, options = {}, &block) click to toggle source
# File lib/ting_yun/instrumentation/sinatra/action.rb, line 48
def route(verb, path, options = {}, &block)
  res = route_without_origin_path(verb, path, options = {}, &block)
  @routes[verb].last << path
  res
end
Also aliased as: route_without_origin_path
route_without_origin_path(verb, path, options = {}, &block)
Alias for: route

Public Instance Methods

aggregate(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/data_mapper.rb, line 149
def aggregate(*args, &block)
  state = TingYun::Agent::TransactionState.tl_get
  *params = get_metrics_params(:read, *args, &block)
  klass_name, *metrics = ::TingYun::Instrumentation::Support::ActiveRecordHelper.metrics_for_data_mapper(*params)

  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, {}, nil, klass_name) do
    t0 = Time.now
    begin
      aggregate_without_tingyun_trace(*args, &block)
    ensure
      elapsed_time = (Time.now - t0).to_f
      state.timings.sql_duration = state.timings.sql_duration  + elapsed_time * 1000
    end
  end
end
basic_get_with_tingyun(*args) click to toggle source
# File lib/ting_yun/instrumentation/bunny.rb, line 145
def basic_get_with_tingyun(*args)
  return basic_get_without_tingyun(*args) unless TingYun::Agent.config[:'mq.enabled']
  begin
    state = TingYun::Agent::TransactionState.tl_get
    metric_name = "#{@connection.host}:#{@connection.port}/Queue/#{args[0]}/Consume"
    summary_metrics = TingYun::Instrumentation::Support::ExternalHelper.metrics_for_message('RabbitMQ', "#{connection.host}:#{connection.port}", 'Consume')
    TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(summary_metrics, {}, nil, "Bunny/Channel") do
      basic_get_without_tingyun(*args)
      state.add_current_node_paramsV3(:vendor => "RabbitMQ")
      state.add_current_node_paramsV3(:instance => "#{@connection.host}:#{@connection.port}")
      state.add_current_node_paramsV3(:operation => "#{args[0]}")
      state.add_current_node_params(:type => 'MQC',:method=>"basic_get")
    end
  rescue =>e
    TingYun::Agent.logger.error("Failed to Bunny basic_get_with_tingyun : ", e)
    basic_get_without_tingyun(*args)
  # ensure
  #   TingYun::Agent::Transaction.stop(state, Time.now.to_f, summary_metrics)
  end
end
build_payload(state) click to toggle source
# File lib/ting_yun/instrumentation/bunny.rb, line 128
def build_payload(state)
  timings = state.timings

  payload = {
      :id => TingYun::Agent.config[:idSecret],
      :tname => state.transaction_name,
      :tid => state.current_transaction.guid,
      :rid => state.trace_id,
      :duration => timings.app_time_in_millis
  }

  payload
end
call_pipelined_with_tingyun_trace(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/redis.rb, line 48
def call_pipelined_with_tingyun_trace(*args, &block)
  pipeline = args[0]
  operation = pipeline.is_a?(::Redis::Pipeline::Multi) ? 'multi' : 'pipeline'

  TingYun::Agent::Datastore.wrap("Redis", operation, db, host, port, nil, method(:record_redis_duration)) do
    state = TingYun::Agent::TransactionState.tl_get
    state.add_current_node_params(:method=>"call_pipelined",:klass=> "Redis/Client")
    call_pipelined_without_tingyun_trace(*args, &block)
  end
end
call_with_tingyun(*args) click to toggle source
# File lib/ting_yun/instrumentation/bunny.rb, line 71
def call_with_tingyun(*args)
  return call_without_tingyun(*args) unless TingYun::Agent.config[:'mq.enabled']
  begin

    headers = args[1][:headers].clone rescue {}


    tingyun_id_secret = headers["X-Tingyun"]

    state = TingYun::Agent::TransactionState.tl_get

    if queue_name.start_with?("amq.")
      metric_name = "#{@channel.connection.host}:#{@channel.connection.port}/Queue/Temp/Consume"
      transaction_name = "RabbitMQ/Queue/FTemp"
    elsif queue_name.include?(".")
      metric_name = "#{@channel.connection.host}:#{@channel.connection.port}/Topic/#{queue_name}/Consume"
      transaction_name = "RabbitMQ/Topic/#{queue_name}"
    else
      metric_name = "#{@channel.connection.host}:#{@channel.connection.port}/Queue/#{queue_name}/Consume"
      transaction_name = "RabbitMQ/Queue/#{queue_name}"
    end

    state.save_referring_transaction_info(tingyun_id_secret.split(';')) if cross_app_enabled?(tingyun_id_secret)

    summary_metrics = TingYun::Instrumentation::Support::ExternalHelper.metrics_for_message('RabbitMQ', "#{@channel.connection.host}:#{@channel.connection.port}", 'Consume')
    TingYun::Agent::Transaction.wrap(state, "Message RabbitMQ/#{metric_name}" , :message, {:mq=> true}, summary_metrics)  do
      TingYun::Agent::Transaction.set_frozen_transaction_name!("#{state.action_type}/#{transaction_name}")
      # TingYun::Agent.record_metric("Message RabbitMQ/#{metric_name}/Byte",args[2].bytesize) if args[2]
      # TingYun::Agent.record_metric("Message RabbitMQ/#{metric_name}Wait", TingYun::Helper.time_to_millis(Time.now)-state.externel_time.to_i) rescue 0
      state.add_custom_params("message.routingkey",queue_name)
      state.add_current_node_params(:type => 'MQC',:method=>"call",:klass=> "Bunny/Consumer")
      state.current_transaction.attributes.add_agent_attribute(:tx_id, state.client_transaction_id)
      headers.delete("X-Tingyun")
      state.merge_request_parameters(headers)
      call_without_tingyun(*args)
      tx_data =  build_payload(state)
      state.current_transaction.attributes.add_agent_attribute(:entryTrace,tx_data) if TingYun::Agent.config[:'nbs.transaction_tracer.enabled']
      state.add_current_node_paramsV3(:vendor => "RabbitMQ",:key => queue_name)
      state.add_current_node_paramsV3(:txData => TingYun::Support::Serialize::JSONWrapper.dump(tx_data))
      state.add_current_node_paramsV3(:instance => "#{@channel.connection.host}:#{@channel.connection.port}")
      state.add_current_node_paramsV3(:operation => "#{queue_name}",:bytes =>args[2].bytesize,:async_wait=>TingYun::Helper.time_to_millis(Time.now)-state.externel_time.to_i)
    end
  rescue => e
    TingYun::Agent.logger.error("Failed to Bunny call_with_tingyun : ", e)
    call_without_tingyun(*args)
  end

end
call_with_tingyun_trace(*args, &blk) click to toggle source
# File lib/ting_yun/instrumentation/redis.rb, line 33
def call_with_tingyun_trace(*args, &blk)
  operation = args[0].is_a?(Array) ? args[0][0] : args[0]

  TingYun::Agent::Datastore.wrap("Redis", operation, db, host, port, nil, method(:record_redis_duration)) do
    state = TingYun::Agent::TransactionState.tl_get
    state.add_current_node_params(:method=>"call_method",:klass=> "Redis/Client")
    call_without_tingyun_trace(*args, &blk)
  end
end
connect(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/redis.rb, line 67
def connect(*args, &block)
  TingYun::Agent::Datastore.wrap("Redis", "connect", db, host, port, nil, method(:record_redis_duration)) do
    state = TingYun::Agent::TransactionState.tl_get
    state.add_current_node_params(:method=>"connect",:klass=> "Redis/Client")
    connect_without_tingyun(*args, &block)
  end
end
create(resources) click to toggle source
# File lib/ting_yun/instrumentation/data_mapper.rb, line 48
def create(resources)
  name = self.name

  resources.each do |resource|
    model      = resource.model
    state = TingYun::Agent::TransactionState.tl_get
    *params = get_metrics_params(:create, model)
    klass_name, *metrics = ::TingYun::Instrumentation::Support::ActiveRecordHelper.metrics_for_data_mapper(*params)

    TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, {}, nil, klass_name) do
      t0 = Time.now
      begin
        serial     = model.serial(name)
        attributes = resource.dirty_attributes

        properties  = []
        bind_values = []

        # make the order of the properties consistent
        model.properties(name).each do |property|
          next unless attributes.key?(property)

          bind_value = attributes[property]

          # skip insering NULL for columns that are serial or without a default
          next if bind_value.nil? && (property.serial? || !property.default?)

          # if serial is being set explicitly, do not set it again
          if property.equal?(serial)
            serial = nil
          end

          properties  << property
          bind_values << bind_value
        end

        statement = insert_statement(model, properties, serial)

        result = with_connection do |connection|
          connection.create_command(statement).execute_non_query(*bind_values)
        end

        if result.affected_rows == 1 && serial
          serial.set!(resource, result.insert_id)
        end
      ensure
        elapsed_time = (Time.now - t0).to_f
        state.timings.sql_duration = state.timings.sql_duration  + elapsed_time * 1000
      end
    end
  end
end
cross_app_enabled?(tingyun_id_secret) click to toggle source
# File lib/ting_yun/instrumentation/bunny.rb, line 124
def cross_app_enabled?(tingyun_id_secret)
  tingyun_id_secret && ::TingYun::Agent.config[:idSecret] && TingYun::Agent.config[:'nbs.transaction_tracer.enabled']
end
deliver_message(*args, **options, &block) click to toggle source
# File lib/ting_yun/instrumentation/kafka.rb, line 64
def deliver_message(*args, **options, &block)
  begin
    state = TingYun::Agent::TransactionState.tl_get
    ip_and_hosts = @seed_brokers.map{|a| [a.host, a.port].join(':')}.join(',') rescue TingYun::Instrumentation::Kafka::UNKNOWN
    metric_name = "Message Kafka/#{ip_and_hosts}/Topic/#{options[:topic]}/Produce"
    summary_metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for_message('Kafka', ip_and_hosts, 'Produce')
    TingYun::Agent::Transaction.wrap(state, metric_name, :Kafka, {}, summary_metrics) do
      # TingYun::Agent.record_metric("#{metric_name}%2FByte", args[0].bytesize) if args[0]
      deliver_message_without_tingyun(*args, **options, &block)
    end
  rescue => e
    TingYun::Agent.logger.error("Failed to kafka deliver_message : ", e)
    deliver_message_without_tingyun(*args, **options, &block)
  end
end
do_request(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/http_client.rb, line 53
def do_request(*args, &block)
  proxy = no_proxy?(args[1]) ? nil : @proxy
  tingyun_request = TingYun::Http::HttpClientRequest.new(proxy, *args, &block)
  TingYun::Agent::CrossAppTracing.tl_trace_http_request(tingyun_request) do
    TingYun::Agent.disable_all_tracing do
      do_request_without_tingyun_trace(*tingyun_request.args, &block)
    end
  end
end
do_request_without_tingyun_trace(*args, &block)
Alias for: do_request
each_batch(*args, **options, &block) click to toggle source
# File lib/ting_yun/instrumentation/kafka.rb, line 145
def each_batch(*args, **options, &block)
  wrap_block = Proc.new do |batch|
    begin
      state = TingYun::Agent::TransactionState.tl_get
      state.reset
      ip_and_hosts = self.cluster.seed_brokers.map{|a| [a.host, a.port].join(':')}.join(',') rescue TingYun::Instrumentation::Kafka::UNKNOWN
      metric_name = "#{ip_and_hosts}/Topic/#{batch.topic}/Consume"
      summary_metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for_message('Kafka', ip_and_hosts, 'Consume')
      TingYun::Agent::Transaction.start(state,:message, {:transaction_name =>
                                                             "WebAction/Kafka/Topic/#{message.topic}/Consume"})
      TingYun::Agent::Transaction.wrap(state, "Message Kafka/#{metric_name}" , :Kafka, {}, summary_metrics)  do
        bytesize = batch.messages.reduce(0){ |res, msg| res += (msg.value ? msg.value.bytesize : 0)}
        # TingYun::Agent.record_metric("Message Kafka/#{metric_name}%2FByte", bytesize) if bytesize.to_i > 0
        block.call(batch)
      end
    rescue => e
      TingYun::Agent.logger.error("Failed to Bunny call_with_tingyun : ", e)
      block.call(batch)
    ensure
      TingYun::Agent::Transaction.stop(state, Time.now.to_f, summary_metrics)
    end
  end
  if options.empty? && args.empty?
    each_batch_without_tingyun(&wrap_block)
  else
    each_batch_without_tingyun(*args, **options, &wrap_block)
  end
end
each_message(*args, **options, &block) click to toggle source
# File lib/ting_yun/instrumentation/kafka.rb, line 84
def each_message(*args, **options, &block)
  wrap_block = Proc.new do |message|
    begin
      state = TingYun::Agent::TransactionState.tl_get
      state.reset
      ip_and_hosts = @seed_brokers.map{|a| [a.host, a.port].join(':')}.join(',') rescue TingYun::Instrumentation::Kafka::UNKNOWN
      metric_name = "#{ip_and_hosts}/Topic/#{message.topic}/Consume"
      summary_metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for_message('Kafka', ip_and_hosts, 'Consume')
      TingYun::Agent::Transaction.start(state,:message, {:transaction_name =>
                                                             "WebAction/Kafka/Topic/#{message.topic}/Consume"})
      TingYun::Agent::Transaction.wrap(state, "Message Kafka/#{metric_name}" , :Kafka, {}, summary_metrics)  do
        # TingYun::Agent.record_metric("Message Kafka/#{metric_name}%2FByte",message.value.bytesize) if message.value
        block.call(message)
      end
    rescue => e
      TingYun::Agent.logger.error("Failed to kafka each_message in client : ", e)
      block.call(message)
    ensure
      TingYun::Agent::Transaction.stop(state, Time.now.to_f, summary_metrics)
    end
  end
  each_message_without_tingyun(*args, **options, &wrap_block)
end
follow_redirect(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/http_client.rb, line 37
def follow_redirect(*args, &block)
  begin
    follow_redirect_without_tingyun_trace(*args, &block)
  rescue => e
    args[1] = (::Module.private_method_defined? :to_resource_url) ? to_resource_url(args[1]) : urify(args[1])
    proxy = no_proxy?(args[1]) ? nil : @proxy
    tingyun_request = TingYun::Http::HttpClientRequest.new(proxy, *args, &block)
    ::TingYun::Instrumentation::Support::ExternalError.handle_error(e, "External/#{tingyun_request.uri.to_s.gsub(/\/\z/,'')}/#{tingyun_request.from}")
    raise e
  end
end
get_metrics_params(method, *args, &block) click to toggle source
# File lib/ting_yun/instrumentation/data_mapper.rb, line 122
def get_metrics_params(method, *args, &block)
  case method
    when :read
      query = args[0]
      return TingYun::Helper.correctly_encoded('SELECT'), nil, self.normalized_uri, DataMapper::Inflector.classify(query.model.storage_name(name))
    when :update
      collection = args[1]
      return TingYun::Helper.correctly_encoded('UPDATE'), nil, self.normalized_uri, DataMapper::Inflector.classify(collection.query.model.storage_name(name))
    when :delete
      collection = args[0]
      return TingYun::Helper.correctly_encoded('DELETE'), nil, self.normalized_uri, DataMapper::Inflector.classify(collection.query.model.storage_name(name))
    when :create
      model = args[0]
      return TingYun::Helper.correctly_encoded('INSERT'), nil, self.normalized_uri, DataMapper::Inflector.classify(model.storage_name(name))
    when :select, :execute
      sql = args[0]
      return nil, sql, self.normalized_uri
  end
end
install_excon_instrumentation(excon_version) click to toggle source
# File lib/ting_yun/instrumentation/excon.rb, line 20
def install_excon_instrumentation(excon_version)
  require 'ting_yun/agent/cross_app/cross_app_tracing'
  require 'ting_yun/http/excon_wrappers'

  if excon_version >= EXCON_MIDDLEWARE_MIN_VERSION
    install_middleware_excon_instrumentation
  else
    install_legacy_excon_instrumentation
  end
end
install_legacy_excon_instrumentation() click to toggle source
# File lib/ting_yun/instrumentation/excon.rb, line 42
def install_legacy_excon_instrumentation
  ::TingYun::Agent.logger.info 'Installing legacy Excon instrumentation'

  ::Excon::Connection.install_tingyun_instrumentation
end
install_middleware_excon_instrumentation() click to toggle source
# File lib/ting_yun/instrumentation/excon.rb, line 31
def install_middleware_excon_instrumentation
  ::TingYun::Agent.logger.info 'Installing middleware-based Excon instrumentation'
  defaults = Excon.defaults

  if defaults[:middlewares]
    defaults[:middlewares] << ::Excon::Middleware::TingYunCrossAppTracing
  else
    ::TingYun::Agent.logger.warn("Did not find :middlewares key in Excon.defaults, skipping Excon instrumentation")
  end
end
instrument_with_tingyun(name, payload = {}, &block) click to toggle source
# File lib/ting_yun/instrumentation/rails3/action_view.rb, line 74
def instrument_with_tingyun(name, payload = {}, &block)
  identifier = payload[:identifier]
  scope_name = "View/#{TingYun::Instrumentation::Rails3::ActionView.template_metric(identifier)}/Partial"
  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(scope_name) do
    instrument_without_tingyun(name, payload, &block)
  end
end
message() click to toggle source
# File lib/ting_yun/instrumentation/http_client.rb, line 65
def message
  header.reason_phrase
end
perform(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/memcached.rb, line 102
def perform(*args, &block)
  return block.call if block
  op, key = args[0..1]
  current_ring = self.class.private_method_defined?(:ring) ? ring : @ring
  server = current_ring.server_for_key(validate_key(key.to_s)) rescue nil
  if server
    host = server.hostname
    port = server.port
  end
  TingYun::Agent::Datastore.wrap('Memcached', op.to_s, nil, host, port, nil, method(:record_memcached_duration)) do
    perform_without_tingyun_trace(*args, &block)
  end
end
produce(*args, **options, &block) click to toggle source
# File lib/ting_yun/instrumentation/kafka.rb, line 179
def produce(*args, **options, &block)
  begin
    state = TingYun::Agent::TransactionState.tl_get
    return produce_without_tingyun(*args, **options, &block) unless state.current_transaction
    ip_and_hosts = @cluster.seed_brokers.map{|a| [a.host, a.port].join(':')}.join(',') rescue TingYun::Instrumentation::Kafka::UNKNOWN
    metric_name = "Message Kafka/#{ip_and_hosts}/Topic/#{options[:topic]}/Produce"
    summary_metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for_message('Kafka', ip_and_hosts, 'Produce')
    TingYun::Agent::Transaction.wrap(state, metric_name, :Kafka, {}, summary_metrics) do
      # TingYun::Agent.record_metric("#{metric_name}%2FByte",args[0].bytesize) if args[0]
      produce_without_tingyun(*args, **options, &block)
    end
  rescue => e
    TingYun::Agent.logger.error("Failed to kafka produce sync : ", e)
    produce_without_tingyun(*args, **options, &block)
  end
end
publish_with_tingyun(payload, opts = {}) click to toggle source
# File lib/ting_yun/instrumentation/bunny.rb, line 24
def publish_with_tingyun(payload, opts = {})
  begin
    state = TingYun::Agent::TransactionState.tl_get
    return publish_without_tingyun(payload, opts) unless state.execution_traced?
    queue_name = opts[:routing_key]
    metric_name = "Message RabbitMQ/#{@channel.connection.host}:#{@channel.connection.port}/"
    if name.empty?
      if queue_name.start_with?("amq.")
        metric_name << "Queue/Temp/Produce"
      elsif queue_name.include?(".")
        metric_name << "Topic/#{queue_name}/Produce"
      else
        metric_name << "Queue/#{queue_name}/Produce"
      end
    else
      metric_name << "Exchange/#{name}/Produce"
    end
    summary_metrics = TingYun::Instrumentation::Support::ExternalHelper.metrics_for_message('RabbitMQ', "#{@channel.connection.host}:#{@channel.connection.port}", 'Produce')
    TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(summary_metrics.unshift(metric_name), {}, nil, "Bunny/Exchange") do
      opts[:headers] = {} unless opts[:headers]
      opts[:headers]["X-Tingyun"] = create_tingyun_id  if TingYun::Agent.config[:'nbs.transaction_tracer.enabled']
      state.add_current_node_paramsV3(:vendor => "RabbitMQ")
      state.add_current_node_paramsV3(:instance => "#{@channel.connection.host}:#{@channel.connection.port}")
      state.add_current_node_paramsV3(:operation => "#{queue_name} #{self.name}",:key=> self.name)
      state.add_current_node_params(:type => 'MQP',:method=>"publish")
      # TingYun::Agent.record_metric("#{metric_name}/Byte",payload.bytesize) if payload
      publish_without_tingyun(payload, opts)
    end
  rescue => e
    TingYun::Agent.logger.error("Failed to Bunny publish_with_tingyun : ", e)
    publish_without_tingyun(payload, opts)
  end
end
receive_message(result_klass)
receive_message_with_tingyun(result_klass) click to toggle source
# File lib/ting_yun/instrumentation/thrift.rb, line 110
def receive_message_with_tingyun(result_klass)
  begin
    state = TingYun::Agent::TransactionState.tl_get

    operate = operator(result_klass)

    t0, node =  started_time_and_node(operate)


    result = receive_message_without_tingyun(result_klass)
    unless result && result.success
      e = ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, "#{operate} failed: unknown result")
      ::TingYun::Instrumentation::Support::ExternalError.handle_error(e,metrics(operate)[0])
    end

    t1 = Time.now.to_f
    node_name, *other_metrics = metrics(operate)
    duration = TingYun::Helper.time_to_millis(t1 - t0)
    my_data = state.thrift_return_data || {}
    # net_block_duration = my_data["time"]? duration - my_data["time"]["duration"]- my_data["time"]["qu"] : duration
    # net_block_duration = duration if net_block_duration < 0
    # TingYun::Agent.instance.stats_engine.tl_record_scoped_and_unscoped_metrics(
    #     node_name, other_metrics, duration
    # )

    if my_data["time"]
      metrics_cross_app = metrics_for_cross_app(operate, my_data)
      _duration =  my_data["time"]["duration"] + my_data["time"]["qu"] + 0.1
      # ::TingYun::Agent.instance.stats_engine.record_scoped_and_unscoped_metrics(state, metrics_cross_app.pop, metrics_cross_app, duration, _duration)
    end
    if node
      node.name = node_name
      ::TingYun::Agent::Collector::TransactionSampler.add_node_info(:uri => "thrift:#{tingyun_host}:#{tingyun_port}/#{operate}")
      stack = state.traced_method_stack
      stack.pop_frame(state, node, node_name, t1)
    end

    result
  rescue => e

    TingYun::Agent.logger.debug("Failed to thrift receive_message_with_tingyun : ", e)
    return  receive_message_without_tingyun(result_klass)
  end
end
Also aliased as: receive_message
receive_message_without_tingyun(result_klass)
Alias for: receive_message
record_redis_duration(duration) click to toggle source
# File lib/ting_yun/instrumentation/redis.rb, line 24
def record_redis_duration(duration)
  state = TingYun::Agent::TransactionState.tl_get
  if state
    state.timings.rds_duration = state.timings.rds_duration + duration * 1000
  end
end
render_with_tingyun(context, options) click to toggle source

namespaced helper methods

# File lib/ting_yun/instrumentation/rails3/action_view.rb, line 58
def render_with_tingyun(context, options)
  # This is needed for rails 3.2 compatibility
  @details = extract_details(options) if respond_to? :extract_details, true
  identifier = determine_template(options) ? determine_template(options).identifier : nil
  scope_name = "View/#{TingYun::Instrumentation::Rails3::ActionView.template_metric(identifier, options)}/Rendering"
  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped scope_name do
    render_without_tingyun(context, options)
  end
end
route_eval(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/sinatra/action.rb, line 72
def route_eval(*args, &block)

  self.class.class_eval do
    require 'ting_yun/instrumentation/support/parameter_filtering'
    require 'ting_yun/instrumentation/support/controller_instrumentation'
    include TingYun::Instrumentation::Sinatra::Action
  end

  params = TingYun::Instrumentation::Support::ParameterFiltering.flattened_filter_request_parameters(@params)

  TingYun::Instrumentation::Support::ControllerInstrumentation.perform_action_with_tingyun_trace(
      :category => :sinatra,
      :name     => @request.path_info,
      :path     => tingyun_metric_path(self.class.name, ty_get_path(self.class)),
      :params   => params,
      :class_name => self.class.name,
      :request => @request
  ) do
    route_eval_without_tingyun_trace(*args, &block)
  end
end
route_eval_without_tingyun_trace(*args, &block)
Alias for: route_eval
run(*args)
Also aliased as: run_without_tingyun
Alias for: run_with_tingyun
run_with_tingyun(*args) click to toggle source
# File lib/ting_yun/instrumentation/grape.rb, line 19
def run_with_tingyun(*args)
  begin
    name = ["Grape",
            self.options[:method].first,
            self.options[:for].to_s,
            self.namespace.to_s.sub(%r{\A/}, ''), # removing leading slashes
            self.options[:path].first.to_s.sub(%r{\A/}, ''),
    ].compact.select{ |n| n.to_s unless n.to_s.empty? }.join("/")
    state = TingYun::Agent::TransactionState.tl_get
    TingYun::Agent::Transaction.wrap(state,name,:controller,) do
      run_without_tingyun(*args)
    end
  rescue => e
    TingYun::Agent.logger.info("Error getting Grape Endpoint Name. Error: #{e.message}. Options: #{self.options.inspect}")
    TingYun::Agent.notice_error(e,:type=>:exception)
    raise e
  end

end
Also aliased as: run
run_without_tingyun(*args)
Alias for: run
send_message(name, args_class, args = {})
Also aliased as: send_message_without_tingyun
send_message_args(args_class, args = {})
send_message_args_with_tingyun(args_class, args = {}) click to toggle source
# File lib/ting_yun/instrumentation/thrift.rb, line 48
def send_message_args_with_tingyun(args_class, args = {})
  return send_message_args_without_tingyun(args_class, args) unless TingYun::Agent.config[:'nbs.transaction_tracer.thrift'] && TingYun::Agent.config[:'nbs.transaction_tracer.enabled']
  begin
    state = TingYun::Agent::TransactionState.tl_get
    return  unless state.execution_traced?

    data = TingYun::Support::Serialize::JSONWrapper.dump("TingyunID" => create_tingyun_id("Thrift","thrift"))
    TingYun::Agent.logger.info("thift will send TingyunID : ", data)
    @oprot.write_field_begin("TingyunField", 11, 40000)
    @oprot.write_string(data)
    @oprot.write_field_end
  rescue => e
    TingYun::Agent.logger.error("Failed to thrift send_message_args_with_tingyun : ", e)
  ensure
    send_message_args_without_tingyun(args_class, args)
  end
end
Also aliased as: send_message_args
send_message_args_without_tingyun(args_class, args = {})
Alias for: send_message_args
send_message_with_tingyun(name, args_class, args = {}) click to toggle source
# File lib/ting_yun/instrumentation/thrift.rb, line 69
def send_message_with_tingyun(name, args_class, args = {})

  begin
    tag = "#{args_class.to_s.split('::').first}.#{name}".downcase
    t0 = Time.now.to_f
    operations[tag] = {:started_time => t0}
    state = TingYun::Agent::TransactionState.tl_get
    return  unless state.execution_traced?
    stack = state.traced_method_stack
    node = stack.push_frame(state,:thrift,t0)
    operations[tag][:node] = node
  rescue => e
    TingYun::Agent.logger.debug("Failed to thrift send_message_with_tingyun : ", e)
  ensure
    send_message_without_tingyun(name, args_class, args)
  end

end
Also aliased as: send_message
send_message_without_tingyun(name, args_class, args = {})
Alias for: send_message
send_oneway_message(name, args_class, args = {})
send_oneway_message_with_tingyun(name, args_class, args = {}) click to toggle source
# File lib/ting_yun/instrumentation/thrift.rb, line 91
def send_oneway_message_with_tingyun(name, args_class, args = {})

  begin
    tag = "#{args_class.to_s.split('::').first}.#{name}".downcase
    op_started = Time.now.to_f
    base, *other_metrics = metrics(tag)
    result = send_oneway_message_without_tingyun(name, args_class, args)
    duration = (Time.now.to_f - op_started)*1000
    # TingYun::Agent.instance.stats_engine.tl_record_scoped_and_unscoped_metrics(base, other_metrics, duration)
    result
  rescue => e
    TingYun::Agent.logger.debug("Failed to thrift send_oneway_message_with_tingyun : ", e)
    return send_oneway_message_without_tingyun(name, args_class, args)
  end

end
Also aliased as: send_oneway_message
send_oneway_message_without_tingyun(name, args_class, args = {})
Alias for: send_oneway_message
skip(type)
Also aliased as: skip_without_tingyun
Alias for: skip_with_tingyun
skip_with_tingyun(type) click to toggle source
# File lib/ting_yun/instrumentation/thrift.rb, line 23
def skip_with_tingyun(type)
  begin
    data = skip_without_tingyun(type)
  ensure
    if data.is_a? ::String
      if data.include?("TingyunTxData")
        my_data = TingYun::Support::Serialize::JSONWrapper.load data.gsub("'",'"')
        TingYun::Agent::TransactionState.process_thrift_data(my_data["TingyunTxData"])

      end
    end
  end
end
Also aliased as: skip
skip_without_tingyun(type)
Alias for: skip
tingyun_template_metric(*args, &block) click to toggle source
# File lib/ting_yun/instrumentation/sinatra/view.rb, line 24
def tingyun_template_metric(*args, &block)
  engine, data, options = args[0..2]
  eat_errors = options[:eat_errors]
  views = options[:views] || settings.views || "./views"
  if data.is_a?(Symbol)
    body, path, line = settings.templates[data]
    unless body.respond_to?(:call)
      template = Tilt[engine]
      found = false
      @preferred_extension = engine.to_s
      find_template(views, data, template) do |file|
        path ||= file
        if found = File.exist?(file)
          path = file
          break
        end
      end
      path = nil if eat_errors and not found  # layout_missing
    end
  else
    path = nil
  end
  if path
    path = path.gsub(settings.root,'') if respond_to?(:settings) && settings.root
    "View/#{path.gsub(/\.+\//,'')}/Rendering".squeeze("/")
  end
end
ty_get_path(base) click to toggle source
# File lib/ting_yun/instrumentation/sinatra/action.rb, line 59
def ty_get_path(base)
  if routes = base.routes[@request.request_method]
    routes.each do |pattern, keys, conditions, block, origin_path|
      route = @request.path_info
      route = '/' if route.empty? and not settings.empty_path_info?
      next unless pattern.match(route)
      return (origin_path.respond_to?(:source) ? origin_path.source : origin_path)
    end
  end
  ty_get_path(base.superclass) if base.superclass.respond_to?(:routes)
end