https://github.com/ez-engines/ez-tracer
Workflow tracing made easy
https://github.com/ez-engines/ez-tracer
ruby tracing workflow
Last synced: over 1 year ago
JSON representation
Workflow tracing made easy
- Host: GitHub
- URL: https://github.com/ez-engines/ez-tracer
- Owner: ez-engines
- License: mit
- Created: 2020-08-06T12:47:48.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-08-06T12:57:13.000Z (almost 6 years ago)
- Last Synced: 2025-01-24T03:25:58.076Z (over 1 year ago)
- Topics: ruby, tracing, workflow
- Language: Ruby
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Ez::Tracer

It is often hard to give an answer to the question: "What is fu#1ing going on in my app?". Why data is so strange? What changed the state, when and why?
It's because you don't trace workflows. EzTracer comes here to rescue you from blind and silent operations.
## How to use
```ruby
class MyOperation
# No magic include or inheritance, just initialize private memoized method like tracer
def call
# Log simple status message
tracer.log('Preparing some data...')
# ruby code that prepeared some data
# Log message and measure how much time it took since the last message
tracer.log('Data prepared', spent: true)
# ruby code changed this data
# Again log simple status message
tracer.log('Executing data change')
# Aggregate changed state
changed = ['a', 'b', 'c']
# Log aggregated state and measure how much it took to perform
tracer.log('Data has been changed', collection: changed, spent: true)
# Log complete of the workflow
tracer.done!
end
private
def tracer
@tracer ||= Ez::Tracer::Agent.new(
# Tracer need any global unique ID to identify reference later on
id: 'any-given-id',
# Define how an agent should store logged trace
storage: Ez::Tracer::Storage::FileSystem.new("logs/my_operation/#{'any-given-id'}-#{Time.now.utc.to_i}"),
# Agent by default will buffer all logs and save them on `done!`
# But you can change this behavior to save every line after log has been called
buffer: false,
# On every `log` execution you can trigger proc with current tracer object and message
stream: proc do |tracer, message|
NotificationsChannel.broadcast_to("tracer-#{'any-given-id'}", message: message)
end
end
end
operation = MyOperation.new
operation.call
operation.tracer.logs # =>
# 2020-08-05 12:57:13 UTC => Preparing some data...
# 2020-08-05 12:57:18 UTC => Data prepared. Spent 5 seconds
# 2020-08-05 12:57:18 UTC => Executing data change
# 2020-08-05 12:57:30 UTC => Data has been changed: a, b, c. Spent 12 seconds
# 2020-08-05 12:57:30 UTC => Done.
operation.tracer.save # => Persist traced logs within given storage backend
```
## Use cases
- Massive data transactions
- External API calls, request-response details
- CSV imports
- Long running background jobs
... any workflow execution where you need to track and log changes
## Storage backend
**Default STDOUT**
```ruby
Ez::Tracer::Storage::Stdout
```
**Local filesystem**
```ruby
Ez::Tracer::Storage::FileSystem.new('file_path')
```
**AWS S3**
```ruby
aws_credentials = {
bucket: ENV['AWS_S3_BUCKET'],
key_id: ENV['AWS_ACCESS_KEY_ID'],
access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: ENV['AWS_S3_REGION'],
endpoint: ENV['AWS_S3_ENDPOINT']
}
Ez::Tracer::Storage::AwsS3.new(aws_credentials, 'prefix/file_name')
```
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'ez-tracer'
```
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ez-tracer
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ez-tracer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ez-tracer/blob/master/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Ez::Tracer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ez-tracer/blob/master/CODE_OF_CONDUCT.md).