Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Apm + options to enable it. #510

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/EasyCaching.Redis/Configurations/RedisDatabaseProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace EasyCaching.Redis
using Elastic.Apm.StackExchange.Redis;

namespace EasyCaching.Redis
{
using StackExchange.Redis;
using StackExchange.Redis.KeyspaceIsolation;
Expand All @@ -17,6 +19,8 @@ public class RedisDatabaseProvider : IRedisDatabaseProvider
/// </summary>
private readonly RedisDBOptions _options;

private readonly bool _useApm;

/// <summary>
/// The connection multiplexer.
/// </summary>
Expand All @@ -25,6 +29,7 @@ public class RedisDatabaseProvider : IRedisDatabaseProvider
public RedisDatabaseProvider(string name, RedisOptions options)
{
_options = options.DBConfig;
_useApm = options.UseApm;
_connectionMultiplexer = new Lazy<ConnectionMultiplexer>(CreateConnectionMultiplexer);
_name = name;
}
Expand All @@ -40,10 +45,14 @@ public IDatabase GetDatabase()
{
try
{

var database = _connectionMultiplexer.Value.GetDatabase();

if (!string.IsNullOrEmpty(_options.KeyPrefix))
database = database.WithKeyPrefix(_options.KeyPrefix);

if (_useApm)
_connectionMultiplexer.Value.UseElasticApm();

return database;
}
catch (Exception)
Expand Down Expand Up @@ -131,4 +140,4 @@ private List<EndPoint> GetMastersServersEndpoints()
return masters;
}
}
}
}
5 changes: 5 additions & 0 deletions src/EasyCaching.Redis/Configurations/RedisOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ public RedisOptions()
}

public RedisDBOptions DBConfig { get; set; } = new RedisDBOptions();

/// <summary>
/// Whether or not to use Elastic APM, defaults to false
/// </summary>
public bool UseApm { get; set; } = false;
}
}
1 change: 1 addition & 0 deletions src/EasyCaching.Redis/EasyCaching.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Elastic.Apm.StackExchange.Redis" Version="1.25.1" />
<PackageReference Include="StackExchange.Redis" Version="2.5.43" />
</ItemGroup>
<ItemGroup>
Expand Down