add metrics to sdk (#133)
* add metrics to sdk * metrics for sends and receives * format
This commit is contained in:
@@ -37,6 +37,7 @@ public partial class Operations
|
||||
)
|
||||
{
|
||||
using var receiveActivity = activityFactory.Start("Operations.Receive");
|
||||
metricsFactory.CreateCounter<long>("Receive").Add(1);
|
||||
|
||||
if (remoteTransport != null)
|
||||
{
|
||||
|
||||
@@ -78,6 +78,7 @@ public partial class Operations
|
||||
}
|
||||
|
||||
// make sure all logs in the operation have the proper context
|
||||
metricsFactory.CreateCounter<long>("Send").Add(1);
|
||||
using var activity = activityFactory.Start();
|
||||
activity?.SetTag("correlationId", Guid.NewGuid().ToString());
|
||||
{
|
||||
|
||||
@@ -10,4 +10,8 @@ namespace Speckle.Sdk.Api;
|
||||
/// <para>Push/Pull (methods to serialize and send data to one or more servers)</para>
|
||||
/// </summary>
|
||||
[GenerateAutoInterface]
|
||||
public partial class Operations(ILogger<Operations> logger, ISdkActivityFactory activityFactory) : IOperations;
|
||||
public partial class Operations(
|
||||
ILogger<Operations> logger,
|
||||
ISdkActivityFactory activityFactory,
|
||||
ISdkMetricsFactory metricsFactory
|
||||
) : IOperations;
|
||||
|
||||
@@ -6,10 +6,3 @@ public interface ISdkActivityFactory : IDisposable
|
||||
{
|
||||
ISdkActivity? Start(string? name = default, [CallerMemberName] string source = "");
|
||||
}
|
||||
|
||||
public sealed class NullActivityFactory : ISdkActivityFactory
|
||||
{
|
||||
public void Dispose() { }
|
||||
|
||||
public ISdkActivity? Start(string? name = default, string source = "") => null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Speckle.Sdk.Logging;
|
||||
|
||||
public interface ISdkCounter<T>
|
||||
where T : struct
|
||||
{
|
||||
void Add(T value);
|
||||
void Add(T value, KeyValuePair<string, object?> tag);
|
||||
void Add(T value, KeyValuePair<string, object?> tag1, KeyValuePair<string, object?> tag2);
|
||||
void Add(
|
||||
T value,
|
||||
KeyValuePair<string, object?> tag1,
|
||||
KeyValuePair<string, object?> tag2,
|
||||
KeyValuePair<string, object?> tag3
|
||||
);
|
||||
void Add(T value, params KeyValuePair<string, object?>[] tag);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Speckle.Sdk.Logging;
|
||||
|
||||
public interface ISdkMetricsFactory
|
||||
{
|
||||
ISdkCounter<T> CreateCounter<T>(string name, string? unit = default, string? description = default)
|
||||
where T : struct;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Speckle.Sdk.Logging;
|
||||
|
||||
public sealed class NullActivityFactory : ISdkActivityFactory
|
||||
{
|
||||
public void Dispose() { }
|
||||
|
||||
public ISdkActivity? Start(string? name = default, string source = "") => null;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Speckle.Sdk.Logging;
|
||||
|
||||
public sealed class NullSdkCounter<T> : ISdkCounter<T>
|
||||
where T : struct
|
||||
{
|
||||
public void Add(T value) { }
|
||||
|
||||
public void Add(T value, KeyValuePair<string, object?> tag) { }
|
||||
|
||||
public void Add(T value, KeyValuePair<string, object?> tag1, KeyValuePair<string, object?> tag2) { }
|
||||
|
||||
public void Add(
|
||||
T value,
|
||||
KeyValuePair<string, object?> tag1,
|
||||
KeyValuePair<string, object?> tag2,
|
||||
KeyValuePair<string, object?> tag3
|
||||
) { }
|
||||
|
||||
public void Add(T value, params KeyValuePair<string, object?>[] tag) { }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Speckle.Sdk.Logging;
|
||||
|
||||
public sealed class NullSdkMetricsFactory : ISdkMetricsFactory
|
||||
{
|
||||
public ISdkCounter<T> CreateCounter<T>(string name, string? unit = default, string? description = default)
|
||||
where T : struct => new NullSdkCounter<T>();
|
||||
}
|
||||
@@ -27,7 +27,8 @@ public static class ServiceRegistration
|
||||
Slug = application.Slug,
|
||||
}
|
||||
);
|
||||
serviceCollection.AddSingleton<ISdkActivityFactory, NullActivityFactory>();
|
||||
serviceCollection.TryAddSingleton<ISdkActivityFactory, NullActivityFactory>();
|
||||
serviceCollection.TryAddSingleton<ISdkMetricsFactory, NullSdkMetricsFactory>();
|
||||
serviceCollection.AddMatchingInterfacesAsTransient(Assembly.GetExecutingAssembly());
|
||||
return serviceCollection;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user