Coder Social home page Coder Social logo

grails-sentry's Introduction

Sentry Grails Plugin

Build Status Download

Introduction

Sentry plugin provides a Grails client for integrating apps with Sentry. Sentry is an event logging platform primarily focused on capturing and aggregating exceptions.

It uses the official Sentry.io client under the cover.

Installation

Declare the plugin dependency in the build.gradle file, as shown here:

dependencies {
    ...
    compile("org.grails.plugins:sentry:11.7.25")
    ...
}

Config

Add your Sentry DSN to your grails-app/conf/application.yml.

grails:
    plugin:
        sentry:
            dsn: https://{PUBLIC_KEY}:{SECRET_KEY}@app.getsentry.com/{PATH}{PROJECT_ID}

The DSN can be found in project's Settings under Client Keys (DSN) section.

The plugin will sent notifications to Sentry by default, if you want to disable notifications for an specific environment set the active option as false.

environments:
    development:
        grails:
            plugin:
                sentry:
                    active: false
    test:
        grails:
            plugin:
                sentry:
                    active: false

You can also configure the multiple logger to which you want to append the sentry appender. You can also set the server name, but it is recommended to don't set this configuration and let the plugin to resolve it.

Optional configurations

# Not tested on Grails 3 plugin...
grails:
    plugin:
        sentry:
            dsn: https://foo:[email protected]/123
            loggers: [LOGGER1, LOGGER2, LOGGER3]
            environment: staging
            serverName: dev.server.com
            levels: [ERROR]
            tags: {tag1: val1,  tag2: val2, tag3: val3}
            subsystems: 
                MODULE1: [com.company.services.module1, com.company.controllers.module1]
                MODULE2: [com.company.services.module2, com.company.controllers.module2]
                MODULE3: [com.company.services.module3, com.company.controllers.module3]
            logClassName: true
            logHttpRequest: true
            disableMDCInsertingServletFilter: true
            springSecurityUser: true
            springSecurityUserProperties:
                id: 'id'
                email: 'emailAddress'
                username: 'login'
                data: # Additional properties to be retrieved from user details object and passed as extra properties to Sentry user interface.
                    - 'authorities'
            priorities: 
                HIGH: [java.lang, com.microsoft.sqlserver.jdbc.SQLServerException]
                MID: [com.company.exception]
                LOW: [java.io]

Check Sentry-java documentation to configure connection, protocol and async options in your DSN. If you are sending extra tags from the plugin for the exceptions, make sure to enable the corresponding tag on sentry tag settings for the particular project to see the tag as a filter on the exception stream on sentry.

Usage

Logback Appender

The Logback Appender is automatically configured by the plugin, you just have to set enabled environments as shown in Configuration section.

All application exceptions will be logged on sentry by the appender. The appender is configured to log just the ERROR and WARN levels. To log manually just use the log.error() method.

sentryClient

You also can use sentryClient to sent info messages to Sentry:

import io.sentry.SentryClient
import io.sentry.event.Event
import io.sentry.event.EventBuilder
import io.sentry.event.interfaces.ExceptionInterface

SentryClient sentryClient // To inject Spring bean raven client in your controllers or services

// Send simple message
sentryClient?.sendMessage("some message")

// Send exception
sentryClient?.sendException(new Exception("some exception"))

// Custom event
EventBuilder eventBuilder = new EventBuilder()
           .withMessage("This is a test")
           .withLevel(Event.Level.INFO)
           .withLogger(MyClass.class.name)

sentryClient?.sendEvent(eventBuilder.build())

Latest releases

  • 2018-07-16 V11.7.25 : upgrade Sentry java lib to 1.7.25 + stack trace sanitizer
  • 2018-07-16 V11.7.24 : upgrade Sentry java lib to 1.7.24 + Grails 4 upgrade
  • 2018-05-18 V11.7.4 : upgrade Sentry java lib to 1.7.4 + bug fixes
  • 2018-02-09 V11.6.5 : upgrade Sentry java lib to 1.6.5 + bug fixes
  • 2017-11-09 V11.4.0.3 : fixes
  • 2017-08-03 V11.4.0.2 : fixes
  • 2017-08-03 V11.4.0 : upgrade Sentry java lib to 1.4.0 + bug fix, thanks to donbeave PR #37
  • 2017-07-17 V11.3.0 : upgrade Sentry java lib to 1.3.0 + bug fix, thanks to donbeave PR #34
  • 2017-07-04 V11.2.0 : upgrade Sentry java lib to 1.2.0 (which replaces the deprecated Raven java lib)
  • 2017-06-06 V8.0.3 : upgrade Raven java lib to 8.0.3
  • 2017-02-01 V7.8.1 : upgrade Raven java lib to 7.8.1
  • 2016-11-22 V7.8.0.2 : event environment support
  • 2016-10-29 V7.8.0.1 : minor bug fix, thanks to donbeave PR
  • 2016-10-19 V7.8.0 : upgrade Raven java lib to 7.8.0
  • 2016-10-10 V7.7.1 : upgrade Raven java lib to 7.7.1
  • 2016-09-27 V7.7.0.1 : bug fix
  • 2016-09-26 V7.7.0 : upgrade Raven java lib to 7.7.0, release support added to events
  • 2016-08-22 V7.6.0 : upgrade Raven java lib to 7.6.0, Spring Security integration improvements, thanks to donbeave PR
  • 2016-07-22 V7.4.0 : upgrade Raven java lib to 7.4.0, better logging and support for Spring Security Core , thanks to donbeave PR
  • 2016-06-22 V7.3.0 : upgrade Raven java lib to 7.3.0
  • 2016-05-03 V7.2.1 : upgrade Raven java lib to 7.2.1
  • 2016-04-12 V7.1.0.1 : minor update
  • 2016-04-06 V7.1.0 : upgrade Raven java lib to 7.1.0, thanks to donbeave PR (WARNING: Raven package has been renamed from net.kencochrane.raven to com.getsentry.raven)
  • 2015-08-31 V6.0.0 : initial release for Grails 3.x

Bugs

To report any bug, please use the project Issues section on GitHub.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

License

Copyright © 2016 Alan Rafael Fachini, authors, and contributors. All rights reserved.

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

Maintained by

Agorapulse & Scentbird

grails-sentry's People

Contributors

alfakini avatar anujku avatar benorama avatar donbeave avatar erichelgeson avatar jglapa avatar musketyr avatar pcontezini avatar svenresch avatar wmedjek avatar zhuravskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grails-sentry's Issues

`unknown` value for ipAddress is unable to be parsed by sentry.io

I recently forgot to turn on request logging (so the request obj was not available to parse) and the plugin tried to use the value unknown for the ipAddress of the sentry.interfaces.User. sentry.io was unable to parse this -
screen shot 2018-01-25 at 1 05 16 pm

A work around may be as simple as having the default be 127.0.0.1 instead of unknown. Let me know (I can open a PR if that's an acceptable work around)

Exception grouping different than from raven-java

This was about grouping of exceptions. Currently, I see the grouping is based on the the exception message. But sometimes two exception messages could be similar with only Ids changed in the message.

Case in point is these exceptions below -

MissingMethodException occurred when processing request: [POST] /platformservices/zones/
No signature of method: net.nosegrind.restrpc.RestRPCService$_getParams_closure1.doCall() is applicable for argument types: (org.codehaus.groovy.grails.web.json.JSONObject) values: [[conceptId:16611, zones:[added:[], updated:[...], ...]]]
Possible solutions: doCall(java.lang.Object, java.lang.Object), call(), call([Ljava.lang.Object;), call(java.lang.Object), call(java.lang.Object, java.lang.Object), findAll(). Stacktrace follows:
MissingMethodException occurred when processing request: [POST] /platformservices/zones/
No signature of method: net.nosegrind.restrpc.RestRPCService$_getParams_closure1.doCall() is applicable for argument types: (org.codehaus.groovy.grails.web.json.JSONObject) values: [[conceptId:16610, zones:[added:[], updated:[...], ...]]]
Possible solutions: doCall(java.lang.Object, java.lang.Object), call(), call([Ljava.lang.Object;), call(java.lang.Object), call(java.lang.Object, java.lang.Object), findAll(). Stacktrace follows:

So apart from Id in the message these exceptions are totally same. But they are still not grouped together. Logically I would say grouping here is correct. What do you think ?

Looks like it is fixed in ravaen-java. The grails-plugin will need an update.

getsentry/sentry-java#125
getsentry/sentry-java#126

Plugins does not seem to work in Grails 3.3.0 anymore

I am using the Sentry plugin for all my applications. I am upgrading to grails 3.3.0 and I cannot get the plugin working anymore. I can send messages from the client, but the logback appender does not report issues anymore.
Is the plugin available for grails 3.3.0?

Allow for tag adding

My use case is that I would like to add a tag to each event.
I cannot use the grails.plugin.sentry.tags config property because the value of that tag is known after the app has started.

In my case it's a grails config property but I imagine that you could also want to load it from a db or from somewhere else.
Using MDC would work but it's too much overhead ( I could create a filter to add it in each request but for not web context bound threads this would be difficult )

I found a way to do it as a big hack in Bootstrap.groovy
I'm basically adding this to the SentryConfig after the Appender has been initialized

def sentryAppenderBeanName = 'sentryAppender'
if (grailsApplication.mainContext.containsBeanDefinition(sentryAppenderBeanName)) {
      def sentryAppender = grailsApplication.mainContext.getBean(sentryAppenderBeanName)
      sentryAppender.config.tags.put('mySpecialTag', grailsApplication.config.my.property)
}

Can I put our company's logo as one of maintainer of this plugin?

I will be happy to see our logo in footer of README file, like this:

Maintained by

snip20160722_48 2 & snip20160722_47 2

Because we use this plugin in production for all of our services, and we love to improve it to provide better exception information and support all of Sentry features on time. We want to be one of a company behind this plugin who use it in production and release bugfixes.

If it's okay with you, I glad to see us in the footer.

By the way, I already create PR for this: #24

User IP in custom header

Is there a way to recognize the User IP sent in a custom request header that is not listed in here? Any configuration options, workarounds, anything?

Appenders don't work

When an exception occurs, it prints:
LOGBACK: No context given for grails.plugin.sentry.GrailsLogbackSentryAppender[null]

Cannot disable the plugin in test env.

I cannot disable the plugin in test environment.
After looking a bit closer it seems that the plugin jar contains application-test.yml config file which is overriding the config in test env

I've inspected the 2 most recent versions v11.6.5 and v11.7.4 and both have that file included.

Error initializing the application: net/kencochrane/raven/event/Event$Level

I'm using the last version of the plugin (6.0.0.4) and Grails 2.5.0 and when I execute run-app I get the following error:

| Error 2015-04-23 09:03:09,987 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: net/kencochrane/raven/event/Event$Level
Message: net/kencochrane/raven/event/Event$Level
    Line | Method
->> 2701 | privateGetDeclaredMethods in java.lang.Class
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1975 | getDeclaredMethods        in     ''
|    266 | run . . . . . . . . . . . in java.util.concurrent.FutureTask
|   1142 | runWorker                 in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                       in java.lang.Thread
Caused by ClassNotFoundException: net.kencochrane.raven.event.Event$Level
->>  381 | findClass                 in java.net.URLClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    424 | loadClass                 in java.lang.ClassLoader
|    357 | loadClass . . . . . . . . in     ''
|   2701 | privateGetDeclaredMethods in java.lang.Class
|   1975 | getDeclaredMethods . . .  in     ''
|    266 | run                       in java.util.concurrent.FutureTask
|   1142 | runWorker . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    617 | run                       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . . . in java.lang.Thread

Is this a know issue?

Incompatibility with Grails 3.3.0

Location of FilterRegistrationBean has changed to org.springframework.boot.web.servlet

import org.springframework.boot.context.embedded.FilterRegistrationBean

java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
	at grails.plugin.sentry.SentryGrailsPlugin$_doWithSpring_closure1.doCall(SentryGrailsPlugin.groovy:78)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)

Process only ERROR level

How to configure the plugin to login only ERROR events?

Having this in my config I would expect only error events to be published

grails.plugin.sentry.levels = ['ERROR']

but looking at the source code it will fall back to the defaults which contains also WARN

if (config.levels && config.levels.contains(event.level)) {
super.append(event)
} else if (SentryConfig.defaultLevels.contains(event.level)) {
super.append(event)
}

java.lang.ClassNotFoundException: net.kencochrane.raven.event.Event

Hello,
I tried to switch to Raven plugin 6.0.0 so I've added to my BuildConfig.groovy next line:
compile ':raven:0.5.8'
After that I got next error:
ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'sentryAppender': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [grails.plugins.raven.GrailsLog4jSentryAppender]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: net/kencochrane/raven/event/Event
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sentryAppender': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [grails.plugins.raven.GrailsLog4jSentryAppender]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: net/kencochrane/raven/event/Event
Can you pls help?

How can I add mapped tags?

I have filter:

    def filters = {

        all(controller: '*', action: '*') {
            before = {
                def principal = securityService.principal

                MDC.clear()
                MDC.put("PrincipalID", principal.hasProperty('id') ? principal.id : "N/A")
            }
        }
    }

And follow Config.groovy:

// log4j.appender.SentryAppender.mappedTags=['PrincipalID']
log4j.appender.GrailsLog4jSentryAppender.mappedTags=['PrincipalID']

The PrincipalID exists in Additional Data section, but tags not appeared in Sentry.
What am I doing wrong?

Support for "release" config property

It does not seem like I can add "release" configuration with this plugin. There appears to be some other ones as well when compared to the java configuration.

I was looking at the code, and wanted to make a PR, but wasn't quite sure how to get the release-config from SentryConfig.groovy all the way to sentry.

I would assume more people would appreciate this config, so I kindly suggest this as a feature request.

Additional Data

After read log4j and raven integration i see that i can use MDC to send information to the "Additional Data" tag. It should be as simple as:

MDC.push("key", "value")
logger.error("error message")

Is this supported by grails-raven or should i use a different way to send extra data?

Thanks in advance.

Raven.uninstall functionality

Is there a way to have uninstall functionality for raven client ?
(Or a way to set grails.plugins.raven.active = false somewhere in the code )
It is available for Raven.js. It will make a whole lot of impact.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.