Hello,

I originally posted this issue in the micrometer tracing, but since it seems to be related to multiple dependencies, I moved it here.

I found a problem with duplicate TraceIds on repeated requests when using the @NewSpan annotation, with datasource-micrometer auto-configured.

SpringBoot Duplicated traceId when using @NewSpan and datasource-micrometer auto-configured

This is a project that can reproduce this issue. https://github.com/0tak2/simpletodo-otel

Reproduction conditions

  1. Micrometer Tracing is Auto Configured with Spring Boot Actuator
  2. Tracing is exported to OpenTelemetry Collector
  3. using @NewSpan with micrometer.observations.annotations.enabled set to true in Spring Boot Properties

* The versions of the related libraries are as follows SpringBoot Duplicated traceId when using @NewSpan and datasource-micrometer auto-configured
SpringBoot Duplicated traceId when using @NewSpan and datasource-micrometer auto-configured

Reproduction Scenario

  • Repeat the data add request (POST /todo) and retrieve request (GET /todo) with HTTP test tool (see: https://github.com/0tak2/simpletodo-otel/blob/main/http/todo.http)
  • Or, open the web client (/client/index.html) in multiple tabs and repeat adding Todo data. (Each time a CUD operation is performed, a websocket event is published to make clients retrieve new data.) SpringBoot Duplicated traceId when using @NewSpan and datasource-micrometer auto-configured

Additional notes

  • The issue is only reproduced when both of the following conditions are met
    1. Set micrometer.observations.annotations.enabled to true and use @NewSpan
    2. include the dependency net.ttddyy.observation:datasource-micrometer-spring-boot.

I would appreciate it if you could take a look at this issue, or if you have any tips on debugging the part of the code where the TraceId is specified, I will try to analyse the code.

Comment From: mhalbritter

Hello,

I don't think that the issue is in Spring Boot. Spring Boot only provides auto-configuration for the tracing system. If this only happens when @NewSpan is used and net.ttddyy.observation:datasource-micrometer-spring-boot is used, I suspect the bug is in one of those components. Maybe it's even in the websocket code, I can't tell, as there's a lot going on in this project.

I'd suggest trying to reduce the complexity by ripping parts out (is the websocket code needed? Does it work without @NewSpan? Does it work without the datasource instrumentation?) and then re-opening the micrometer-tracing issue or creating an issue in the affected component.

The class which manages the span is io.micrometer.tracing.otel.bridge.OtelTracer.

If there's really a bug in Spring Boot, please don't hesitate to comment here and I'll reopen this issue.

Comment From: 0tak2

I am sorry for my confusion, and thank you for taking a closer look at this issue nonetheless. I'll try to refine the issue and raise it again in micrometer tracing or datasource or another repository.