Search code examples
node.jsazure-eventhub

correlationid for azure events


What is the correct way to add a correlation-id to azure events ?

Right now, I send the events as follows:

const { EventHubProducerClient } = require('@azure/event-hubs');

const producer = new EventHubProducerClient(connectionString, eventHubName);
const batch = await producer.createBatch();
batch.tryAdd({
  body: {
    foo: "bar"
  }
});
await producer.sendBatch(batch);

Of course as a workaround I could just add my own field to the body. However, I suspect that there is a built-in mechanism or default approach to do this.


Solution

  • The latest release exposes a correlationId property on EventData, which corresponds to the correlation-id field of the message properties section of the underlying AMQP message.

    One important call-out is that the correlationId is intended to enable tracing of data within an application, such as an event's path from producer to consumer. It has no meaning to the Event Hubs service or within a distributed tracing/AppInsights/OpenTelemetry context.