/// <inheritdoc />
        public IDisposable StartSpan(string name, StartSpanOptions options = null)
        {
            GaxPreconditions.CheckNotNull(name, nameof(name));
            options = options ?? StartSpanOptions.Create();

            TraceSpan span = new TraceSpan();

            span.SpanId    = _spanIdFactory.NextId();
            span.Kind      = options.SpanKind.Convert();
            span.Name      = name;
            span.StartTime = Timestamp.FromDateTime(DateTime.Now.ToUniversalTime());

            lock (_stackLock)
            {
                if (_traceStack.Count != 0)
                {
                    span.ParentSpanId = _traceStack.Peek().SpanId;
                }
                else if (_rootSpanParentId != null)
                {
                    span.ParentSpanId = (ulong)_rootSpanParentId;
                }

                _traceStack.Push(span);
                AnnotateSpan(options.Labels);
            }

            return(new Span(this));
        }
예제 #2
0
        /// <inheritdoc />
        public IDisposable StartSpan(string name, StartSpanOptions options = null)
        {
            GaxPreconditions.CheckNotNull(name, nameof(name));
            options = options ?? StartSpanOptions.Create();

            var currentStack = TraceStack;
            var span         = new TraceSpan
            {
                SpanId       = _spanIdFactory.NextId(),
                Kind         = options.SpanKind.Convert(),
                Name         = name,
                StartTime    = Timestamp.FromDateTime(DateTime.UtcNow),
                ParentSpanId = GetCurrentSpanId(currentStack).GetValueOrDefault()
            };

            AnnotateSpan(span, options.Labels);

            TraceStack = currentStack.Push(span);

            Interlocked.Increment(ref _openSpanCount);
            return(new Span(this));
        }