Example #1
0
        public void OnNext(KeyValuePair <string, object?> value)
        {
            var activity = Activity.Current;

            if (activity == null)
            {
                return;
            }

            if (value.Key.EndsWith(".Stop"))
            {
                var serviceAttribute = activity.Tags.FirstOrDefault(tag => tag.Key == CouchbaseTags.Service);
                if (serviceAttribute.Value == null)
                {
                    return;
                }

                if (_serviceThresholds.TryGetValue(serviceAttribute.Value, out var threshold))
                {
                    if (activity.Duration > threshold)
                    {
                        var summary = ThresholdSummary.FromActivity(activity);
                        ServiceThresholdQueue.AddByService(serviceAttribute.Value, summary);
                    }
                }
            }
        }
Example #2
0
        public static bool AddByService(string serviceName, ThresholdSummary overThresholdSummary)
        {
            if (CoreQueues.TryGetValue(serviceName, out var serviceQueue))
            {
                serviceQueue.Add(overThresholdSummary);
                return(true);
            }

            return(false);
        }
Example #3
0
        private void Add(ThresholdSummary overThresholdEvent)
        {
            // Don't add while sample reporting is being done.
            // We don't care otherwise if Add races a little against other adds.
            ReportIdle.Wait();

            Interlocked.Increment(ref _sampleCount);
            _latestEvents.Enqueue(overThresholdEvent);
            if (_latestEvents.Count > _sampleSize)
            {
                _latestEvents.TryDequeue(out var oldest);
            }
        }