コード例 #1
0
        private static void Inject <TMessageRequest>(SpanContext context, IDictionary messageAttributes)
        {
            // Consolidate headers into one JSON object with <header_name>:<value>
            var sb = Util.StringBuilderCache.Acquire(Util.StringBuilderCache.MaxBuilderSize);

            sb.Append('{');
            SpanContextPropagator.Instance.Inject(context, sb, default(StringBuilderCarrierSetter));
            sb.Remove(startIndex: sb.Length - 1, length: 1); // Remove trailing comma
            sb.Append('}');

            var resultString = Util.StringBuilderCache.GetStringAndRelease(sb);

            messageAttributes[SqsKey] = CachedMessageHeadersHelper <TMessageRequest> .CreateMessageAttributeValue(resultString);
        }
コード例 #2
0
        public static void InjectHeadersIntoMessage <TMessageRequest>(IContainsMessageAttributes carrier, SpanContext spanContext)
        {
            // add distributed tracing headers to the message
            if (carrier.MessageAttributes == null)
            {
                carrier.MessageAttributes = CachedMessageHeadersHelper <TMessageRequest> .CreateMessageAttributes();
            }

            // SQS allows a maximum of 10 message attributes: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes
            // Only inject if there's room
            if (carrier.MessageAttributes.Count < 10)
            {
                Inject <TMessageRequest>(spanContext, carrier.MessageAttributes);
            }
        }