Trifle::Traces / Configuration
Learn how to configure Trifle::Traces for your Ruby application.


You don't need to use it with Rails, but you still need to run Trifle::Traces.configure.

Global configuration

If you're running it with Rails, create config/initializers/trifle.rb and configure the gem.

Middleware automatically creates an instance of a tracer for you. To do that automatically, you need to provide tracer_class in your configuration. It defaults to Trifle::Traces::Tracer::Hash, but you can override it with your own custom tracer.

Trifle::Traces.configure do |config|
  config.tracer_klass = Trifle::Traces::Tracer::Hash

To persist your trace, you need to implement callback(s). Please read more about Callbacks.

Custom configuration

Sometimes you may wanna run tracer outside of a middleware. When doing that, setting up tracer_class is not useful. Instead custom configuration can be passed as a keyword argument to any Tracer directly. This configuration will be then used during persistance callbacks.

config =
config.on(:wrapup) do |tracer|
  entry = MyModel.find_by(id: tracer.reference)
  next if entry.nil?

    state: tracer.state

Then you can create an instance of your Tracer with custom configuration.

entry = MyModel.create
tracer = 'my_key', reference:, config: config)

tracer.trace('My message')

While you don't need to use callbacks to update your record/entry, I would encourage you to do so. With callbacks you can get live updates with minimal configuration.