public static IDisposable SetMdlcState(MappedDiagnosticsLogicalContextSetterProxy mdlc, Tracer tracer)
        {
            var spanContext = tracer.DistributedSpanContext;
            var array       = spanContext is null
                            ? new KeyValuePair <string, object> [3]
                            : new KeyValuePair <string, object> [5];

            array[0] = new KeyValuePair <string, object>(CorrelationIdentifier.ServiceKey, tracer.DefaultServiceName ?? string.Empty);
            array[1] = new KeyValuePair <string, object>(CorrelationIdentifier.VersionKey, tracer.Settings.ServiceVersion ?? string.Empty);
            array[2] = new KeyValuePair <string, object>(CorrelationIdentifier.EnvKey, tracer.Settings.Environment ?? string.Empty);

            if (spanContext is not null)
            {
                // For mismatch version support we need to keep requesting old keys.
                var hasTraceId = spanContext.TryGetValue(SpanContext.Keys.TraceId, out string traceId) ||
                                 spanContext.TryGetValue(HttpHeaderNames.TraceId, out traceId);
                var hasSpanId = spanContext.TryGetValue(SpanContext.Keys.ParentId, out string spanId) ||
                                spanContext.TryGetValue(HttpHeaderNames.ParentId, out spanId);
                if (hasTraceId && hasSpanId)
                {
                    array[3] = new KeyValuePair <string, object>(CorrelationIdentifier.TraceIdKey, traceId);
                    array[4] = new KeyValuePair <string, object>(CorrelationIdentifier.SpanIdKey, spanId);
                }
            }

            var state = mdlc.SetScoped(array);

            return(state);
        }
Example #2
0
        public static IDisposable SetMdlcState(MappedDiagnosticsLogicalContextSetterProxy mdlc, Tracer tracer)
        {
            var spanContext = tracer.DistributedSpanContext;
            var array       = spanContext is null
                            ? new KeyValuePair <string, object> [3]
                            : new KeyValuePair <string, object> [5];

            array[0] = new KeyValuePair <string, object>(CorrelationIdentifier.ServiceKey, tracer.DefaultServiceName ?? string.Empty);
            array[1] = new KeyValuePair <string, object>(CorrelationIdentifier.VersionKey, tracer.Settings.ServiceVersion ?? string.Empty);
            array[2] = new KeyValuePair <string, object>(CorrelationIdentifier.EnvKey, tracer.Settings.Environment ?? string.Empty);

            if (spanContext is not null &&
                spanContext.TryGetValue(HttpHeaderNames.TraceId, out string traceId) &&
                spanContext.TryGetValue(HttpHeaderNames.ParentId, out string spanId))
            {
                array[3] = new KeyValuePair <string, object>(CorrelationIdentifier.TraceIdKey, traceId);
                array[4] = new KeyValuePair <string, object>(CorrelationIdentifier.SpanIdKey, spanId);
            }

            var state = mdlc.SetScoped(array);

            return(state);
        }