c# - 通过应用程序洞察中的端到端事务跟踪 azure redis

标签 c# azure redis

我正在使用 Azure Application Insights 来跟踪请求中的操作。

我实现了redis,将数据存储到 key 中,并将过期时间设置为1天。这是测试方法:

public async Task<IReadOnlyCollection<FoodDescriptionModel>> SearchIngredientAsync(string name)
{
    _redisCache.TryGetValue("FoodDescriptionModelCollection", out IReadOnlyCollection<FoodDescriptionModel> cached);

    return cached.Where(x => x.LongDescription.Contains(name)).ToList() as IReadOnlyCollection<FoodDescriptionModel>;
}

这肯定是从缓存中获取数据。 问题是 azure 门户中的端到端事务显示对该请求的数据库访问: enter image description here

为什么?另一方面,当我检查 Redis 的获取量正在增加时: enter image description here

最佳答案

很难判断您使用的是哪种 Redis 客户端,但看起来不像 StackExchange 或 ServiceStack。如果您提供 _redisCache

的类型,将会很有帮助

Application Insights 尚未自动跟踪对 Redis 的调用(使用任何客户端),但您可以手动跟踪它们,以下是 StackExchange.Redis.IDatabase.StringSet 的示例:

private async Task<bool> StringSetTrackedAsync(RedisKey key, string value)
{
    var dependency = new DependencyTelemetry()
    {
        Type = "Redis",
        Name = "SetStringAsync"
    };
    dependency.Properties["key"] = key;
    using (telemetryClient.StartOperation(dependency))
    {
        var result = await cache.StringSetAsync(key, value);
        dependency.Success = result;
        return result;
    }
}

您可以添加 Redis 主机等详细信息,或删除您不希望出现在遥测中的内容。

Here is how it looks like in the viewer

关于c# - 通过应用程序洞察中的端到端事务跟踪 azure redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49925531/

相关文章:

node.js - 使 Node.js Redis 客户端的 .multi() 和 .batch() 在结果中返回错误以用于测试目的

c# - C# 中的简单输入验证

c# - 是否将 Task<>.Factory.StartNew/Task.Factory.ContinueWhenAll() 转换为 async/await?

c# - WPF UserControl Dependency Property Setter 未触发

azure - 用户 '<token-identified principal>' 登录失败。 (微软 SQL Server,错误 : 18456)

c# - ASP.NET 中的安全设置问题

c# - 使用接口(interface)作为构造函数参数

asp.net - 我们可以使用 imageresizer 加速或避免对图像请求使用 AuthorizeRequest 吗?

redis - 无法使用 JMeter SSH 命令删除 Redis key

arrays - 二分搜索与基于键的搜索