Skip to content

Commit

Permalink
Support from 2.0.405
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Jul 27, 2022
1 parent 4837637 commit aad6c78
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ for more details.
| `MySqlData` | [MySql.Data](https://www.nuget.org/packages/MySql.Data) **Not supported on .NET Framework** | ≥6.10.7 | source |
| `Npgsql` | [Npgsql](https://www.nuget.org/packages/Npgsql) | ≥6.0.0 | source |
| `SqlClient` | [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) and [System.Data.SqlClient](https://www.nuget.org/packages/System.Data.SqlClient) | * | source |
| `StackExchangeRedis` | [StackExchange.Redis](https://www.nuget.org/packages/StackExchange.Redis) **Not supported on .NET Framework** | ≥2.1.58 < 3.0.0 | source & binary |
| `StackExchangeRedis` | [StackExchange.Redis](https://www.nuget.org/packages/StackExchange.Redis) **Not supported on .NET Framework** | ≥2.0.405 < 3.0.0 | source & binary |

### Instrumented metrics libraries and frameworks

Expand Down
104 changes: 101 additions & 3 deletions integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,31 @@
"target": {
"assembly": "StackExchange.Redis",
"type": "StackExchange.Redis.ConnectionMultiplexer",
"method": "Connect",
"method": "ConnectImpl",
"signature_types": [
"StackExchange.Redis.ConnectionMultiplexer",
"System.Object",
"System.IO.TextWriter"
],
"minimum_major": 2,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "OpenTelemetry.AutoInstrumentation",
"type": "OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegration",
"action": "CallTargetModification"
}
},
{
"caller": {},
"target": {
"assembly": "StackExchange.Redis",
"type": "StackExchange.Redis.ConnectionMultiplexer",
"method": "ConnectImpl",
"signature_types": [
"StackExchange.Redis.ConnectionMultiplexer",
"StackExchange.Redis.ConfigurationOptions",
Expand All @@ -138,9 +162,58 @@
"target": {
"assembly": "StackExchange.Redis",
"type": "StackExchange.Redis.ConnectionMultiplexer",
"method": "ConnectAsync",
"method": "ConnectImpl",
"signature_types": [
"StackExchange.Redis.ConnectionMultiplexer",
"StackExchange.Redis.ConfigurationOptions",
"System.IO.TextWriter",
"System.Nullable`1[StackExchange.Redis.ServerType]"
],
"minimum_major": 2,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "OpenTelemetry.AutoInstrumentation",
"type": "OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegration",
"action": "CallTargetModification"
}
},
{
"caller": {},
"target": {
"assembly": "StackExchange.Redis",
"type": "StackExchange.Redis.ConnectionMultiplexer",
"method": "ConnectImplAsync",
"signature_types": [
"System.Threading.Tasks.Task`1[StackExchange.Redis.ConnectionMultiplexer]",
"System.Object",
"System.IO.TextWriter"
],
"minimum_major": 2,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "OpenTelemetry.AutoInstrumentation",
"type": "OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegrationAsync",
"action": "CallTargetModification"
}
},
{
"caller": {},
"target": {
"assembly": "StackExchange.Redis",
"type": "StackExchange.Redis.ConnectionMultiplexer",
"method": "ConnectImplAsync",
"signature_types": [
"System.Threading.Tasks.Task`1<StackExchange.Redis.ConnectionMultiplexer>",
"System.Threading.Tasks.Task`1[StackExchange.Redis.ConnectionMultiplexer]",
"StackExchange.Redis.ConfigurationOptions",
"System.IO.TextWriter"
],
Expand All @@ -156,6 +229,31 @@
"type": "OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegrationAsync",
"action": "CallTargetModification"
}
},
{
"caller": {},
"target": {
"assembly": "StackExchange.Redis",
"type": "StackExchange.Redis.ConnectionMultiplexer",
"method": "ConnectImplAsync",
"signature_types": [
"System.Threading.Tasks.Task`1[StackExchange.Redis.ConnectionMultiplexer]",
"StackExchange.Redis.ConfigurationOptions",
"System.IO.TextWriter",
"System.Nullable`1[StackExchange.Redis.ServerType]"
],
"minimum_major": 2,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "OpenTelemetry.AutoInstrumentation",
"type": "OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegrationAsync",
"action": "CallTargetModification"
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ internal static class StackExchangeRedisConstants
{
public const string AssemblyName = "StackExchange.Redis";

public const string MinimumVersion = "2.0.0"; // 2.1.58, but dll uses 2.0.0
public const string MinimumVersion = "2.0.0"; // this is AssemblyVersion, all 2.* versions are released with this value
public const string MaximumVersion = "2.65535.65535";
public const string IntegrationName = "StackExchangeRedis";

public const string ConnectionMultiplexerTypeName = "StackExchange.Redis.ConnectionMultiplexer";
public const string ConfigurationOptionsTypeName = "StackExchange.Redis.ConfigurationOptions";
public const string TextWriterTypeName = "System.IO.TextWriter";
public const string TaskConnectionMultiplexerTypeName = $"System.Threading.Tasks.Task`1<{ConnectionMultiplexerTypeName}>";
public const string TaskConnectionMultiplexerTypeName = $"System.Threading.Tasks.Task`1[{ConnectionMultiplexerTypeName}]";
public const string NullableServerType = $"System.Nullable`1[{ServerTypeTypeName}]";

public const string ConnectMethodName = "Connect";
public const string ConnectAsyncMethodName = "ConnectAsync";
public const string ConnectImplMethodName = "ConnectImpl";
public const string ConnectImplAsyncMethodName = "ConnectImplAsync";

private const string ServerTypeTypeName = "StackExchange.Redis.ServerType";
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,54 @@
using System;
using OpenTelemetry.AutoInstrumentation.CallTarget;

namespace OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis
namespace OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis;

/// <summary>
/// StackExchange.Redis.ConnectionMultiplexer calltarget instrumentation
/// </summary>
[InstrumentMethod(// releases 2.0.495 - 2.1.39
AssemblyName = StackExchangeRedisConstants.AssemblyName,
TypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
MethodName = StackExchangeRedisConstants.ConnectImplMethodName,
ReturnTypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
ParameterTypeNames = new[] { ClrNames.Object, StackExchangeRedisConstants.TextWriterTypeName },
MinimumVersion = StackExchangeRedisConstants.MinimumVersion,
MaximumVersion = StackExchangeRedisConstants.MaximumVersion,
IntegrationName = StackExchangeRedisConstants.IntegrationName)]
[InstrumentMethod(// releases 2.1.50 - 2.5.43
AssemblyName = StackExchangeRedisConstants.AssemblyName,
TypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
MethodName = StackExchangeRedisConstants.ConnectImplMethodName,
ReturnTypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
ParameterTypeNames = new[] { StackExchangeRedisConstants.ConfigurationOptionsTypeName, StackExchangeRedisConstants.TextWriterTypeName },
MinimumVersion = StackExchangeRedisConstants.MinimumVersion,
MaximumVersion = StackExchangeRedisConstants.MaximumVersion,
IntegrationName = StackExchangeRedisConstants.IntegrationName)]
[InstrumentMethod(// releases 2.5.61+
AssemblyName = StackExchangeRedisConstants.AssemblyName,
TypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
MethodName = StackExchangeRedisConstants.ConnectImplMethodName,
ReturnTypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
ParameterTypeNames = new[] { StackExchangeRedisConstants.ConfigurationOptionsTypeName, StackExchangeRedisConstants.TextWriterTypeName, StackExchangeRedisConstants.NullableServerType },
MinimumVersion = StackExchangeRedisConstants.MinimumVersion,
MaximumVersion = StackExchangeRedisConstants.MaximumVersion,
IntegrationName = StackExchangeRedisConstants.IntegrationName)]
public class StackExchangeRedisIntegration
{
/// <summary>
/// StackExchange.Redis.ConnectionMultiplexer calltarget instrumentation
/// OnMethodEnd callback
/// </summary>
[InstrumentMethod(
AssemblyName = StackExchangeRedisConstants.AssemblyName,
TypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
MethodName = StackExchangeRedisConstants.ConnectMethodName,
ReturnTypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
ParameterTypeNames = new[] { StackExchangeRedisConstants.ConfigurationOptionsTypeName, StackExchangeRedisConstants.TextWriterTypeName },
MinimumVersion = StackExchangeRedisConstants.MinimumVersion,
MaximumVersion = StackExchangeRedisConstants.MaximumVersion,
IntegrationName = StackExchangeRedisConstants.IntegrationName)]
public class StackExchangeRedisIntegration
/// <param name="returnValue">Return value</param>
/// <param name="exception">Exception value</param>
/// <param name="state">CallTarget state</param>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TReturn">Return type</typeparam>
/// <returns>A response value, in an async scenario will be T of Task of T</returns>
public static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TReturn returnValue, Exception exception, CallTargetState state)
{
/// <summary>
/// OnMethodEnd callback
/// </summary>
/// <param name="returnValue">Return value</param>
/// <param name="exception">Exception value</param>
/// <param name="state">CallTarget state</param>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TReturn">Return type</typeparam>
/// <returns>A response value, in an async scenario will be T of Task of T</returns>
public static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TReturn returnValue, Exception exception, CallTargetState state)
{
StackExchangeRedisInitializer.Initialize(returnValue);
StackExchangeRedisInitializer.Initialize(returnValue);

return new CallTargetReturn<TReturn>(returnValue);
}
return new CallTargetReturn<TReturn>(returnValue);
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,33 @@ namespace OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis;
/// <summary>
/// StackExchange.Redis.ConnectionMultiplexer calltarget instrumentation
/// </summary>
[InstrumentMethod(
[InstrumentMethod(// releases 2.0.495 - 2.1.39
AssemblyName = StackExchangeRedisConstants.AssemblyName,
TypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
MethodName = StackExchangeRedisConstants.ConnectAsyncMethodName,
MethodName = StackExchangeRedisConstants.ConnectImplAsyncMethodName,
ReturnTypeName = StackExchangeRedisConstants.TaskConnectionMultiplexerTypeName,
ParameterTypeNames = new[] { StackExchangeRedisConstants.ConfigurationOptionsTypeName, StackExchangeRedisConstants.TextWriterTypeName },
MinimumVersion = StackExchangeRedisConstants.MinimumVersion,
MaximumVersion = StackExchangeRedisConstants.MaximumVersion,
IntegrationName = StackExchangeRedisConstants.IntegrationName)]
[InstrumentMethod(// releases 2.1.50 - 2.5.43
AssemblyName = StackExchangeRedisConstants.AssemblyName,
TypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
MethodName = StackExchangeRedisConstants.ConnectImplAsyncMethodName,
ReturnTypeName = StackExchangeRedisConstants.TaskConnectionMultiplexerTypeName,
ParameterTypeNames = new[] { StackExchangeRedisConstants.ConfigurationOptionsTypeName, StackExchangeRedisConstants.TextWriterTypeName },
MinimumVersion = StackExchangeRedisConstants.MinimumVersion,
MaximumVersion = StackExchangeRedisConstants.MaximumVersion,
IntegrationName = StackExchangeRedisConstants.IntegrationName)]
[InstrumentMethod(// releases 2.5.61+
AssemblyName = StackExchangeRedisConstants.AssemblyName,
TypeName = StackExchangeRedisConstants.ConnectionMultiplexerTypeName,
MethodName = StackExchangeRedisConstants.ConnectImplAsyncMethodName,
ReturnTypeName = StackExchangeRedisConstants.TaskConnectionMultiplexerTypeName,
ParameterTypeNames = new[] { StackExchangeRedisConstants.ConfigurationOptionsTypeName, StackExchangeRedisConstants.TextWriterTypeName, StackExchangeRedisConstants.NullableServerType },
MinimumVersion = StackExchangeRedisConstants.MinimumVersion,
MaximumVersion = StackExchangeRedisConstants.MaximumVersion,
IntegrationName = StackExchangeRedisConstants.IntegrationName)]
public class StackExchangeRedisIntegrationAsync
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/StackExchangeRedisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void SubmitsTraces()

RunTestApplication(agent.Port, arguments: $"--redis {_redis.Port}");

const int expectedSpansCount = 2;
const int expectedSpansCount = 8;

var spans = agent.WaitForSpans(expectedSpansCount, TimeSpan.FromSeconds(5));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>

using System;
using System.Threading.Tasks;
using StackExchange.Redis;
using TestApplication.Shared;
Expand All @@ -29,22 +28,63 @@ public static async Task Main(string[] args)

var redisPort = GetRedisPort(args);

const string key = "myKey";
const string definedValue = "testValue";
var connectionString = $@"127.0.0.1:{redisPort}";

using (var connection = await ConnectionMultiplexer.ConnectAsync(connectionString))
{
var db = connection.GetDatabase();

db.StringSet(key, definedValue);
db.Ping();
}

using (var connection = await ConnectionMultiplexer.ConnectAsync(ConfigurationOptions.Parse(connectionString)))
{
var db = connection.GetDatabase();

db.Ping();
}

using (var connection = ConnectionMultiplexer.Connect(connectionString))
{
var db = connection.GetDatabase();

Console.WriteLine(db.StringGet(key));
db.Ping();
}

using (var connection = ConnectionMultiplexer.Connect(ConfigurationOptions.Parse(connectionString)))
{
var db = connection.GetDatabase();

db.Ping();
}

// SentinelConnect and SentinelConnectAsync introduced in 2.1.50
using (var connection = ConnectionMultiplexer.SentinelConnect(connectionString))
{
var db = connection.GetDatabase();

db.Ping();
}

using (var connection = ConnectionMultiplexer.SentinelConnect(ConfigurationOptions.Parse(connectionString)))
{
var db = connection.GetDatabase();

db.Ping();
}

using (var connection = await ConnectionMultiplexer.SentinelConnectAsync(connectionString))
{
var db = connection.GetDatabase();

db.Ping();
}

using (var connection = await ConnectionMultiplexer.SentinelConnectAsync(ConfigurationOptions.Parse(connectionString)))
{
var db = connection.GetDatabase();

db.Ping();
}
}

Expand Down

0 comments on commit aad6c78

Please sign in to comment.