Пример #1
0
        public void Instrument(Action aspect, string instrumentationContext = null, double samplingRate = Constants.DefaultSamplingRate)
        {
            Tuple <IEnumerable <PerfitHandlerContext>, Dictionary <string, object> > contexts = null;
            var corrId = Correlation.GetId(_info.CorrelationIdKey);

            try
            {
                if (_info.PublishCounters)
                {
                    contexts = BuildContexts();
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                if (_info.RaisePublishErrors)
                {
                    throw;
                }
            }

            var stopwatch = Stopwatch.StartNew();

            try
            {
                aspect();
            }
            catch (Exception)
            {
                SetErrorContexts(contexts);
                throw;
            }
            finally
            {
                try
                {
                    if (_info.PublishEvent && ShouldInstrument(samplingRate))
                    {
                        PublishInstrumentationCallback(_info.CategoryName,
                                                       _info.InstanceName, stopwatch.ElapsedMilliseconds, instrumentationContext, corrId.ToString());
                    }

                    if (_info.PublishCounters)
                    {
                        CompleteContexts(contexts);
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                    if (_info.RaisePublishErrors)
                    {
                        throw;
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Starts instrumentation
 /// </summary>
 /// <returns>The token to be passed to Finish method when finished</returns>
 public object Start(double samplingRate = Constants.DefaultSamplingRate)
 {
     return(new InstrumentationToken()
     {
         Contexts = _info.PublishCounters ? BuildContexts() : null,
         Kronometer = Stopwatch.StartNew(),
         SamplingRate = samplingRate,
         CorrelationId = Correlation.GetId(_info.CorrelationIdKey)
     });
 }
Пример #3
0
        bool ShouldInstrument(double samplingRate)
        {
            var corrId = Correlation.GetId(_info.CorrelationIdKey);

            return(ShouldInstrument(samplingRate, corrId.ToString()));
        }