Example #1
0
        /// <summary>
        /// Set event dimensions
        /// </summary>
        /// <param name="values">dimensions values</param>
        /// <returns>this</returns>
        public WorkContextBuilder Set(IEventDimensions eventDimension)
        {
            eventDimension.Verify().IsNotNull();

            Dimensions = new EventDimensions(eventDimension);
            return(this);
        }
Example #2
0
        public void ActivityStart(IWorkContext context, string message = null, IEventDimensions dimensions = null)
        {
            Verify.IsNotNull(nameof(context), context);

            var dim = context.Materialized(dimensions);

            _router.Post(new EventData(EventSourceName, nameof(ActivityStart), TelemetryLevel.Verbose, message, context.Cv, context.Tag, dim));
        }
Example #3
0
        /// <summary>
        /// Create new context with cancellation token
        /// </summary>
        /// <param name="eventDimenensions">event log to use</param>
        /// <returns>new work context</returns>
        public IWorkContext With(IEventDimensions eventDimenensions)
        {
            eventDimenensions.Verify(nameof(eventDimenensions)).IsNotNull();

            return(new WorkContext(this)
            {
                Dimensions = new EventDimensions(Dimensions) + eventDimenensions,
            });
        }
Example #4
0
        /// <summary>
        /// Create new context with cancellation token
        /// </summary>
        /// <param name="eventDimenensions">event log to use</param>
        /// <returns>new work context</returns>
        public IWorkContext With(IEventDimensions eventDimenensions)
        {
            Verify.IsNotNull(nameof(eventDimenensions), eventDimenensions);

            return(new WorkContext(this)
            {
                Dimensions = eventDimenensions,
            });
        }
Example #5
0
        /// <summary>
        /// Create new event dimensions by merging two instances.  "newOrOverrides" will take
        /// precedent of parent values
        /// </summary>
        /// <param name="source">source of dimension values</param>
        /// <param name="upserts">new or updates to dimension values</param>
        /// <returns>merged new event dimensions</returns>
        public static IEventDimensions WithUpserts(this IEventDimensions source, IEventDimensions upserts)
        {
            if (source == null)
            {
                return(null);
            }

            return(source
                   .Select(x => new { Index = 2, Dim = x })
                   .Concat(upserts.Select(x => new { Index = 1, Dim = x }))
                   .GroupBy(x => x.Dim.Key)
                   .Select(x => x.OrderBy(y => y.Index).First())
                   .ToDictionary(x => x.Dim.Key, x => x.Dim.Value, StringComparer.InvariantCultureIgnoreCase)
                   .AsTypeOrDefault <IEventDimensions>());
        }
Example #6
0
        /// <summary>
        /// Construct work context, for values that are not known to be immutable, shallow copies are made
        /// </summary>
        /// <param name="cv">correlation vector</param>
        /// <param name="tag">code location tag</param>
        /// <param name="workContainer">container</param>
        /// <param name="properties">properties (optional)</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <param name="eventLog"></param>
        /// <param name="dimensions"></param>
        public WorkContext(
            CorrelationVector cv,
            Tag tag,
            ILifetimeScope workContainer,
            IPropertyBag properties             = null,
            CancellationToken?cancellationToken = null,
            ITelemetry eventLog         = null,
            IEventDimensions dimensions = null
            )
        {
            Verify.IsNotNull(nameof(cv), cv);
            Verify.IsNotNull(nameof(tag), tag);

            Cv                = cv;
            Tag               = tag;
            Container         = workContainer;
            Properties        = properties != null ? new PropertyBag(properties) : new PropertyBag();
            CancellationToken = cancellationToken ?? CancellationToken.None;
            EventLog          = eventLog ?? new TelemetryLogNull();
            Dimensions        = dimensions != null ? new EventDimensions(dimensions) : new EventDimensions();
        }
