internal static EventTelemetry ToTelemetry([NotNull] this BbTelemetryEvent @event) { try { var tEvent = new EventTelemetry { Name = @event.GetType().Name, Timestamp = DateTimeOffset.Now }; tEvent.SetCorrelation(@event); @event.CopyPropertiesInto(tEvent.Properties); return(tEvent); } catch (Exception ex) { #if DEBUG if (Debugger.IsAttached) { throw; } #endif BigBrother.PublishError(ex); return(null); } }
/// <summary> /// Handles external events that are fired by the <see cref="InternalStream"/>. /// </summary> /// <param name="event">The event being handled.</param> internal virtual void HandleInternalEvent(BbTelemetryEvent @event) { switch (@event) { case BbExceptionEvent ex: var tEvent = ex.ToTelemetry(); if (tEvent == null) { return; } tEvent.SeverityLevel = SeverityLevel.Error; InternalClient.TrackException(tEvent); break; case BbTimedEvent te: InternalClient.TrackEvent(te.ToTelemetry()); break; default: InternalClient.TrackEvent(@event.ToTelemetry()); break; } }
/// <summary> /// Populates the Id and CorrelationVector on any <see cref="ITelemetry"/> object with /// what it can find on the base <see cref="BbTelemetryEvent"/>. /// </summary> /// <param name="telemetry">The <see cref="ITelemetry"/> object that we want to populate with correlation data.</param> /// <param name="event">The base event we are transforming to the AI object.</param> public static void SetCorrelation([NotNull] this ITelemetry telemetry, [NotNull] BbTelemetryEvent @event) { var vector = @event.CorrelationVector; if (vector == null) { return; } telemetry.Context.Operation.CorrelationVector = vector; telemetry.Context.Operation.Id = vector; }
public void Ensure_NullCorrelation_DoesntPopulate() { const string correlationVector = null; var tEvent = new EventTelemetry(); var bbEvent = new BbTelemetryEvent { CorrelationVector = correlationVector }; tEvent.SetCorrelation(bbEvent); tEvent.Context.Operation.CorrelationVector.Should().BeNull(); tEvent.Context.Operation.Id.Should().BeNull(); }
public void Test_EventTelemetry_OperationIsPoPulated() { const string correlationVector = "SOMEIDHERE.1.3"; var tEvent = new EventTelemetry(); var bbEvent = new BbTelemetryEvent { CorrelationVector = correlationVector }; tEvent.SetCorrelation(bbEvent); tEvent.Context.Operation.CorrelationVector.Should().Be(correlationVector); tEvent.Context.Operation.Id.Should().Be(correlationVector); }
/// <summary> /// Deals with all the details of setting up the correlation vector inside the event object. /// </summary> /// <param name="event">The event that we want to correlate through.</param> /// <param name="correlation">The correlation handle used to correlate.</param> internal void SetupCorrelation(BbTelemetryEvent @event, object correlation) { if (correlation != null) // lose > strict, so we override strict if a lose is passed in { if (CorrelationHandles.ContainsKey(correlation)) { @event.CorrelationVector = CorrelationHandles[correlation].Vector; CorrelationHandles[correlation].Touch(); } else { var handle = new CorrelationHandle(DefaultCorrelationKeepAlive); CorrelationHandles.Add(correlation, handle); @event.CorrelationVector = handle.Vector; } } else if (Handle != null) { @event.CorrelationVector = Handle.Vector; } }