Created
March 24, 2022 13:22
-
-
Save cheoalfredo/a2e041ab5a0a05e2d5989a49b99bc622 to your computer and use it in GitHub Desktop.
Extract propagated context from message headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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