Example #7
0
        /// <summary>
        /// Construct work context, for values that are not known to be immutable, shallow copies are made
        /// </summary>
        /// <param name="cv">correlation vector</param>
        /// <param name="tag">code location tag</param>
        /// <param name="workContainer">container</param>
        /// <param name="properties">properties (optional)</param>
        /// <param name="cancellationToken">Cancellation token</param>
        public WorkContext(
            CorrelationVector cv,
            Tag tag,
            ILifetimeScope workContainer,
            IProperties properties = null,
            CancellationToken?cancellationToken = null,
            IEventLog eventLog          = null,
            IEventDimensions dimensions = null
            )
        {
            Verify.IsNotNull(nameof(cv), cv);
            Verify.IsNotNull(nameof(tag), tag);

            Cv                = cv;
            Tag               = tag;
            Container         = workContainer;
            Properties        = (properties?.ToDictionary(x => x.Key, x => x.Value) ?? new Dictionary <string, object>()).AsTypeOrDefault <IProperties>();
            CancellationToken = cancellationToken ?? CancellationToken.None;
            EventLog          = eventLog ?? new EventLogNull();
            Dimensions        = dimensions ?? new Dictionary <string, string>().AsTypeOrDefault <IEventDimensions>();
        }
        public void DimensionTest()
        {
            var dimensions = new EventDimensionsBuilder()
                             .Add("WorkflowCv", new CorrelationVector().ToString())
                             .Add("PackageName", "PackageNameData")
                             .Add("FriendlyName", "friendlyNameData")
                             .Add("BuildNumber", "buildNumberData")
                             .Build();

            dimensions.Count.Should().Be(4);

            IEventDimensions addDimensions = new EventDimensionsBuilder()
                                             .Add("ExeFile", "Exec.exe")
                                             .Add("NodeType", "LocalExec")
                                             .Build();

            addDimensions.Count.Should().Be(2);

            IEventDimensions newDimensions = (EventDimensions)dimensions + addDimensions;

            newDimensions.Count.Should().Be(6);
        }
Example #9
0
 public void ActivityStart(IWorkContext context, string message = null, IEventDimensions dimensions = null)
 {
 }
Example #10
0
 public void Verbose(IWorkContext context, string message, IEventDimensions dimensions = null)
 {
 }
Example #11
0
 public void TrackMetric(IWorkContext context, string name, double value, IEventDimensions dimensions = null)
 {
 }
Example #12
0
 public void LogEvent(IWorkContext context, TelemetryLevel telemetryLevel, string eventSourceName, string eventName, IEventDimensions dimensions = null)
 {
 }
Example #13
0
 public void Error(IWorkContext context, string message, Exception exception = null, IEventDimensions dimensions = null)
 {
 }
Example #14
0
 public void ActivityStop(IWorkContext context, string message = null, long durationMs = 0, IEventDimensions dimensions = null)
 {
 }
Example #15
0
        public void Verbose(IWorkContext context, string message, IEventDimensions dimensions = null)
        {
            var dim = context.Materialized(dimensions);

            _router.Post(new EventData(EventSourceName, nameof(Verbose), TelemetryLevel.Verbose, message, context.Cv, context.Tag, dim));
        }
Example #16
0
        public void Error(IWorkContext context, string message, Exception exception = null, IEventDimensions dimensions = null)
        {
            var dim = context.Materialized(dimensions);

            _router.Post(new EventData(EventSourceName, nameof(Error), TelemetryLevel.Error, message, context.Cv, context.Tag, dim));
        }
Example #17
0
        public void ActivityStop(IWorkContext context, string message = null, long durationMs = 0, IEventDimensions dimensions = null)
        {
            var dim = context.Materialized(dimensions);

            _router.Post(new EventData(EventSourceName, nameof(ActivityStop), TelemetryLevel.Verbose, message, context.Cv, context.Tag, dim));
        }
Example #18
0
        // ========================================================================================
        // Log event
        public void LogEvent(IWorkContext context, TelemetryLevel telemetryLevel, string eventSourceName, string eventName, IEventDimensions dimensions = null)
        {
            var dim = context.Materialized(dimensions);

            _router.Post(new EventData(eventSourceName, eventName, telemetryLevel, context.Cv, context.Tag, dim));
        }
Example #19
0
        public void TrackMetric(IWorkContext context, string name, double value, IEventDimensions dimensions = null)
        {
            var dim = context.Materialized(dimensions);

            _router.Post(new EventData(EventSourceName, name, TelemetryLevel.Metric, context.Cv, context.Tag, value, dim));
        }