agorapulse / grails-sentry

A Sentry client for Grails
Apache License 2.0
12 stars 14 forks source link

stackTrace sanitizer #53

Closed wmedjek closed 4 years ago

wmedjek commented 4 years ago

The goal of the PR is to provide an option to sanitize the stack trace exception

Changes:

Another change has been made, not necessary for sanitizing the stack trace, but which was my first option. I added the possibility to the user of the plugin to provide his own SentryClientFactory. Cause with the actual method, it seems that we can only use the default one. The only problem is that the sentryFactory is no more registred.

musketyr commented 4 years ago

I like the idea but removing sentryFactory and adding grailsSentryClientFactory may break some existing code.

what about creating something like sentryClientFactoryFactory as a factory of SentryClientFactory? The name is horrible so maybe you can figure out something more creative :-)

@Slf4j
class SentryClientFactoryFactory {

    SentryClientFactory createFactory() {
            String sentryClientFactoryName = Lookup.lookup("factory", realDsn);
            if (Util.isNullOrEmpty(sentryClientFactoryName)) {
                // no name specified, use the default factory
                return new DefaultSentryClientFactory();
            } else {
                // attempt to construct the user specified factory class
                Class<? extends SentryClientFactory> factoryClass = null;
                try {
                    factoryClass = (Class<? extends SentryClientFactory>) Class.forName(sentryClientFactoryName);
                    return factoryClass.newInstance();
                } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                    log.error("Error creating SentryClient using factory class: '"
                        + sentryClientFactoryName + "'.", e);
                    return null;
                }
            }
    }

}

see io.sentry.SentryClientFactory#sentryClient(java.lang.String, io.sentry.SentryClientFactory) for reference.

then you can use the new factory to create the sentry factory:

sentryClientFactoryFactory(SentryClientFactoryFactory)
sentryFactory(sentryClientFactoryFactory: 'createFactory')

WDYT @wmedjek