Sending Kafka and ZooKeeper logs to Sentry (using log4j)

Hello,

Has anyone here ever tried to send Kafka and ZooKeeper logs to Sentry?

Since Apache Kafka and ZooKeeper are important services, I would like to redirect their error messages to Sentry. However, I’m not sure how to configure log4j to do so.

First I configured the log4j.properties file, which Kafka uses to learn its logging policy, with the following settings:

log4j.rootLogger=INFO, stdout, SentryAppender
log4j.appender.SentryAppender=com.getsentry.raven.log4j.SentryAppender
log4j.appender.SentryAppender.dsn=https://a6c1ffcb34e8442e8f9e2d62680d0910:3dcbddac54df410aa7c74f4772715f2d@sentry.io/130726
log4j.appender.SentryAppender.tags=dc:1,service:kafka
log4j.appender.SentryAppender.ravenFactory=com.getsentry.raven.DefaultRavenFactory
log4j.appender.SentryAppender.Threshold=WARN

However, Kafka’s output shows it couldn’t instantiate the Raven class queried by the Sentry Appender:

log4j:ERROR Could not instantiate class [com.getsentry.raven.log4j.SentryAppender].
java.lang.ClassNotFoundException: com.getsentry.raven.log4j.SentryAppender

According to the log4j module (https://docs.sentry.io/clients/java/modules/log4j/) Raven can be installed using Maven. However, since I haven’t compiled Kafka by myself, there is no pom.xml I can use to place this dependency.

How should I proceed?

Thanks in advance.

Gabriel.

We discussed this over SaaS support last week, but here are the details for anyone searching for this in the future:

I haven’t tested this in a while, but to the best of my recollection, all you’ll need to do is ensure that the raven-log4j JAR file (and all of it’s dependencies, as documented in the README) are included in the CLASSPATH environment variable when running the service scripts (e.g. bin/kafka-server-start.sh or bin/zkServer.sh, etc.) If you’re using a daemon like upstart to manage the server processes, you’ll need to ensure the CLASSPATH variable is set in those scripts.

1 Like