【问题标题】:Sentry Configuration not Working in Consumer Base Project哨兵配置在消费者基础项目中不起作用
【发布时间】:2021-10-19 22:53:20
【问题描述】:

最近我们的 12+ 微服务在不同端口的 AWS 服务器中运行。 有些项目是 api 基础,有些项目是消费者基础,所以最近我在 All this Project 中配置了哨兵,我们使用相同的 DNS 和不同的 EVN,例如`

此 API 项目

  1. 项目:API

类似的配置

sentry.dns=exmpale1
application.enviroment=PROD_API

这是消费者基础项目

  1. 项目:返回 类似的配置
sentry.dns=exmpale1
application.enviroment=PROD_BACK
  1. 项目:结束

类似的配置

sentry.dns=exmpale1
application.enviroment=PROD_OUT
  1. 项目:在

类似的配置

sentry.dns=exmpale1
application.enviroment=PROD_IN

所有项目都使用相同的配置 Java 类

@Configuration
public class SentryConfiguration {

  Logger logger = LoggerFactory.getLogger(SentryConfiguration.class);
  
  @Value("${sentry.dsn:null}")
  private String dsn;

  @Value("${application.environment:local}")
  private String environment;

  @EventListener
  public void onApplicationEvent(ContextRefreshedEvent event) {
    if (!"null".equalsIgnoreCase(dsn)) {
      SentryClient sentryClient = Sentry.init(dsn);
      sentryClient.setEnvironment(environment);
      logger.info("Sentry Configured for BACK");
    }
  }
}

【问题讨论】:

    标签: java spring spring-boot sentry


    【解决方案1】:

    您似乎正在使用 Sentry Java SDK 1.x。请升级到最新(当前为 5.1.0),并使用sentry-spring-boot-starter 可以在application.properties 文件中配置环境,无需任何额外的 Java 代码:

    sentry.dns=exmpale1
    sentry.enviroment=PROD_IN
    

    更多关于如何使用 Sentry Spring Boot Starter:https://docs.sentry.io/platforms/java/guides/spring-boot/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      相关资源
      最近更新 更多