/// <summary>
        ///     Create a new Span.
        /// </summary>
        /// <param name="tracer">Tracer that will record the span.</param>
        /// <param name="operationName">Operation name being recorded by the span.</param>
        /// <param name="startTimestamp">The <see cref="DateTimeOffset" /> at which the span begun.</param>
        /// <param name="tags">Tags for the span.</param>
        /// <param name="references">References to other spans.</param>
        public Span(
            Tracer tracer,
            string operationName,
            DateTimeOffset startTimestamp,
            IDictionary <string, object> tags,
            IReadOnlyCollection <Reference> references)
        {
            _tracer        = tracer;
            OperationName  = operationName;
            StartTimestamp = startTimestamp;

            _tags = tags == null
                ? new Dictionary <string, object>()
                : new Dictionary <string, object>(tags);

            _references = references == null
                ? new List <Reference>()
                : references.ToList();


            var parentContext = FindPreferredParentRef(_references);

            OperationName  = operationName.Trim();
            StartTimestamp = startTimestamp;

            if (parentContext == null)
            {
                // we are a root span
                _context = new SpanContext(GetRandomId(), GetRandomId(), new Baggage());
                ParentId = null;
            }
            else
            {
                // we are a child span
                _context = new SpanContext(parentContext.TraceId, GetRandomId(), MergeBaggages(_references),
                                           parentContext.SpanId);
                ParentId = parentContext.SpanId;
            }
            if (_tracer._options.EnableMetaEventLogging && Utilities.IsNotMetaSpan(this))
            {
                _tracer.BuildSpan(LightStepConstants.MetaEvent.TracerCreateOperation)
                .IgnoreActiveSpan()
                .WithTag(LightStepConstants.MetaEvent.MetaEventKey, true)
                .WithTag(LightStepConstants.MetaEvent.SpanIdKey, _context.SpanId)
                .WithTag(LightStepConstants.MetaEvent.TraceIdKey, _context.TraceId)
                .Start()
                .Finish();
            }
        }
        private void OnFinished()
        {
            var spanData = new SpanData
            {
                Context        = this.TypedContext(),
                OperationName  = OperationName,
                StartTimestamp = StartTimestamp,
                Duration       = FinishTimestamp - StartTimestamp,
                Tags           = _tags,
                LogData        = _logs
            };

            _tracer.AppendFinishedSpan(spanData);
            if (_tracer._options.EnableMetaEventLogging && Utilities.IsNotMetaSpan(this))
            {
                _tracer.BuildSpan(LightStepConstants.MetaEvent.SpanFinishOperation)
                .IgnoreActiveSpan()
                .WithTag(LightStepConstants.MetaEvent.MetaEventKey, true)
                .WithTag(LightStepConstants.MetaEvent.SpanIdKey, this.TypedContext().SpanId)
                .WithTag(LightStepConstants.MetaEvent.TraceIdKey, this.TypedContext().TraceId)
                .Start()
                .Finish();
            }
        }