示例#1
0
        /// <summary>
        /// Starts instrumentation
        /// </summary>
        /// <returns>The token to be passed to Finish method when finished</returns>
        public object Start(double samplingRate = Constants.DefaultSamplingRate)
        {
            try
            {
                var token = new InstrumentationToken()
                {
                    Contexts       = BuildContexts(),
                    Kronometer     = Stopwatch.StartNew(),
                    SamplingRate   = samplingRate,
                    CorrelationId  = Correlation.GetId(_info.CorrelationIdKey),
                    TracerContexts = new Dictionary <string, object>()
                };

                foreach (var kv in _tracers)
                {
                    token.TracerContexts.Add(kv.Key, kv.Value.Start(_info));
                }

                return(token);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                if (_info.RaisePublishErrors)
                {
                    throw;
                }
            }

            return(null);
        }
示例#2
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;
                    }
                }
            }
        }
示例#3
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)
     });
 }
示例#4
0
        bool ShouldInstrument(double samplingRate)
        {
            var corrId = Correlation.GetId(_info.CorrelationIdKey);

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