protected override void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { SingleSpanBlockTest(document, blockType, spanType, acceptedCharacters, expectedError: null); }
private static bool IsValidSpan(TraceSpan span, string name, ulong parentId, SpanKind kind) { return(span.SpanId != 0 && kind.Convert() == span.Kind && name.Equals(span.Name) && span.StartTime != null && parentId == span.ParentSpanId && span.EndTime != null && span.StartTime.ToDateTime() <= span.EndTime.ToDateTime()); }
/// <inheritdoc/> public ISpan StartSpan(string operationName, ISpan parent, SpanKind kind, SpanCreationOptions options) { if (parent == null) { parent = this.CurrentSpan; } return(Span.CreateFromParentSpan(operationName, parent, kind, options, this.sampler, this.tracerConfiguration, this.spanProcessor, this.LibraryResource)); }
public SpanConstructor(SpanKind kind, IEnumerable<ISymbol> symbols) { Builder = new SpanBuilder(); Builder.Kind = kind; Builder.EditHandler = SpanEditHandler.CreateDefault(TestTokenizer); foreach (ISymbol sym in symbols) { Builder.Accept(sym); } }
protected virtual void SingleSpanDocumentTest( string document, BlockType blockType, SpanKind spanType ) { Block b = CreateSimpleBlockAndSpan(document, blockType, spanType); ParseDocumentTest(document, b); }
public SpanConstructor(SpanKind kind, IEnumerable <ISymbol> symbols) { Builder = new SpanBuilder(); Builder.Kind = kind; Builder.EditHandler = SpanEditHandler.CreateDefault(TestTokenizer); foreach (ISymbol sym in symbols) { Builder.Accept(sym); } }
private static Span GenerateSpan( string text, SpanKind spanKind, int spanIndex, string spanText ) { Span[] spans = GenerateSpans(text, spanKind, spanIndex, spanText); return(spans[spanIndex]); }
private SpanConstructor CreateSymbolSpan( SpanKind kind, string content, Func <SourceLocation, ISymbol> ctor ) { SourceLocation start = LocationTracker.CurrentLocation; LocationTracker.UpdateLocation(content); return(new SpanConstructor(kind, new[] { ctor(start) })); }
internal static JaegerSpan CreateTestJaegerSpan( bool setAttributes = true, Dictionary <string, object> additionalAttributes = null, bool addEvents = true, bool addLinks = true, Resource resource = null, SpanKind kind = SpanKind.Client) { return(JaegerSpanConverterTest.CreateTestSpan( setAttributes, additionalAttributes, addEvents, addLinks, resource, kind).ToJaegerSpan()); }
public static void IsSpan( Span tok, SpanKind type, string content, int actualIndex, int lineIndex, int charIndex ) { IsSpan(tok, type, content, new SourceLocation(actualIndex, lineIndex, charIndex)); }
private Span( string name, SpanContext parentSpanContext, ActivityAndTracestate activityAndTracestate, bool ownsActivity, SpanKind spanKind, DateTimeOffset startTimestamp, IEnumerable <Link> links, TracerConfiguration tracerConfiguration, SpanProcessor spanProcessor, Resource libraryResource) { this.Name = name; this.LibraryResource = libraryResource; this.startTimestamp = startTimestamp; this.tracerConfiguration = tracerConfiguration; this.spanProcessor = spanProcessor; this.Kind = spanKind; this.OwnsActivity = ownsActivity; this.Activity = activityAndTracestate.Activity; var tracestate = activityAndTracestate.Tracestate; this.IsRecordingEvents = MakeSamplingDecision( parentSpanContext, name, null, links, // we'll enumerate again, but double enumeration over small collection is cheaper than allocation this.Activity.TraceId, this.Activity.SpanId, this.tracerConfiguration); if (this.IsRecordingEvents) { this.Activity.ActivityTraceFlags |= ActivityTraceFlags.Recorded; if (links != null) { foreach (var link in links) { this.AddLink(link); } } this.spanProcessor.OnStart(this); } else { this.Activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded; } this.Context = new SpanContext(this.Activity.TraceId, this.Activity.SpanId, this.Activity.ActivityTraceFlags, tracestate); }
protected ApplicationInsightsSpan(ApplicationInsightsTracer tracer, IApplicationInsightsSpanContext typedContext, string operationName, DateTimeOffset start, SpanKind spanKind, Endpoint localEndpoint = null, Dictionary <string, string> tagsActual = null) { TypedContext = typedContext; SpanKind = spanKind; OperationName = operationName; Started = start; LocalEndpoint = localEndpoint; Tracer = tracer; }
public static SpanData CreateSpanData(string name, SpanContext parentContext, SpanKind kind, DateTimeOffset startTimestamp, IEnumerable <Link> links, IDictionary <string, object> attributes, IEnumerable <Event> events, Status status, DateTimeOffset endTimestamp) { var processor = new Mock <SpanProcessor>(); processor.Setup(p => p.OnEnd(It.IsAny <SpanData>())); var tracer = TracerFactory.Create(b => b.AddProcessorPipeline(p => p.AddProcessor(_ => processor.Object))) .GetTracer(null); SpanCreationOptions spanOptions = null; if (links != null || attributes != null || startTimestamp != default) { spanOptions = new SpanCreationOptions { Links = links, Attributes = attributes, StartTimestamp = startTimestamp, }; } var span = tracer.StartSpan(name, parentContext, kind, spanOptions); if (events != null) { foreach (var evnt in events) { span.AddEvent(evnt); } } span.Status = status.IsValid ? status : Status.Ok; if (endTimestamp == default) { span.End(); } else { span.End(endTimestamp); } return((SpanData)processor.Invocations[0].Arguments[0]); }
public AreaContainer getNextArea(FObj fo) { _isNewSpanArea = false; SpanKind span = SpanKind.NONE; if (fo is Block) { span = ((Block)fo).GetSpan(); } else if (fo is BlockContainer) { span = ((BlockContainer)fo).GetSpan(); } if (this.mainReferenceArea.getChildren().Count == 0) { if (span == SpanKind.ALL) { return(addSpanArea(1)); } else { return(addSpanArea(columnCount)); } } ArrayList spanAreas = this.mainReferenceArea.getChildren(); SpanArea spanArea = (SpanArea)spanAreas[spanAreas.Count - 1]; if ((span == SpanKind.ALL) && (spanArea.getColumnCount() == 1)) { return(spanArea.getCurrentColumnArea()); } else if ((span == SpanKind.NONE) && (spanArea.getColumnCount() == columnCount)) { return(spanArea.getCurrentColumnArea()); } else if (span == SpanKind.ALL) { return(addSpanArea(1)); } else if (span == SpanKind.NONE) { return(addSpanArea(columnCount)); } else { throw new FonetException("BodyAreaContainer::getNextArea(): Span attribute messed up"); } }
public SpanBuilder(ITracer tracer, string operationName, string logKey = null, SpanKind kind = SpanKind.Internal, ISpan parent = null) { EnsureArg.IsNotNull(tracer, nameof(tracer)); EnsureArg.IsNotNullOrEmpty(operationName, nameof(operationName)); this.tracer = tracer; this.traceId = parent?.TraceId; this.operationName = operationName; this.logKey = logKey ?? LogKeys.Tracing; this.kind = kind; this.parent = parent; // TODO: copy baggage items from parent }
public RequestSpan(ApplicationInsightsTracer tracer, IApplicationInsightsSpanContext typedContext, string operationName, DateTimeOffset start, SpanKind spanKind, Endpoint localEndpoint = null, Dictionary <string, string> tagsActual = null) : base(tracer, typedContext, operationName, start, spanKind, localEndpoint, tagsActual) { var telemetry = new RequestTelemetry { Id = typedContext.SpanId, Name = operationName }; InitializeTelemetry(typedContext, localEndpoint, tagsActual, telemetry); _operation = Tracer.Client.StartOperation(telemetry); }
private void CompleteTagBlockWithSpan(IDisposable tagBlockWrapper, AcceptedCharacters acceptedCharacters, SpanKind spanKind) { Debug.Assert(tagBlockWrapper != null, "Tag block wrapper should not be null when attempting to complete a block"); Span.EditHandler.AcceptedCharacters = acceptedCharacters; // Write out the current span into the block before closing it. Output(spanKind); // Finish the tag block tagBlockWrapper.Dispose(); }
private void ExtractGenericProperties(ISpanData span, out SpanKind resultKind, out DateTimeOffset timestamp, out string name, out string resultCode, out IDictionary <string, string> props, out string traceId, out string spanId, out string parentId, out Tracestate tracestate, out bool?success, out TimeSpan duration) { resultKind = span.Kind; // TODO: Should this be a part of generic logic? if (resultKind == SpanKind.Internal) { if (span.HasRemoteParent.HasValue && span.HasRemoteParent.Value) { resultKind = SpanKind.Server; } else { resultKind = SpanKind.Client; } } // 1 tick is 100 ns timestamp = DateTimeOffset.FromUnixTimeSeconds(span.StartTimestamp.Seconds); timestamp = timestamp.Add(TimeSpan.FromTicks(span.StartTimestamp.Nanos / 100)); name = span.Name; props = new Dictionary <string, string>(); traceId = span.Context.TraceId.ToLowerBase16(); spanId = span.Context.SpanId.ToLowerBase16(); parentId = null; if (span.ParentSpanId != null && span.ParentSpanId.IsValid) { parentId = span.ParentSpanId.ToLowerBase16(); } resultCode = null; success = null; if (span.Status != null) { resultCode = ((int)span.Status.CanonicalCode).ToString(); success = span.Status.IsOk; if (!string.IsNullOrEmpty(span.Status.Description)) { props["statusDescription"] = span.Status.Description; } } tracestate = span.Context.Tracestate; var durationTs = span.EndTimestamp.SubtractTimestamp(span.StartTimestamp); duration = TimeSpan.FromTicks((durationTs.Seconds * TimeSpan.TicksPerSecond) + (durationTs.Nanos / 100)); }
/// <summary> /// Converts a <see cref="SpanKind"/> to a <see cref="TraceSpan.Types.SpanKind"/>. /// </summary> internal static TraceSpan.Types.SpanKind Convert(this SpanKind kind) { switch (kind) { case SpanKind.RpcClient: return(TraceSpan.Types.SpanKind.RpcClient); case SpanKind.RpcServer: return(TraceSpan.Types.SpanKind.RpcServer); default: return(TraceSpan.Types.SpanKind.Unspecified); } }
/// <inheritdoc/> public ISpan StartRootSpan(string operationName, SpanKind kind, DateTimeOffset startTimestamp, IEnumerable <Link> links) { if (operationName == null) { throw new ArgumentNullException(nameof(operationName)); } if (startTimestamp == default) { startTimestamp = PreciseTimestamp.GetUtcNow(); } return(Span.CreateRoot(operationName, kind, startTimestamp, links, this.tracerConfiguration, this.spanProcessor, this.LibraryResource)); }
protected override void SingleSpanBlockTest( string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any ) { SingleSpanBlockTest( document, blockType, spanType, acceptedCharacters, expectedError: null ); }
public ISpanBuilder BuildSpan( string operationName, string logKey = null, SpanKind kind = SpanKind.Internal, ISpan parent = null, bool ignoreCurrentSpan = false) { return(new SpanBuilder( this, operationName, logKey ?? this.CurrentSpan.LogKey ?? LogKeys.Tracing, kind, parent == null && ignoreCurrentSpan ? null : parent ?? this.CurrentSpan) .WithTag(SpanTagKey.SpanKind, kind.ToString())); // pass correlationid as traceid }
public bool isBalancingRequired(FObj fo) { if (this.mainReferenceArea.getChildren().Count == 0) { return(false); } ArrayList spanAreas = this.mainReferenceArea.getChildren(); SpanArea spanArea = (SpanArea)spanAreas[spanAreas.Count - 1]; if (spanArea.isBalanced()) { return(false); } SpanKind span = SpanKind.NONE; if (fo is Block) { span = ((Block)fo).GetSpan(); } else if (fo is BlockContainer) { span = ((BlockContainer)fo).GetSpan(); } if ((span == SpanKind.ALL) && (spanArea.getColumnCount() == 1)) { return(false); } else if ((span == SpanKind.NONE) && (spanArea.getColumnCount() == columnCount)) { return(false); } else if (span == SpanKind.ALL) { return(true); } else if (span == SpanKind.NONE) { return(false); } else { return(false); } }
internal int flags = 0; // bit field for timestamp and duration public Builder Reset() { traceId = null; parentId = null; id = null; kind = default(SpanKind); name = null; timestamp = 0L; duration = 0L; localEndpoint = default(Endpoint); remoteEndpoint = default(Endpoint); annotations?.Clear(); tags?.Clear(); flags = 0; return(this); }
public static void NextSpanIs( IEnumerator <Span> enumerator, SpanKind type, string content, int actualIndex, int lineIndex, int charIndex ) { NextSpanIs( enumerator, type, content, new SourceLocation(actualIndex, lineIndex, charIndex) ); }
protected override void SingleSpanBlockTest( string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedError ) { SingleSpanBlockTest( document, document, blockType, spanType, acceptedCharacters, expectedError ); }
protected override void SingleSpanBlockTest( string document, string spanContent, BlockType blockType, SpanKind spanType, params RazorError[] expectedErrors ) { SingleSpanBlockTest( document, spanContent, blockType, spanType, AcceptedCharacters.Any, expectedErrors ?? new RazorError[0] ); }
public bool IsAllowedTime(SpanKind kind) { switch (kind) { case SpanKind.Unknown: throw new NotSupportedException(); case SpanKind.Account: return(IsInRange(From, ToAccountDisable)); case SpanKind.Shutdown: return(IsInRange(From, ToShutdown)); default: throw new ArgumentOutOfRangeException("kind"); } }
private void OverwriteSpanKindFromAttribute(IAttributeValue spanKindAttr, ref SpanKind resultKind) { // override span kind with attribute named span.kind if (spanKindAttr != null) { var kind = spanKindAttr.Match((s) => s, null, null, null, null); if (kind == "server") { resultKind = SpanKind.Server; } else { resultKind = SpanKind.Client; } } }
protected virtual Block CreateSimpleBlockAndSpan( string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any ) { SpanConstructor span = Factory .Span(spanType, spanContent, spanType == SpanKind.Markup) .Accepts(acceptedCharacters); BlockBuilder b = new BlockBuilder() { Type = blockType }; return(ConfigureAndAddSpanToBlock(b, span)); }
protected virtual void SingleSpanBlockTest( string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any ) { SingleSpanBlockTest( document, spanContent, blockType, spanType, acceptedCharacters, expectedErrors: null ); }
protected override void SingleSpanBlockTest( string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors ) { Block b = CreateSimpleBlockAndSpan( spanContent, blockType, spanType, acceptedCharacters ); ParseBlockTest(document, b, expectedErrors ?? new RazorError[0]); }
public Span Span(SpanKind kind, params ISymbol[] symbols) { var builder = new SpanBuilder(); builder.Kind = kind; foreach (var symbol in symbols) { builder.Accept(symbol); } var span = builder.Build(); if (_last != null) { span.Previous = _last; _last.Next = span; } _last = span; return span; }
internal virtual void SingleSpanDocumentTest(string document, BlockType blockType, SpanKind spanType) { ParseDocumentTest(document, new Block(blockType, new[] { new TestSimpleSpan(spanType, document) })); }
protected virtual void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedError) { SingleSpanBlockTest(document, document, blockType, spanType, acceptedCharacters, expectedError); }
protected Span(SpanKind kind, SourceLocation start, string content, bool hidden, AcceptedCharacters acceptedCharacters) : this(kind, content, hidden, acceptedCharacters) { _start = start; }
public TestSimpleSpan(SpanKind kind, string content, AcceptedCharacters acceptedCharacters) : base(kind, content, hidden: false, acceptedCharacters: acceptedCharacters) { }
protected virtual Block CreateSimpleBlockAndSpan(string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { var span = Factory.Span(spanType, spanContent, spanType == SpanKind.Markup).Accepts(acceptedCharacters); var b = new BlockBuilder() { Type = blockType }; return ConfigureAndAddSpanToBlock(b, span); }
public TestSimpleSpan(SpanKind kind, string content) : base(kind, content) { }
public SpanConstructor Span(SpanKind kind, params ISymbol[] symbols) { return new SpanConstructor(kind, symbols); }
private static Span GenerateSpan(string text, SpanKind spanKind, int spanIndex, string spanText) { Span[] spans = GenerateSpans(text, spanKind, spanIndex, spanText); return spans[spanIndex]; }
public SpanConstructor Span(SpanKind kind, string content, HtmlSymbolType type) { return CreateSymbolSpan(kind, content, st => new HtmlSymbol(st, content, type)); }
protected Span(ParserContext context, SpanKind kind, bool hidden) : this(kind, context.CurrentSpanStart, context.ContentBuffer.ToString(), hidden) { }
protected override void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors) { var b = CreateSimpleBlockAndSpan(spanContent, blockType, spanType, acceptedCharacters); ParseBlockTest(document, b, expectedErrors ?? new RazorError[0]); }
/// <summary> /// Test span to simplify the generation of the actual Span in test initializer. /// </summary> /// <param name="kind">Span kind</param> /// <param name="start">Zero indexed start char index in the buffer.</param> /// <param name="end">End Column, if the text length is zero Start == End.</param> public TestSpan(SpanKind kind, int start, int end) { Kind = kind; Start = start; End = end; }
public SpanConstructor Span(SpanKind kind, string[] content, bool markup) { return new SpanConstructor(kind, Tokenize(content, markup)); }
protected Span(SpanKind kind, SourceLocation start, string content, bool hidden) : this(kind, content, hidden) { _start = start; }
private SpanConstructor CreateSymbolSpan(SpanKind kind, string content, Func<SourceLocation, ISymbol> ctor) { var start = LocationTracker.CurrentLocation; LocationTracker.UpdateLocation(content); return new SpanConstructor(kind, new[] { ctor(start) }); }
protected virtual void SingleSpanDocumentTest(string document, BlockType blockType, SpanKind spanType) { Block b = CreateSimpleBlockAndSpan(document, blockType, spanType); ParseDocumentTest(document, b); }
private static Span[] GenerateSpans(string text, SpanKind spanKind, int spanIndex, string spanText) { Assert.True(spanIndex > 0); RazorParser parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser()); Span[] spans; using (var reader = new StringReader(text)) { ParserResults results = parser.Parse(reader); spans = results.Document.Flatten().ToArray(); } Assert.True(spans.Length > spanIndex); Assert.Equal(spanKind, spans[spanIndex].Kind); Assert.Equal(spanText, spans[spanIndex].Content); return spans; }
protected Span(ParserContext context, SpanKind kind, bool hidden, AcceptedCharacters acceptedCharacters) : this(kind, context.CurrentSpanStart, context.ContentBuffer.ToString(), hidden, acceptedCharacters) { }
protected override void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, params RazorError[] expectedError) { SingleSpanBlockTest(document, document, blockType, spanType, expectedError); }
protected Span(SpanKind kind, SourceLocation start, string content) : this(kind, content) { _start = start; }
protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, params RazorError[] expectedErrors) { SingleSpanBlockTest(document, spanContent, blockType, spanType, AcceptedCharacters.Any, expectedErrors ?? new RazorError[0]); }
// For parser unit tests, where start point is calculated internal NamespaceImportSpan(SpanKind kind, string content, AcceptedCharacters acceptedCharacters, string ns, int namespaceKeywordLength) : base(kind, content, hidden: false, acceptedCharacters: acceptedCharacters) { Namespace = ns; NamespaceKeywordLength = namespaceKeywordLength; }
protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors) { var builder = new BlockBuilder(); builder.Type = blockType; ParseBlockTest( document, ConfigureAndAddSpanToBlock( builder, Factory.Span(spanType, spanContent, spanType == SpanKind.Markup) .Accepts(acceptedCharacters)), expectedErrors ?? new RazorError[0]); }
public NamespaceImportSpan(SpanKind kind, SourceLocation start, string content, AcceptedCharacters acceptedCharacters, string ns, int namespaceKeywordLength) : base(kind, start, content, hidden: false, acceptedCharacters: acceptedCharacters) { Namespace = ns; NamespaceKeywordLength = namespaceKeywordLength; }
protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { SingleSpanBlockTest(document, spanContent, blockType, spanType, acceptedCharacters, expectedErrors: null); }
public static NamespaceImportSpan Create(ParserContext context, AcceptedCharacters acceptedCharacters, SpanKind kind, string ns, int namespaceKeywordLength) { return new NamespaceImportSpan(kind, context.CurrentSpanStart, context.ContentBuffer.ToString(), acceptedCharacters, ns, namespaceKeywordLength); }