in src/Services.Remoting/OmexRemotingHeadersExtensions.cs [66:102]
public static Activity? StartActivityFromIncomingRequest(this IServiceRemotingRequestMessage requestMessage, DiagnosticListener listener, string name)
{
if (!listener.IsEnabled(name))
{
return null;
}
IServiceRemotingRequestMessageHeader headers = requestMessage.GetHeader();
string parentId = string.Empty;
if (headers.TryGetHeaderValue(TraceParentHeaderName, out byte[] idBytes))
{
parentId = s_encoding.GetString(idBytes);
}
Activity? activity = listener.CreateAndStartActivity(name, parentId);
if (activity == null)
{
return null;
}
if (headers.TryGetHeaderValue(TraceStateHeaderName, out byte[] baggageBytes))
{
KeyValuePair<string, string>[] baggage = DeserializeBaggage(baggageBytes);
// AddBaggage adds items at the beginning of the list, so we need to add them in reverse to keep the same order as the client
// An order could be important if baggage has two items with the same key (that is allowed by the contract)
for (int i = baggage.Length - 1; i >= 0; i--)
{
KeyValuePair<string, string> pair = baggage[i];
activity.AddBaggage(pair.Key, pair.Value);
}
}
return activity;
}