Azure / aspnet-redis-providers

ASP.NET Redis Providers
Other
269 stars 181 forks source link

Add App Insights Dependency Tracking #51

Open lukos opened 8 years ago

lukos commented 8 years ago

Currently, Redis does not use Dependency Tracking for Application Insights, and we have seen many issues related to Redis timeouts and network latency that would be much easier to debug and see if dependency tracking was built into this provider.

markalanevans commented 7 years ago

Do you guys think you will add support for this?

Leonardo-Ferreira commented 7 years ago

i really don't think thats a good idea... at least not bluntly put as such... my redis logs about 14 million operations per hour (avg of 4 operations per millisecond) and i'm operating from a single 2 core 3gb ram PaaS... that would affect me in 3 ways:

andre-castro-garcia commented 4 years ago

I'm currently bypasses this problem using a custom implementation for track events in my Application Insights.

My code seems like this:

    /// <summary>
    /// 
    /// </summary>
    public class RedisFacade : IRedisFacade {
        private readonly IDatabaseAsync _cache;
        private readonly TelemetryClient _telemetry;

        private readonly Stopwatch _watch;

        private const string Redis = "REDIS";
        private readonly string _redisHost;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="multiplexer"></param>
        /// <param name="options"></param>
        /// <param name="telemetry"></param>
        public RedisFacade(IConnectionMultiplexer multiplexer, IOptions<ConnectionsOptions> options,
            TelemetryClient telemetry) {
            _cache = multiplexer.GetDatabase();
            _telemetry = telemetry;
            _watch = new Stopwatch();
            _redisHost = "myredishost:6379";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="method"></param>
        /// <param name="func"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private async Task<T> ExecuteWithTracking<T>(string method, Func<Task<T>> func) {
            var start = DateTimeOffset.Now;
            if (_watch.IsRunning)
                _watch.Restart();
            else
                _watch.Start();
            var result = await func().ConfigureAwait(false);
            _watch.Stop();

            var end = _watch.Elapsed;
            _telemetry.TrackDependency(Redis, _redisHost,
                method, string.Empty, start, end, string.Empty, true);
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task<RedisValue> StringGetAsync(RedisKey key) {
            return await ExecuteWithTracking("StringGetAsync", () => _cache.StringGetAsync(key))
                .ConfigureAwait(false);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task<bool> KeyExistsAsync(RedisKey key) {
            return await ExecuteWithTracking("KeyExistsAsync", () => _cache.KeyExistsAsync(key))
                .ConfigureAwait(false);
        }
}

My Application Insights Application Map:

image

mtamrakar commented 2 years ago

@andre-castro-garcia, is IRedisFacade your own abstraction? If not, how do we inject this abstraction into RedisSessionStateProvider.cs to make sure everything goes through this override.