Skip to content

Tubitv/logger_sentry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LoggerSentry

Build Status Module Version Hex Docs Total Download License Last Updated

The Logger backend for Sentry.

Installation

The package can be installed as:

Add :logger_sentry to your mix.exs file:

def deps do
  [
    {:logger_sentry, "~> 0.6.0"}
  ]
end

Configure your config file, just like:

config :logger,
  backends: [:console, Logger.Backends.Sentry],
  sentry: [
    level: :error,
    metadata: [:application, :module, :function, :file, :line, :pid] # :all
  ]

If you want keep :console backend in Logger event server, you should set :backends with [:console, Logger.Backends.Sentry]. Just like :console backend, the sentry backend supports the same :level and :metadata options.

Usage

Similar to Logger.

Logger.debug("this is one debug message")
Logger.info("this is one info message")
Logger.warning("this is one warning message")

# if you set sentry logger level with `:error`, the message will sent to your
# sentry server
Logger.error("this is one error message")

Get log level

Logger.Backends.Sentry.level

Set log level

Logger.Backends.Sentry.level(:error)

Get metadata

Logger.Backends.Sentry.metadata

Set metadata

Logger.Backends.Sentry.metadata([])
Logger.Backends.Sentry.metadata(:all)
Logger.Backends.Sentry.metadata([:application, :module, :pid])

Fingerprints

To use fingerprints in sentry dashboard, set :logger_sentry option to define generate fingerprints modules:

config :logger_sentry,
  fingerprints_mods: [
    LoggerSentry.Fingerprint.MatchMessage,
    LoggerSentry.Fingerprint.CodeLocation,
    MyApp.Fingerprint.MyModule
  ]

Only match error message, LoggerSentry.Fingerprint.MatchMessage and code location, LoggerSentry.Fingerprint.CodeLocation are available by default right now.

You can define your own module, for example, MyApp.Fingerprint.MyModule, by adding a fingerprints/2 function.

Examples

See additional usage examples at wiki.

Rate Limiting

Sentry can be configured with a rate limit on the Sentry servers. Any messages received faster than that limit will not be processed. In order to avoid unnecessary traffic and potentially getting IP-blocked by Sentry, it is recommended to add rate limiting on your own servers.

By default, LoggerSentry does not enforce rate limits. Rate limiting can be added through your project config files like this:

import Config

config :logger_sentry, LoggerSentry.RateLimiter,
    rate_limiter_module: LoggerSentry.RateLimiter.TokenBucket,
    rate_limiter_options: [token_count: 20, interval_ms: 60_000]

LoggerSentry comes with a simple token bucket algorithm. You may add other rate-limiting algorithms by creating a module that conforms to the LoggerSentry.RateLimiter module. Then setting rate_limiter_module to your custom module.

Copyright and License

Copyright (c) 2017 Taotao Lin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.