Distributed Tracing - Get traceId at time message is published

With the Distributed Tracing Extension enabled, I am able to see that the resulting traceId is made available to subscribers of sampled messages through the “userProperties” > “traceparent” field. This is a powerful way for us to make subscribers aware of the trace context for messages that are recieved.

However, we have a need for a publisher to see this traceId at the time a message is published. We are using the latest version of the hivemq-mqtt-client (1.3.0) and I can see that the Mqtt5PublishResult object has a “userProperties” field in the “pubAck”. However, it is not populated with the “traceparent” like we’re seeing in the message received by subscribers.

Is there any way for us to get the traceId in the PublishResult for messages that are sampled by the Distributed Tracing Extension?

Thanks!

Hi @lgaskill ,

Great to see your interest in MQTT and HiveMQ, welcome to the community! There is no configuration option to get the traceId in the PublishResult for messages that are sampled by the Distributed Tracing Extension.

If there was such option, what would you use it for? Can you share your use case with us?

Thanks,
Dasha from HiveMQ team

Hey @Daria_H,

Thanks for the prompt response! My specific use case is that I’m looking to integrate the information that the trace gives us with our internal auditing system. Right now, the application that is responsible for creating audit logs for system changes is also responsible for publishing the changes to our IoT devices (should be decoupled, I know :frowning:). But what I was hoping to do was embed the traceId into each audit record, so our support staff and engineers can quickly drill into the trace associated with each audit log.

ALTERNATIVELY, I suppose I could get by with just the message id. I am currently using Grafana Tempo to persist, analyze and search traces. I should be able to use the tempo search API to locate each specific trace by message id, right?

So in that case, is it possible for the the hivemq-mqtt-client to get the resulting message id on publish?

Thanks again!

Hi @lgaskill ,

If your MQTT clients support MQTT v5 you could add any custom ID to each Publish as User Property. We have User Properties nicely explained in Part 6 of the MQTT 5 Essentials lecture course..

In case that does not match your use case: The HiveMQ Enterprise Edition comes with a HiveMQ Enterprise Extension SDK, which can be leveraged for what you are trying to achieve.

I suggest you reach out to our colleagues at sales@hivemq.com and schedule a meeting to dive deeper into your specific requirements.

Kind regards,
Dasha from HiveMQ team