DKX.Tracer by david_kudera

<PackageReference Include="DKX.Tracer" Version="0.1.0" />

 Span

public class Span : ISpan, IDisposable
using DKX.Tracer.Attributes; using DKX.Tracer.Events; using System; using System.Collections.Immutable; using System.Runtime.CompilerServices; namespace DKX.Tracer { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class Span : ISpan, IDisposable { private readonly IDateTimeProvider _dateTimeProvider; public string Name { get; } public DateTime StartedAt { get; } public DateTime? ClosedAt { get; set; } [System.Runtime.CompilerServices.Nullable(2)] [field: System.Runtime.CompilerServices.Nullable(2)] public ISpan Parent { [System.Runtime.CompilerServices.NullableContext(2)] get; } public IImmutableList<ISpan> Children { get; set; } = ImmutableList<ISpan>.Empty; public IImmutableList<IAttribute> Attributes { get; set; } = ImmutableList<IAttribute>.Empty; public bool Closed => ClosedAt.HasValue; [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] [method: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] [field: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] public event EventHandler<SpanForkedArgs> OnForked; [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] [method: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] [field: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] public event EventHandler<SpanClosedArgs> OnClosed; public Span(IDateTimeProvider dateTimeProvider, string name, [System.Runtime.CompilerServices.Nullable(2)] ISpan parent = null) { _dateTimeProvider = dateTimeProvider; Name = name; Parent = parent; StartedAt = _dateTimeProvider.GetUtcNow(); } public virtual void Dispose() { if (Closed) throw new Exception("Can not dispose of already disposed span"); ClosedAt = _dateTimeProvider.GetUtcNow(); this.OnClosed?.Invoke(this, new SpanClosedArgs(this)); this.OnForked = null; this.OnClosed = null; } public ISpan AddAttribute(string name, string value) { Attributes = Attributes.Add(new StringAttribute(name, value)); return this; } public ISpan AddAttribute(string name, long value) { Attributes = Attributes.Add(new NumberAttribute(name, value)); return this; } public ISpan AddAttribute(string name, bool value) { Attributes = Attributes.Add(new BooleanAttribute(name, value)); return this; } public ISpan Fork(string name) { if (Closed) throw new Exception("Can not fork already closed span"); Span span = new Span(_dateTimeProvider, name, this); Children = Children.Add(span); this.OnForked?.Invoke(this, new SpanForkedArgs(this, span)); return span; } } }