Skip to content

Instantly share code, notes, and snippets.

@FlowerWrong
Last active August 18, 2020 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlowerWrong/66e3fd61314e95d5ca0a90c9e6929631 to your computer and use it in GitHub Desktop.
Save FlowerWrong/66e3fd61314e95d5ca0a90c9e6929631 to your computer and use it in GitHub Desktop.
write elastic ruby agent apm to file
# frozen_string_literal: true
class FileAdapter
include ElasticAPM::Logging
def initialize(config)
@config = config
@mutex = Mutex.new
@logger_file = File.new('log/apm.log', 'a+')
end
def write(str)
return false if @config.disable_send
begin
@mutex.synchronize do
@logger_file.puts(str)
end
rescue IOError => e
error('FileAdapter error: %s', e.inspect)
rescue Errno::EPIPE => e
error('FileAdapter error: %s', e.inspect)
rescue Exception => e
error('FileAdapter error: %s', e.inspect)
end
end
def flush(reason = :force)
@mutex.synchronize do
error('FileAdapter flush: %s', reason)
@logger_file&.close
end
end
end
@FlowerWrong
Copy link
Author

gem 'elastic-apm'

ElasticAPM::Transport::Worker.adapter = FileAdapter # application.rb after Bundler.require(*Rails.groups)

@FlowerWrong
Copy link
Author

   create_table :metricsets do |t|
      t.jsonb :samples
      t.jsonb :transaction
      t.jsonb :span

      t.timestamps
    end

    create_table :spans, id: :string do |t|
      t.string :transaction_id
      t.string :parent_id
      t.string :name
      t.string :t # type
      t.decimal :duration
      t.jsonb :context
      t.jsonb :stacktrace
      t.string :trace_id

      t.timestamps
    end

    create_table :transactions, id: :string do |t|
      t.string :trace_id
      t.string :parent_id
      t.string :name
      t.string :t # type
      t.string :result
      t.decimal :duration
      t.boolean :sampled
      t.jsonb :context
      t.jsonb :span_count

      t.timestamps
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment