Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo in README & code inline comments #28

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/melvrickgoh/event_tracer" }
source 'https://rubygems.org'

# Specify your gem's dependencies in event_tracer.gemspec
gemspec

group :test do
gem 'aws-sdk-dynamodb'
gem 'nokogiri'
gem 'prometheus-client'
gem 'sidekiq'
gem 'timecop'
gem 'prometheus-client'
end
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ EventTracer.info(
message: 'There is an action',
metrics: {
metric_1: { type: :counter, value: 12 },
metric_2: { type: :gauce, value: 1 },
metric_2: { type: :gauge, value: 1 },
metric_3: { type: :distribution, value: 10 }
}
)
Expand All @@ -131,7 +131,7 @@ Appsignal >= 2.5 is currently supported for the following metric functions:
|------------------------|-----------------|
| increment_counter | counter |
| add_distribution_value | distribution |
| set_gauge | gauce |
| set_gauge | gauge |

We can also add [tags](https://docs.appsignal.com/metrics/custom.html#metric-tags) for metric:

Expand Down Expand Up @@ -232,7 +232,7 @@ registry = if Sidekiq.server?
else
Prometheus.registry
end

logger = EventTracer::Prometheus.new(registry, allowed_tags: [], default_tags: {})
EventTracer.register :prometheus, logger
```
Expand All @@ -242,16 +242,16 @@ Then you can track your metrics using the same interface that `EventTracer` prov
*Notes*
- For multi-processes app, we need to choose the `DirectFileStore` for Prometheus's data store. Read on [Data store](https://github.com/prometheus/client_ruby#data-stores) for more information.

- Prometheus requires every metrics to be pre-registered before we can track them. In `EventTracer`, by default it will raise the error for any unregistered metrics. Alternative, we provide a `raise_if_missing` flag to allow just-in-time metric registration.
- Prometheus requires every metrics to be pre-registered before we can track them. In `EventTracer`, by default it will raise the error for any unregistered metrics. Alternative, we provide a `raise_if_missing` flag to allow just-in-time metric registration.
```ruby
logger = EventTracer::Prometheus.new(
registry,
allowed_tags: [],
registry,
allowed_tags: [],
default_tags: {},
raise_if_missing: false # this will register the missing metric instead of raising error
)
```
However, doing so defeats the purpose of being clear on what metrics we want to track and can also result in a performance penalty.
However, doing so defeats the purpose of being clear on what metrics we want to track and can also result in a performance penalty.
To make the metrics registration less tedious, we recommend you to standardize your custom metrics name.

### Results
Expand Down Expand Up @@ -306,7 +306,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/melvrickgoh/event_tracer.
Bug reports and pull requests are welcome on GitHub at https://github.com/Kaligo/event_tracer.

## License

Expand Down
2 changes: 1 addition & 1 deletion lib/event_tracer/appsignal_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# EventTracer::AppsignalLogger.new(Appsignal, allowed_tags: ['tag_1', 'tag_2'])
#
# appsignal_logger.info metrics: [:counter_1, :counter_2]
# appsignal_logger.info metrics: { counter_1: { type: :counter, value: 1 }, gauce_2: { type: :gauce, value: 10 } }
# appsignal_logger.info metrics: { counter_1: { type: :counter, value: 1 }, gauge_2: { type: :gauge, value: 10 } }
module EventTracer
class AppsignalLogger < MetricLogger

Expand Down
12 changes: 8 additions & 4 deletions lib/event_tracer/buffered_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def execute_payload(payloads)
filtered_payloads = filter_invalid_data(payloads)

EventTracer.warn(
loggers: %i(base),
loggers: %i[base],
action: self.class.name,
app: EventTracer::Config.config.app_name,
error: e.class.name,
Expand All @@ -46,12 +46,16 @@ def execute_payload(payloads)
)

worker.perform_async(filtered_payloads) if filtered_payloads.any?
rescue StandardError => error
raise EventTracer::ErrorWithPayload.new(error, payloads)
rescue StandardError => e
raise EventTracer::ErrorWithPayload.new(e, payloads)
end

def filter_invalid_data(payloads)
payloads.select { |payload| payload.to_json rescue false }
payloads.select do |payload|
payload.to_json
rescue StandardError
false
end
end
end
end
10 changes: 5 additions & 5 deletions lib/event_tracer/dynamo_db/default_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module DynamoDB
class DefaultProcessor
def call(log_type, action:, message:, args:)
args.merge(
timestamp: Time.now.utc.iso8601(6),
action: action,
message: message,
log_type: log_type,
app: EventTracer::Config.config.app_name
'timestamp' => Time.now.utc.iso8601(6),
'action' => action,
'message' => message,
'log_type' => log_type.to_s,
'app' => EventTracer::Config.config.app_name
)
end
end
Expand Down
24 changes: 14 additions & 10 deletions spec/event_tracer/dynamo_db/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
let(:payload) do
{
message: 'Some message',
action: 'Testing',
log_type: :info
action: 'Testing'
}
end
let(:expected_log_worker_payload) do
[{
message: 'Some message',
action: 'Testing',
log_type: :info,
timestamp: '2020-02-09T12:34:56.000000Z',
app: EventTracer::Config.config.app_name
'message' => 'Some message',
'action' => 'Testing',
'log_type' => 'info',
'timestamp' => '2020-02-09T12:34:56.000000Z',
'app' => EventTracer::Config.config.app_name
}]
end

Expand All @@ -44,8 +43,7 @@
let(:payload) do
{
message: "\xAE",
action: 'Testing',
log_type: :info
action: 'Testing'
}
end
let(:expected_log_worker_payload) do
Expand All @@ -55,7 +53,13 @@
error: 'JSON::GeneratorError',
loggers: [:base],
app: EventTracer::Config.config.app_name,
payload: [hash_including(payload)]
payload: [
hash_including(
'log_type' => 'info',
'action' => 'Testing',
'message' => "\xAE"
)
]
}
end

Expand Down
Loading