Beispiel #1
0
        private ZipkinSpanContext GetOrCreateContext()
        {
            ulong spanId = GetRandomId();

            // Only one reference is supported right now - the rest is ignored.
            var parent = (ZipkinSpanContext)SpanReferences.FirstOrDefault()?.ReferencedContext;

            if (parent != null)
            {
                return(parent.CreateChild(spanId));
            }
            else
            {
                // This is a root span!

                bool sampled = false;

                if (IntTags.Any(x => x.Key == Tags.SamplingPriority && x.Value == 1))
                {
                    sampled = true;
                }
                else if (_tracer.Sampler.IsSampled(spanId))
                {
                    sampled = true;

                    foreach (var tag in _tracer.Sampler.GetTags())
                    {
                        WithTag(tag.Key, tag.Value);
                    }
                }

                // TraceId and SpanId may be equal: http://zipkin.io/pages/instrumenting.html
                return(new ZipkinSpanContext(spanId, spanId, parentId: null, sampled: sampled, baggage: null));
            }
        }
        public int?GetIntTag(string key)
        {
            var kvp = IntTags.FirstOrDefault(x => string.Equals(x.Key, key));

            return(kvp.Key == null ? (int?)null : kvp.Value);
        }