sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Spring Boot Queue Integration

Open adinauer opened this issue 1 year ago • 1 comments

Problem Statement

Automatically instrument Spring Boot queues. Might require different implementation for JMS, AMQP and other integrations.

Solution Brainstorm

One major problems seems to be supported characters for headers / properties. Specifically dash/hyphen/- is not supported by Java JMS API (setStringProperty). We need it to support tracing using sentry-trace. While it'd be possible to replace the character in the Java SDK, we'd have to then support this way of naming the header/property in all other SDKs.

OpenTelemetry seems to deal with this by replacing the - with a special String (__dash__). However they only seem to be doing this for their Java SDK, so they'll likely run into problems with different SDKs for producer vs. consumer.

  • https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/5b2d1b29bd63fd6484a3237490d2646cf09d44d1/instrumentation/jms/jms-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/MessagePropertyGetter.java#L25
  • https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/5b2d1b29bd63fd6484a3237490d2646cf09d44d1/instrumentation/jms/jms-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/MessagePropertySetter.java#L22
  • https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/5b2d1b29bd63fd6484a3237490d2646cf09d44d1/instrumentation/jms/jms-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/MessagePropertySetter.java#L18
  • https://github.com/opentracing-contrib/java-jms/pull/20/files

The easiest way forward is to not fully support tracing when using JMS until we have a different set of headers that can be used instead.

adinauer avatar Jun 04 '24 13:06 adinauer

Tested with org.springframework.boot:spring-boot-starter-artemis. Writing to the queue will enforce the jms specification and throw an exception: AMQ139012: The property name 'sentry-trace' is not a valid java identifier When reading from the queue this is not enforced, i.e. a stringProperty with key sentry-trace can be successfully read.

The JMS specification can be downloaded here: https://jcp.org/aboutJava/communityprocess/final/jsr343/index.html

The relevant section is 3.8.1.1, which is referenced by Section 3.5.1

lbloder avatar Jun 07 '24 13:06 lbloder