示例#1
0
 public PrefixSpan(
     ISpan inner,
     string prefix )
 {
     _inner = inner;
     _prefix = prefix;
 }
 private SpanBuilder(string name, SpanBuilderOptions options, ISpanContext remoteParentSpanContext = null, ISpan parent = null)
 {
     this.Name   = name ?? throw new ArgumentNullException(nameof(name));
     this.Parent = parent;
     this.RemoteParentSpanContext = remoteParentSpanContext;
     this.Options = options;
 }
 public override void OnEnd(ISpan span)
 {
 }
 internal static ISpanBuilder CreateWithParent(string spanName, ISpan parent, SpanBuilderOptions options)
 {
     return(new SpanBuilder(spanName, options, null, parent));
 }
 private bool TryAddSpan(string activityId, ISpan span)
 {
     return(_activeSpanDic.TryAdd(activityId, span));
 }
示例#6
0
 public void QueueSpan(ISpan span) => EnqueueEvent(span, "Span");
示例#7
0
 public void Record(ISpan span)
 {
     _eventBus.PublishAsync(new TracingEvent(SpanContractUtils.CreateFromSpan(span)));
 }
示例#8
0
      private void recordSourceMappingSpanStart(ISpan ast) 
      {
         if (this.sourceMapper!=null && ASTHelpers.isValidSpan(ast)) 
         {
               LineCol lineCol = new LineCol() { line = -1, character = -1 };
               var sourceMapping = new SourceMapping();
               sourceMapping.start.emittedColumn = this.emitState.column;
               sourceMapping.start.emittedLine = this.emitState.line;
               // REVIEW: check time consumed by this binary search (about two per leaf statement)
               var lineMap = this.document.lineMap();
               lineMap.fillLineAndCharacterFromPosition(ast.start(), lineCol);
               sourceMapping.start.sourceColumn = lineCol.character;
               sourceMapping.start.sourceLine = lineCol.line + 1;
               lineMap.fillLineAndCharacterFromPosition(ast.end(), lineCol);
               sourceMapping.end.sourceColumn = lineCol.character;
               sourceMapping.end.sourceLine = lineCol.line + 1;

               /*
               Debug.assert(!isNaN(sourceMapping.start.emittedColumn));
               Debug.assert(!isNaN(sourceMapping.start.emittedLine));
               Debug.assert(!isNaN(sourceMapping.start.sourceColumn));
               Debug.assert(!isNaN(sourceMapping.start.sourceLine));
               Debug.assert(!isNaN(sourceMapping.end.sourceColumn));
               Debug.assert(!isNaN(sourceMapping.end.sourceLine));
               */

               if (this.sourceMapper.currentNameIndex.Count > 0) {
                  sourceMapping.nameIndex = this.sourceMapper.currentNameIndex[this.sourceMapper.currentNameIndex.Count - 1];
               }
               // Set parent and child relationship
               var siblings = this.sourceMapper.currentMappings[this.sourceMapper.currentMappings.Count - 1];
               siblings.Add(sourceMapping);
               this.sourceMapper.currentMappings.Add(sourceMapping.childMappings);
               this.sourceMapper.increaseMappingLevel(ast);
         }
      }
示例#9
0
 public static IContinousLoad Create(ISpan span, double temperatureDifference)
 {
     return(new AlongTemperatureDifferenceLoad(
                new LoadData(0, 0),
                new LoadData(span.Length, temperatureDifference)));
 }
        private ClientInterceptorContext <TRequest, TResponse> SetJaegerHeader <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, ISpan span)
            where TRequest : class
            where TResponse : class
        {
            var header = context.Options.Headers?.Where(p => p.Key == JaegerTracingMiddleware.jaegerKey).FirstOrDefault();

            if (header == null)
            {
                var metaEntry = new Metadata.Entry("jaeger", span.Context.ToString());
                if (context.Options.Headers == null)
                {
                    var meta = new Metadata();
                    meta.Add(metaEntry);
                    var callOptions = context.Options.WithHeaders(meta);
                    context = new ClientInterceptorContext <TRequest, TResponse>(context.Method, context.Host, callOptions);
                }
                else
                {
                    context.Options.Headers.Add(metaEntry);
                }
            }
            return(context);
        }
