I have a library I share among several micro services. The library contains helper methods to read messages from Kafka. As part of the message, I have a trace id that I want to use to start new Activity:
(simplified pseudo code)
// code that is using my library
var message = await mylibrary.GetMessageFromKafka();
// I expect Activity.Current to be set here after calling the library, but it is null
In GetMessageFromKafka I'm trying to change the current Activity:
public async Task<Message> GetMessageFromKafka()
{
// ... read message from Kafka (not important here) ...
var activity = new Activity("NewMessageReceived");
activity.SetParent(messageFromKafka.Traceparent);
activity.Start();
return message;
}
The current activity does not propagate back to the caller, after calling GetMessageFromKafka(), Activity.Current is null for the code that is using my library.
Is there any way to change the current activity of the parent context from my library code?