Skip to content

Instantly share code, notes, and snippets.

@cheoalfredo
Created March 24, 2022 13:22
Show Gist options
  • Save cheoalfredo/a2e041ab5a0a05e2d5989a49b99bc622 to your computer and use it in GitHub Desktop.
Save cheoalfredo/a2e041ab5a0a05e2d5989a49b99bc622 to your computer and use it in GitHub Desktop.
Extract propagated context from message headers
private IEnumerable<string> ExtractHeaders(IBasicProperties prop, string key)
{
try
{
if (prop.Headers.TryGetValue(key, out var value))
{
var bytes = value as byte[] ?? throw new Exception("no value");
return new[] { System.Text.Encoding.UTF8.GetString(bytes) };
}
}
catch (Exception e)
{
_logger.LogError("Error extracting context", e);
}
return Enumerable.Empty<string>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment