Skip to content

[bug] Instrumentation.StackExchangeRedis High memory #4083

@jojo-Fish

Description

@jojo-Fish

Component

OpenTelemetry.Instrumentation.StackExchangeRedis

Package Version

Package Name Version
OpenTelemetry.Exporter.Console 1.15.2
OpenTelemetry.Extensions.Hosting 1.15.2
OpenTelemetry.Instrumentation.AspNetCore 1.15.1
OpenTelemetry.Instrumentation.Http 1.15.0
OpenTelemetry.Instrumentation.StackExchangeRedis 1.15.0-beta.1

Runtime Version

net10.0

Description

code demo

when this test action executed,the memory become High memory usage,even got more than 2.5GB usage

Steps to Reproduce

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using OpenTelemetry;
using OpenTelemetry.Trace;
using StackExchange.Redis;

var builder = WebApplication.CreateBuilder(args);

var connection = ConnectionMultiplexer.Connect("localhost:6693,abortConnect=false,keepAlive=30");
builder.Services.AddSingleton<IConnectionMultiplexer>(connection);
builder.Services.AddOpenTelemetry()
    .WithTracing(tracingBuilder =>
    {
        tracingBuilder.SetSampler(new AlwaysOnSampler());
        tracingBuilder
            .AddHttpClientInstrumentation()
            .AddHttpClientInstrumentation()
            .AddRedisInstrumentation(connection, opt => opt.FlushInterval = TimeSpan.FromSeconds(2))
            .AddConsoleExporter();
    });
var app = builder.Build();
app.MapGet("/test", async (IConnectionMultiplexer connect) =>
{
    var db = connection.GetDatabase();
    var counter = 0;
    await Parallel.ForEachAsync(
        Enumerable.Range(0, 200_0000),
        new ParallelOptions { MaxDegreeOfParallelism = 10 },
        async (i, _) =>
        {
            var key = $"text4_{i}";

            await db.HashSetAsync(key, i, 1);
            await db.KeyExpireAsync(key, TimeSpan.FromHours(3));

            Interlocked.Increment(ref counter);
        });
    return $"Total: {counter}";
});
await app.RunAsync();

Expected Result

when i disable AddRedisInstrumentation,the memory usage is very low,the Instrumentation.Stackexchange.redis has some memroy problem?

Actual Result

very hign memory usage

Additional Context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions