90 lines
3.3 KiB
C#
90 lines
3.3 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace StellaOps.Provcache;
|
|
|
|
public static partial class ProvcacheTelemetry
|
|
{
|
|
/// <summary>
|
|
/// Start a cache lookup activity.
|
|
/// </summary>
|
|
/// <param name="veriKey">The VeriKey being looked up.</param>
|
|
/// <returns>The activity or null if tracing is not enabled.</returns>
|
|
public static Activity? StartGetActivity(string veriKey)
|
|
{
|
|
var activity = ActivitySource.StartActivity("provcache.get", ActivityKind.Internal);
|
|
if (activity is null) return null;
|
|
|
|
activity.SetTag("provcache.verikey", TruncateVeriKey(veriKey));
|
|
return activity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start a cache store activity.
|
|
/// </summary>
|
|
/// <param name="veriKey">The VeriKey being stored.</param>
|
|
/// <param name="trustScore">The trust score of the entry.</param>
|
|
/// <returns>The activity or null if tracing is not enabled.</returns>
|
|
public static Activity? StartSetActivity(string veriKey, int trustScore)
|
|
{
|
|
var activity = ActivitySource.StartActivity("provcache.set", ActivityKind.Internal);
|
|
if (activity is null) return null;
|
|
|
|
activity.SetTag("provcache.verikey", TruncateVeriKey(veriKey));
|
|
activity.SetTag("provcache.trust_score", trustScore);
|
|
return activity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start an invalidation activity.
|
|
/// </summary>
|
|
/// <param name="invalidationType">The type of invalidation (verikey, policy_hash, signer_set_hash, feed_epoch).</param>
|
|
/// <param name="targetValue">The target value for invalidation.</param>
|
|
/// <returns>The activity or null if tracing is not enabled.</returns>
|
|
public static Activity? StartInvalidateActivity(string invalidationType, string? targetValue)
|
|
{
|
|
var activity = ActivitySource.StartActivity("provcache.invalidate", ActivityKind.Internal);
|
|
if (activity is null) return null;
|
|
|
|
activity.SetTag("provcache.invalidation_type", invalidationType);
|
|
if (!string.IsNullOrWhiteSpace(targetValue))
|
|
{
|
|
activity.SetTag("provcache.target", TruncateVeriKey(targetValue));
|
|
}
|
|
|
|
return activity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start a write-behind flush activity.
|
|
/// </summary>
|
|
/// <param name="batchSize">Number of entries in the batch.</param>
|
|
/// <returns>The activity or null if tracing is not enabled.</returns>
|
|
public static Activity? StartWriteBehindFlushActivity(int batchSize)
|
|
{
|
|
var activity = ActivitySource.StartActivity("provcache.writebehind.flush", ActivityKind.Internal);
|
|
if (activity is null) return null;
|
|
|
|
activity.SetTag("provcache.batch_size", batchSize);
|
|
return activity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start a VeriKey construction activity.
|
|
/// </summary>
|
|
/// <returns>The activity or null if tracing is not enabled.</returns>
|
|
public static Activity? StartVeriKeyBuildActivity()
|
|
{
|
|
return ActivitySource.StartActivity("provcache.verikey.build", ActivityKind.Internal);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start a DecisionDigest construction activity.
|
|
/// </summary>
|
|
/// <returns>The activity or null if tracing is not enabled.</returns>
|
|
public static Activity? StartDecisionDigestBuildActivity()
|
|
{
|
|
return ActivitySource.StartActivity("provcache.digest.build", ActivityKind.Internal);
|
|
}
|
|
}
|