Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error propagating cutom trace-id on pub/sub #1231

Open
rochabr opened this issue Mar 4, 2025 · 2 comments
Open

Error propagating cutom trace-id on pub/sub #1231

rochabr opened this issue Mar 4, 2025 · 2 comments
Labels
kind/bug Something isn't working

Comments

@rochabr
Copy link

rochabr commented Mar 4, 2025

Expected Behavior

Dapr runtime: 1.15.5
Dapr Cli: 1.15.0
Java SDK: 1.13.3

I'm expecting to see the same trace-id for my publisher and subscriber on zipkin when I set a custom trace-id as a metadata when I call PublishEvent. Ie:

Image

Sample code:

// Create order data
Map<String, Object> order = new HashMap<>();
String orderId = UUID.randomUUID().toString();
order.put("orderId", orderId);
order.put("customer", "test-customer");
order.put("amount", 100.00);
order.put("timestamp", System.currentTimeMillis());

// Create metadata to override CloudEvent properties
Map<String, String> metadata = new HashMap<>();
metadata.put("cloudevent.traceid", "your-custom-trace-id");
metadata.put("cloudevent.source", "order-service");
metadata.put("cloudevent.type", "com.example.order");
metadata.put("cloudevent.id", UUID.randomUUID().toString());

// Publish with metadata
return daprClient.publishEvent(
        PUBSUB_NAME,
        TOPIC_NAME,
        order,
        metadata
).then(Mono.fromCallable(() -> {
    String response = "Published order with ID: " + orderId;
    logger.info(response);
    return response;
}));

Actual Behavior

Following the example above, Zipkin shows 2 different entries for the publisher and subscriber.each with its own trace-id:

Image

Steps to Reproduce the Problem

Run the sample here: https://github.com/rochabr/dapr-trace-example

@rochabr rochabr added the kind/bug Something isn't working label Mar 4, 2025
@salaboy
Copy link
Contributor

salaboy commented Mar 4, 2025

@rochabr I am not sure if this is a bug.. I think adding a cloudevent trace.id doesn't automatically propagate the trace to the right place.

Look at this example on how the context is propagated: https://github.com/salaboy/pizza/blob/observability/pizza-store/src/main/java/io/diagrid/dapr/PizzaStore.java#L220

The trick is in:

.contextWrite(getReactorContext(context))

By adding this code, we are grabbing the context from the Reactor framework in Spring and propagating the incoming trace to Dapr.

@rochabr
Copy link
Author

rochabr commented Mar 5, 2025

@salaboy I think I'm missing a few steps here. to pass this context from the publisher to the subscriber it needs to be fetched somehow. I couldn't find in your project how to do it.

I see an import statement to import io.diagrid.dapr.otel.OpenTelemetryConfig.getReactorContext; which cannot be resolved with the dapr-spring-boot-starter dependency. Can you help me understand or point me to the docs that explain how to fetch context, modify the trace and propagate to the subscriber?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants