<commit_before>﻿using System;
using System.Diagnostics;
using Vostok.Airlock;
using Vostok.Commons.Collections;
using Vostok.Flow;

namespace Vostok.Tracing
{
    internal class SpanBuilder : ISpanBuilder
    {
        private const string SpanContextName = "Vostok.Tracing.Span";
        private readonly string airlockRoutingKey;
        private readonly IAirlock airlock;
        private readonly PoolHandle<Span> spanHandle;
        private readonly TraceContextScope contextScope;
        private readonly TraceConfiguration configuration;
        private readonly Stopwatch stopwatch;
        private readonly Span parentSpan;

        public SpanBuilder(
            string operationName,
            string airlockRoutingKey,
            IAirlock airlock,
            PoolHandle<Span> spanHandle,
            TraceContextScope contextScope,
            TraceConfiguration configuration)
        {
            this.airlockRoutingKey = airlockRoutingKey;
            this.airlock = airlock;
            this.spanHandle = spanHandle;
            this.contextScope = contextScope;
            this.configuration = configuration;

            stopwatch = Stopwatch.StartNew();

            parentSpan = Context.Properties.Get<Span>(SpanContextName);

            InitializeSpan(operationName ?? parentSpan?.OperationName);
            EnrichSpanWithContext();
            EnrichSpanFromParentSpan();
        }

        private void EnrichSpanFromParentSpan()
        {
            if (parentSpan == null)
            {
                return;<commit_msg>Add set span to context<commit_after>﻿using System;
using System.Diagnostics;
using Vostok.Airlock;
using Vostok.Commons.Collections;
using Vostok.Flow;

namespace Vostok.Tracing
{
    internal class SpanBuilder : ISpanBuilder
    {
        private const string SpanContextName = "Vostok.Tracing.Span";
        private readonly string airlockRoutingKey;
        private readonly IAirlock airlock;
        private readonly PoolHandle<Span> spanHandle;
        private readonly TraceContextScope contextScope;
        private readonly TraceConfiguration configuration;
        private readonly Stopwatch stopwatch;
        private readonly Span parentSpan;

        public SpanBuilder(
            string operationName,
            string airlockRoutingKey,
            IAirlock airlock,
            PoolHandle<Span> spanHandle,
            TraceContextScope contextScope,
            TraceConfiguration configuration)
        {
            this.airlockRoutingKey = airlockRoutingKey;
            this.airlock = airlock;
            this.spanHandle = spanHandle;
            this.contextScope = contextScope;
            this.configuration = configuration;

            stopwatch = Stopwatch.StartNew();

            parentSpan = Context.Properties.Get<Span>(SpanContextName);

            InitializeSpan(operationName ?? parentSpan?.OperationName);
            EnrichSpanWithContext();
            EnrichSpanFromParentSpan();
            Context.Properties.Set(SpanContextName, Span);
        }

        private void EnrichSpanFromParentSpan()
        {
            if (parentSpan == null)
            {
                return;
{'fraction_non_alphanumeric': 0.0609487904492617, 'fraction_numerical': 0.0, 'mean_word_length': 2.3063343717549327, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1765621', 'n_tokens_mistral': 741, 'n_tokens_neox': 750, 'n_words': 181}