in Elastiflix/java-favorite-elastic-manual/src/main/java/com/movieapi/ApiServlet.java [131:146]
private void handleCanary() throws Exception {
Random random = new Random();
if (sleepTime > 0 && random.nextDouble() < 0.5) {
double randomGaussDelay = Math.min(sleepTime*5, Math.max(0, random.nextGaussian() * (sleepTime)));
TimeUnit.MILLISECONDS.sleep((long) randomGaussDelay);
logger.info("Canary enabled");
Transaction transaction = ElasticApm.currentTransaction();
transaction.setLabel("quiz_solution", "correlations");
transaction.setLabel("canary", "test-new-feature");
if (random.nextDouble() < toggleCanaryFailure) {
logger.error("Something went wrong");
throw new Exception("Something went wrong");
}
}
}