Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ dependencies {
implementation(projects.sentryAsyncProfiler)
implementation(projects.sentryOpentelemetry.sentryOpentelemetryAgentlessSpring)

// kafka
implementation(libs.spring.kafka3)

// cache tracing
implementation(libs.springboot3.starter.cache)
implementation(libs.caffeine)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.sentry.samples.spring.boot.jakarta;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Profile("kafka")
public class KafkaConsumer {

private static final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class);

@KafkaListener(topics = "sentry-topic", groupId = "sentry-sample-group")
public void listen(String message) {
logger.info("Received message: {}", message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.sentry.samples.spring.boot.jakarta;

import org.springframework.context.annotation.Profile;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Profile("kafka")
@RequestMapping("/kafka")
public class KafkaController {

private final KafkaTemplate<String, String> kafkaTemplate;

public KafkaController(KafkaTemplate<String, String> kafkaTemplate) {
this.kafkaTemplate = kafkaTemplate;
}

@GetMapping("/produce")
String produce(@RequestParam(defaultValue = "hello from sentry!") String message) {
kafkaTemplate.send("sentry-topic", message);
return "Message sent: " + message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Kafka โ€” activate with: --spring.profiles.active=kafka
sentry.enable-queue-tracing=true

spring.autoconfigure.exclude=
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=sentry-sample-group
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer

logging.level.org.apache.kafka=warn
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ spring.graphql.graphiql.enabled=true
spring.graphql.websocket.path=/graphql
spring.quartz.job-store-type=memory

# Kafka is only active with the 'kafka' profile (--spring.profiles.active=kafka)
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration

# Cache tracing
sentry.enable-cache-tracing=true
spring.cache.cache-names=todos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ dependencies {
implementation(libs.otel)
implementation(projects.sentryAsyncProfiler)

// kafka
implementation(libs.spring.kafka3)

// cache tracing
implementation(libs.springboot3.starter.cache)
implementation(libs.caffeine)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.sentry.samples.spring.boot.jakarta;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Profile("kafka")
public class KafkaConsumer {

private static final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class);

@KafkaListener(topics = "sentry-topic", groupId = "sentry-sample-group")
public void listen(String message) {
logger.info("Received message: {}", message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.sentry.samples.spring.boot.jakarta;

import org.springframework.context.annotation.Profile;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Profile("kafka")
@RequestMapping("/kafka")
public class KafkaController {

private final KafkaTemplate<String, String> kafkaTemplate;

public KafkaController(KafkaTemplate<String, String> kafkaTemplate) {
this.kafkaTemplate = kafkaTemplate;
}

@GetMapping("/produce")
String produce(@RequestParam(defaultValue = "hello from sentry!") String message) {
kafkaTemplate.send("sentry-topic", message);
return "Message sent: " + message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Kafka โ€” activate with: --spring.profiles.active=kafka
sentry.enable-queue-tracing=true

spring.autoconfigure.exclude=
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=sentry-sample-group
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer

logging.level.org.apache.kafka=warn
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ spring.graphql.graphiql.enabled=true
spring.graphql.websocket.path=/graphql
spring.quartz.job-store-type=memory

# Kafka is only active with the 'kafka' profile (--spring.profiles.active=kafka)
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration

# Cache tracing
sentry.enable-cache-tracing=true
spring.cache.cache-names=todos
Expand Down
Loading