Skip to content

OpenTelementry trace context wrong on grouped multi #52152

@magro

Description

@magro

Describe the bug

In our quarkus application we use reactive messaging / mutiny and OpenTelemetry tracing. There we discovered, that for a KeyedMulti (or GroupedMulti in general) the traceId / trace context is wrong for all elements after the first one of a given substream.

With the following example:

@Incoming("items")
@Outgoing("processed-items")
fun processItems(items: Multi<String>): Multi<Triple<String, String, String>> {
    return items
        .map { item ->
            val traceId = Span.fromContext(Context.current()).spanContext.traceId
            item to traceId
        }
        .group().by { it.first[0] }
        .flatMap {
            it.onItem().transform { (item, originalTraceId) ->
                // The traceId for the 2nd item in each substream is wrong (it's the traceId of the first item)
                val traceId = Span.fromContext(Context.current()).spanContext.traceId
                Triple(item, originalTraceId, traceId)
            }
        }
}
  • for input items "a1" and "a2"
  • with traceIds "t1" (for "a1") and "t2" (for "a2")

Expected behavior

The expected outgoing/processed results are Triple("a1", "t1", "t1") and Triple("a2", "t2", "t2")

Actual behavior

Actually the outgoing/processed results are Triple("a1", "t1", "t1") and Triple("a2", "t2", "t1")

How to Reproduce?

I have setup a reproducer here: https://github.com/magro/quarkus-mutiny-tracing/

Output of uname -a or ver

Linux mescalin 6.18.4-100.fc42.x86_64

Output of java -version

openjdk version "23.0.1" 2024-10-15 OpenJDK Runtime Environment (build 23.0.1+11-39) OpenJDK 64-Bit Server VM (build 23.0.1+11-39, mixed mode, sharing)

Quarkus version or git rev

3.30.6

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9 (Red Hat 3.9.9-14)

Additional information

No response

Metadata

Metadata

Assignees

Type

Projects

Status

Todo

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions