예제 #1
0
        /// <inheritdoc/>
        public void Inject <T>(SpanContext spanContext, T carrier, Action <T, string, string> setter)
        {
            if (!spanContext.IsValid)
            {
                OpenTelemetryApiEventSource.Log.FailedToInjectSpanContext("Invalid context");
                return;
            }

            if (carrier == null)
            {
                OpenTelemetryApiEventSource.Log.FailedToInjectSpanContext("null carrier");
                return;
            }

            if (setter == null)
            {
                OpenTelemetryApiEventSource.Log.FailedToInjectSpanContext("null setter");
                return;
            }

            var traceparent = string.Concat("00-", spanContext.TraceId.ToHexString(), "-", spanContext.SpanId.ToHexString());

            traceparent = string.Concat(traceparent, (spanContext.TraceFlags & ActivityTraceFlags.Recorded) != 0 ? "-01" : "-00");

            setter(carrier, TraceParent, traceparent);

            string tracestateStr = TracestateUtils.GetString(spanContext.Tracestate);

            if (tracestateStr.Length > 0)
            {
                setter(carrier, TraceState, tracestateStr);
            }
        }
        /// <inheritdoc/>
        public void Inject <T>(SpanContext spanContext, T carrier, Action <T, string, string> setter)
        {
            var traceparent = string.Concat("00-", spanContext.TraceId.ToHexString(), "-", spanContext.SpanId.ToHexString());

            traceparent = string.Concat(traceparent, (spanContext.TraceOptions & ActivityTraceFlags.Recorded) != 0 ? "-01" : "-00");

            setter(carrier, "traceparent", traceparent);

            string tracestateStr = TracestateUtils.GetString(spanContext.Tracestate);

            if (tracestateStr.Length > 0)
            {
                setter(carrier, "tracestate", tracestateStr);
            }
        }