Chamod Pathirana
Chamod Pathirana

Reputation: 758

Sentry log4j2 appender cannot add environment

I am using the Sentry log4j appender(version: 5.7.1) to send logged exceptions to Sentry. bellow is the log4j2.xml configuration.

 <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" packages="org.apache.logging.log4j.core,io.sentry.log4j2">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    <Sentry name="Sentry"
            dsn="https://dsn" />
  </Appenders>
  <Loggers>
    <Root level="info">
      <AppenderRef ref="Sentry"/>
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

Now I need to add a specific environment in order to differentiate records based on the QA and Production environment. when I add environment="qa", it gives following error.

ERROR Sentry contains an invalid element or attribute "environment"

Upvotes: 1

Views: 718

Answers (1)

Maciej Walkowiak
Maciej Walkowiak

Reputation: 12932

In Log4j2 integration, properties other than "dsn" can be configured either using:

  • environment variable: "SENTRY_ENVIRONMENT=qa"
  • system property "sentry.environment=qa"
  • sentry.properties file with content: environment=qa

Read more in docs: https://docs.sentry.io/platforms/java/configuration/

Upvotes: 1

Related Questions