Skip to content

Commit

Permalink
feat: redis.client.request.duration to db.client.operation.duration
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagodaraujo committed Nov 6, 2024
1 parent 45816c4 commit d343c6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using System.Diagnostics.Metrics;
using System.Reflection;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation;

internal class RedisMetrics : IDisposable
{
internal const string MetricRequestDurationName = "redis.client.request.duration";
internal const string MetricQueueDurationName = "redis.client.queue.duration";
internal const string MetricNetworkDurationName = "redis.client.network.duration";
internal const string OperationMetricName = "db.client.operation.duration";
internal const string QueueMetricName = "db.client.queue.duration";
internal const string NetworkMetricName = "db.client.network.duration";

internal static readonly Assembly Assembly = typeof(StackExchangeRedisInstrumentation).Assembly;
internal static readonly AssemblyName AssemblyName = Assembly.GetName();
Expand All @@ -25,19 +26,20 @@ public RedisMetrics()
this.meter = new Meter(InstrumentationName, InstrumentationVersion);

this.QueueHistogram = this.meter.CreateHistogram<double>(
MetricQueueDurationName,
QueueMetricName,
unit: "s",
description: "Total time the redis request was waiting in queue before being sent to the server.");

this.NetworkHistogram = this.meter.CreateHistogram<double>(
MetricNetworkDurationName,
NetworkMetricName,
unit: "s",
description: "Duration of redis requests since sent the request to receive the response.");

this.RequestHistogram = this.meter.CreateHistogram<double>(
MetricRequestDurationName,
this.OperationHistogram = this.meter.CreateHistogram<double>(
OperationMetricName,
unit: "s",
description: "Total client request duration, including processing, queue and server duration.");
description: "Total client request duration, including processing, queue and server duration.",
[new(SemanticConventions.AttributeDbSystem, "redis")]);
}

public static RedisMetrics Instance { get; } = new RedisMetrics();
Expand All @@ -46,9 +48,9 @@ public RedisMetrics()

public Histogram<double> NetworkHistogram { get; }

public Histogram<double> RequestHistogram { get; }
public Histogram<double> OperationHistogram { get; }

public bool Enabled => this.RequestHistogram.Enabled;
public bool Enabled => this.OperationHistogram.Enabled;

public void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static bool GetCommandAndKey(
{
metrics.QueueHistogram.Record(command.EnqueuedToSending.TotalSeconds, meterTagList);
metrics.NetworkHistogram.Record(command.SentToResponse.TotalSeconds, meterTagList);
metrics.RequestHistogram.Record(command.ElapsedTime.TotalSeconds, meterTagList);
metrics.OperationHistogram.Record(command.ElapsedTime.TotalSeconds, meterTagList);
}

activity?.Stop();
Expand Down

0 comments on commit d343c6c

Please sign in to comment.