示例#11
0
 public override ISpanBuilder SpanBuilderWithExplicitParent(string spanName, ISpan parent = null)
 {
     return(Trace.SpanBuilder.CreateWithParent(spanName, parent, spanBuilderOptions));
 }
示例#12
0
 public Span(ISpan other)
 {
     this.StartPosition       = other.StartPosition;
     this.step                = other.Step;
     this.RaisesChangedEvents = true;
 }
示例#13
0
 /// <summary>
 /// Registers a continuation on the task.
 /// Within the continuation it ends the transaction and captures errors
 /// </summary>
 private static void RegisterContinuation(Task task, ISpan span) => task.ContinueWith(t =>
示例#14
0
 public void QueueSpan(ISpan span)
 {
     lock (_lock)
         _spans.Add(span);
 }
示例#15
0
        public void Parse(ISpan span)
        {
            //TODO: store if a splitpoint is special case, do not try to fetch hash if not!
            var separators = CharacterClasses.WhitespaceCharacters;
            var textSpan   = span.ValueAsSpan;

            bool hasEmoji = false;

            for (int i = 0; i < textSpan.Length - 1; i++)
            {
                if (textSpan.Slice(i).IsEmoji(out _))
                {
                    hasEmoji = true; break;
                }
            }

            var splitPoints = new List <SplitPoint>(textSpan.Length / 4);

            int offset = 0, sufix_offset = 0;

            while (true)
            {
                if (splitPoints.Count > textSpan.Length)
                {
                    throw new InvalidOperationException(); //If we found more splitting points than actual characters on the span, we hit a bug in the tokenizer
                }

                offset      += sufix_offset;
                sufix_offset = 0;
                if (offset > textSpan.Length)
                {
                    break;
                }
                var splitPoint = textSpan.IndexOfAny(separators, offset);
                ReadOnlySpan <char> candidate;

                if (splitPoint == offset)
                {
                    //Happens on sequential separators
                    offset++; continue;
                }

                if (splitPoint < 0)
                {
                    candidate  = textSpan.Slice(offset);
                    splitPoint = offset + candidate.Length;
                    if (candidate.Length == 0)
                    {
                        break;
                    }
                }
                else
                {
                    candidate = textSpan.Slice(offset, splitPoint - offset);
                }

                //Special case to split also at emojis
                if (hasEmoji)
                {
                    for (int i = 0; i < (candidate.Length - 1); i++)
                    {
                        if (candidate.Slice(i).IsEmoji(out var emojiLength))
                        {
                            if (i == 0)
                            {
                                splitPoint = offset + emojiLength - 1;
                                candidate  = candidate.Slice(0, emojiLength);
                            }
                            else
                            {
                                splitPoint = offset + i - 1;
                                candidate  = candidate.Slice(0, i);
                            }
                            break;
                        }
                    }
                }

                while (!candidate.IsEmpty)
                {
                    int hash = candidate.CaseSensitiveHash32();
                    if (SpecialCases.ContainsKey(hash))
                    {
                        splitPoints.Add(new SplitPoint(offset, splitPoint - 1, SplitPointReason.Exception));
                        candidate = new ReadOnlySpan <char>();
                        offset    = splitPoint + 1;
                        continue;
                    }
                    else if (candidate.IsLikeURLorEmail())
                    {
                        splitPoints.Add(new SplitPoint(offset, splitPoint - 1, SplitPointReason.EmailOrUrl));
                        candidate = new ReadOnlySpan <char>();
                        offset    = splitPoint + 1;
                        continue;
                    }
                    else if (hasEmoji && candidate.IsEmoji(out var emojiLength))
                    {
                        splitPoints.Add(new SplitPoint(offset, offset + emojiLength - 1, SplitPointReason.Emoji));
                        candidate = candidate.Slice(emojiLength);
                        offset   += emojiLength;
                        continue;
                    }
                    else
                    {
                        if (candidate.Length == 1)
                        {
                            splitPoints.Add(new SplitPoint(offset, offset, SplitPointReason.SingleChar));
                            candidate = new ReadOnlySpan <char>();
                            offset    = splitPoint + 1;
                            continue;
                        }

                        if (!candidate.IsAllLetterOrDigit())
                        {
                            if (candidate.IsSentencePunctuation() || candidate.IsHyphen() || candidate.IsSymbol())
                            {
                                splitPoints.Add(new SplitPoint(offset, splitPoint - 1, SplitPointReason.Punctuation));
                                candidate = new ReadOnlySpan <char>();
                                offset    = splitPoint + 1;
                                continue;
                            }

                            int prefixLocation = FindPrefix(candidate);
                            if (prefixLocation >= 0)
                            {
                                splitPoints.Add(new SplitPoint(offset + prefixLocation, offset + prefixLocation, SplitPointReason.Prefix));
                                candidate = candidate.Slice(prefixLocation + 1);
                                offset   += prefixLocation + 1;
                                continue;
                            }

                            var(sufixIndex, sufixLength) = FindSufix(candidate);

                            if (sufixIndex > -1)
                            {
                                splitPoints.Add(new SplitPoint(offset + sufixIndex, offset + sufixIndex + sufixLength - 1, SplitPointReason.Sufix));
                                candidate     = candidate.Slice(0, sufixIndex);
                                splitPoint    = offset + sufixIndex;
                                sufix_offset += sufixLength;
                                continue;
                            }

                            var infixLocation = FindInfix(candidate);
                            if (infixLocation.Count > 0)
                            {
                                int in_offset = offset;

                                foreach (var(index, length) in infixLocation)
                                {
                                    if ((offset + index - 1) >= in_offset)
                                    {
                                        splitPoints.Add(new SplitPoint(in_offset, offset + index - 1, SplitPointReason.Infix));
                                    }

                                    //Test if the remaining is not an exception first
                                    if ((in_offset - offset + index) <= candidate.Length)
                                    {
                                        var rest     = candidate.Slice(in_offset - offset + index);
                                        int hashRest = rest.CaseSensitiveHash32();

                                        if (SpecialCases.ContainsKey(hashRest))
                                        {
                                            in_offset = offset + index;
                                            break;
                                        }
                                    }
                                    in_offset = offset + index + length;
                                    splitPoints.Add(new SplitPoint(offset + index, offset + index + length - 1, SplitPointReason.Infix));
                                }

                                candidate = candidate.Slice(in_offset - offset);

                                offset = in_offset;
                                continue;
                            }
                        }
                    }

                    splitPoints.Add(new SplitPoint(offset, splitPoint - 1, SplitPointReason.Normal));
                    candidate = new ReadOnlySpan <char>();
                    offset    = splitPoint + 1;
                }
            }

            int spanBegin = span.Begin;
            int pB = int.MinValue, pE = int.MinValue;

            span.ReserveTokens(splitPoints.Count);
            foreach (var sp in splitPoints.OrderBy(s => s.Begin).ThenBy(s => s.End))
            {
                int b = sp.Begin;
                int e = sp.End;

                if (pB == b && pE == e)
                {
                    continue;
                }
                pB = b; pE = e;

                if (b > e)
                {
                    Logger.LogError("Error processing text: '{DOC}', found token with begin={b} and end={e}", span.Value, b, e);
                    throw new InvalidOperationException();
                }

                while (char.IsWhiteSpace(textSpan[b]) && b < e)
                {
                    b++;
                }

                while (char.IsWhiteSpace(textSpan[e]) && e > b)
                {
                    e--;
                }

                int hash = textSpan.Slice(b, e - b + 1).CaseSensitiveHash32();

                if (e < b)
                {
                    Logger.LogError("Error processing text: '{DOC}', found token with begin={b} and end={e}", span.Value, b, e);
                    continue;
                }

                if (SpecialCases.TryGetValue(hash, out TokenizationException exp))
                {
                    if (exp.Replacements is null)
                    {
                        var tk = span.AddToken(spanBegin + b, spanBegin + e);
                    }
                    else
                    {
                        //TODO: Tokens begins and ends are being artificially placed here, check in the future how to better handle this
                        int begin2 = spanBegin + b;
                        for (int i = 0; i < exp.Replacements.Length; i++)
                        {
                            //Adds replacement tokens sequentially, consuming one char from the original document at a time, and
                            //using the remaing chars in the last replacement token
                            var tk = span.AddToken(begin2, ((i == exp.Replacements.Length - 1) ? (spanBegin + e) : begin2));
                            tk.Replacement = exp.Replacements[i];
                            begin2++;
                        }
                    }
                }
                else
                {
                    var tk = span.AddToken(spanBegin + b, spanBegin + e);
                    if (sp.Reason == SplitPointReason.EmailOrUrl)
                    {
                        tk.AddEntityType(new EntityType("EmailOrURL", EntityTag.Single));
                    }
                }
            }
        }
示例#16
0
 public void increaseMappingLevel(ISpan ast) {
     this.mappingLevel.Add(ast);
 }
示例#17
0
 public override void ConsiderForSampling(ISpan span)
 {
 }
 public override ISpan StartSpan(string operationName, ISpan parent, SpanKind kind, SpanCreationOptions options)
 {
     return(this.realTracer != null?this.realTracer.StartSpan(operationName, parent, kind, options) : BlankSpan.Instance);
 }
 public void Record(ISpan span)
 {
     _dispatcher.Dispatch(SpanContractUtils.CreateFromSpan(span));
 }
 /// <summary>
 /// Sets the sampling priority for the trace that contains the specified <see cref="ISpan"/>.
 /// </summary>
 /// <param name="span">A span that belongs to the trace.</param>
 /// <param name="samplingPriority">The new sampling priority for the trace.</param>
 public static void SetTraceSamplingPriority(this ISpan span, SamplingPriority samplingPriority)
 {
     span.SetTraceSamplingPriority((int)samplingPriority);
 }
示例#21
0
 public virtual void Handle(Exception e, ISpan span)
 {
     SetError(span);
 }
示例#22
0
 public abstract ISpanBuilder SpanBuilderWithExplicitParent(string spanName, ISpan parent = null);
示例#23
0
 protected static void SetError(ISpan span)
 {
     Tags.Error.Set(span, true);
 }
示例#24
0
 public override void OnStart(ISpan span)
 {
 }
示例#25
0
 public static void SetCurrentSpan(this ITracer tracer, ISpan spanContext)
 {
     SpanLocal.Current = spanContext;
 }
示例#26
0
        private ISpan StartSpanInternal(
            ISpanContext parent,
            bool hasRemoteParent,
            string name,
            ISampler sampler,
            IEnumerable <ISpan> parentLinks,
            bool recordEvents,
            ITimestampConverter timestampConverter)
        {
            ITraceParams        activeTraceParams = this.Options.TraceConfig.ActiveTraceParams;
            IRandomGenerator    random            = this.Options.RandomHandler;
            ITraceId            traceId;
            ISpanId             spanId       = SpanId.GenerateRandomId(random);
            ISpanId             parentSpanId = null;
            TraceOptionsBuilder traceOptionsBuilder;

            if (parent == null || !parent.IsValid)
            {
                // New root span.
                traceId             = TraceId.GenerateRandomId(random);
                traceOptionsBuilder = TraceOptions.Builder();

                // This is a root span so no remote or local parent.
                // hasRemoteParent = null;
                hasRemoteParent = false;
            }
            else
            {
                // New child span.
                traceId             = parent.TraceId;
                parentSpanId        = parent.SpanId;
                traceOptionsBuilder = TraceOptions.Builder(parent.TraceOptions);
            }

            traceOptionsBuilder.SetIsSampled(
                MakeSamplingDecision(
                    parent,
                    hasRemoteParent,
                    name,
                    sampler,
                    parentLinks,
                    traceId,
                    spanId,
                    activeTraceParams));
            TraceOptions traceOptions = traceOptionsBuilder.Build();
            SpanOptions  spanOptions  = SpanOptions.None;

            if (traceOptions.IsSampled || recordEvents)
            {
                spanOptions = SpanOptions.RecordEvents;
            }

            ISpan span = Span.StartSpan(
                SpanContext.Create(traceId, spanId, traceOptions, parent?.Tracestate ?? Tracestate.Empty),
                spanOptions,
                name,
                parentSpanId,
                hasRemoteParent,
                activeTraceParams,
                this.Options.StartEndHandler,
                timestampConverter,
                this.Options.Clock);

            LinkSpans(span, parentLinks);
            return(span);
        }
示例#27
0
        public override double CalculateSpanLoadVectorNormalForceMember(ISpan span, bool leftNode)
        {
            double distanceFromOtherNode = leftNode ? span.Length - this.Position : this.Position;

            return(-this.Value * distanceFromOtherNode / span.Length);
        }
示例#28
0
 public StiffnessMatrix(ISpan span)
 {
     _span = span ?? throw new ArgumentNullException(nameof(span));
 }
示例#29
0
        private async Task ProcessWebQueueMessageAsync(object sender, BasicDeliverEventArgs @event)
        {
            // ExtractActivity creates the Activity setting the parent based on the RabbitMQ "traceparent" header
            var activity = @event.ExtractActivity("Process single RabbitMQ message");

            ISpan span = null;
            IOperationHolder <DependencyTelemetry> operation = null;
            var    processingSucceeded = false;
            string source = string.Empty;

            IDisposable loggingScope = null;

            try
            {
                if (tracer != null)
                {
                    // OpenTelemetry seems to require the Activity to have started, unlike AI SDK
                    activity.Start();
                    tracer.StartActiveSpanFromActivity(activity.OperationName, activity, SpanKind.Consumer, out span);

                    span.SetAttribute("queue", Constants.WebQueueName);
                }

                using (operation = telemetryClient?.StartOperation <DependencyTelemetry>(activity))
                {
                    if (operation != null)
                    {
                        operation.Telemetry.Properties.Add("queue", Constants.WebQueueName);
                        operation.Telemetry.Type   = ApplicationInformation.Name;
                        operation.Telemetry.Target = this.rabbitMQHostName;
                    }

                    loggingScope = logger.BeginScope("Starting message processing");

                    // Get the payload
                    var message = JsonSerializer.Deserialize <EnqueuedMessage>(@event.Body, jsonSerializerOptions);
                    if (logger.IsEnabled(LogLevel.Information))
                    {
                        logger.LogInformation("Processing message from {source}: {message}", message.Source, Encoding.UTF8.GetString(@event.Body));
                    }

                    source = message.Source;

                    if ("error".Equals(message.EventName, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new InvalidEventNameException("Invalid event name");
                    }

                    var apiFullUrl = $"{timeApiURL}/api/time/dbtime";
                    var time       = await httpClientFactory.CreateClient().GetStringAsync(apiFullUrl);

                    if (!string.IsNullOrEmpty(message.EventName))
                    {
                        span?.AddEvent(message.EventName);
                        telemetryClient?.TrackEvent(message.EventName);
                    }
                }
                processingSucceeded = true;
            }
            catch (Exception ex)
            {
                if (span != null)
                {
                    span.SetAttribute("error", true);
                    span.Status = Status.Internal.WithDescription(ex.ToString());
                }

                if (operation != null)
                {
                    operation.Telemetry.Success    = false;
                    operation.Telemetry.ResultCode = "500";

                    // Track exception, adding the connection to the current activity
                    var exOperation = new ExceptionTelemetry(ex);
                    exOperation.Context.Operation.Id       = operation.Telemetry.Context.Operation.Id;
                    exOperation.Context.Operation.ParentId = operation.Telemetry.Context.Operation.ParentId;
                    telemetryClient.TrackException(exOperation);
                }

                logger.LogError(ex, "Failed to process message from {source}", source);
            }
            finally
            {
                span?.End();
                metrics.TrackItemProcessed(1, source, processingSucceeded);
                loggingScope?.Dispose();
            }
        }
示例#30
0
        public void Add(ISpan span)
        {
            FlushBuilder();

            _content.Add(span);
        }
示例#31
0
 public static ISpan Tag(this ISpan span, string key, double value)
 {
     return(Tag(span, key, value.ToString()));
 }
示例#32
0
        internal NoopSpan(string name, string type, string subtype, string action,
                          ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer, string parentId = null, string traceId = null, ISpan
                          parentSpan = null
                          )
        {
            Name     = name;
            Type     = type;
            ParentId = parentId;
            TraceId  = traceId;
            Subtype  = subtype;
            Action   = action;

            _currentExecutionSegmentsContainer             = currentExecutionSegmentsContainer;
            _currentExecutionSegmentsContainer.CurrentSpan = this;
            _parentSpan = parentSpan;
        }
示例#33
0
 public static ISpan Log(this ISpan span, LogField fields)
 {
     return(Log(span, DateTime.UtcNow, fields));
 }
示例#34
0
 public void decreaseMappingLevel(ISpan ast) 
 {
     Debug.Assert(this.mappingLevel.Count > 0, "Mapping level should never be less than 0. This suggests a missing start call.");
     
     var expectedAst = this.mappingLevel[this.mappingLevel.Count-1]; 
     this.mappingLevel.RemoveAt(this.mappingLevel.Count-1); // .pop()
     
     /*
     var expectedAstInfo = (<ISyntaxElement>expectedAst).kind ? SyntaxKind[(<ISyntaxElement>expectedAst).kind()] : [expectedAst.start(), expectedAst.end()];
     
     var astInfo = (<ISyntaxElement>ast).kind ? SyntaxKind[(<ISyntaxElement>ast).kind()] : [ast.start(), ast.end()];
     
     Debug.Assert(
         ast == expectedAst,
         "Provided ast is not the expected ISyntaxElement, Expected: " + expectedAstInfo + " Given: " + astInfo);
     */ 
 }
示例#35
0
 public static void Finish(this ISpan span)
 {
     span?.Finish(DateTimeOffset.UtcNow);
 }
示例#36
0
      private void recordSourceMappingSpanEnd(ISpan ast) 
      {
         if (this.sourceMapper!=null && ASTHelpers.isValidSpan(ast)) 
         {
               // Pop source mapping childs
               //this.sourceMapper.currentMappings.pop();
               this.sourceMapper.currentMappings.RemoveAt(this.sourceMapper.currentMappings.Count-1);

               // Get the last source mapping from sibling list = which is the one we are recording end for
               var siblings = this.sourceMapper.currentMappings[this.sourceMapper.currentMappings.Count - 1];
               var sourceMapping = siblings[siblings.Count - 1];

               sourceMapping.end.emittedColumn = this.emitState.column;
               sourceMapping.end.emittedLine = this.emitState.line;

               /*
               Debug.assert(!isNaN(sourceMapping.end.emittedColumn));
               Debug.assert(!isNaN(sourceMapping.end.emittedLine));
               */ 

               this.sourceMapper.decreaseMappingLevel(ast);
         }
      }
示例#37
0
 public static bool isValidSpan(ISpan ast)
 {
    throw new NotImplementedException();
 }