-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/prod 2955/add traces to hz cache #12
Merged
JoelNygren-Norce
merged 16 commits into
main
from
feature/PROD-2955/Add-Traces-to-HzCache
Nov 27, 2024
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a9af0c3
added StartActivityWithCommonTags to all Functions
JoelNygren-Norce c254f95
add activityName to isActive option
JoelNygren-Norce 8ab0296
tidy
JoelNygren-Norce b69bf6f
added span for get from redis
JoelNygren-Norce 7cb7a15
internal -> public
JoelNygren-Norce 6c850df
added ExecuteFactory
JoelNygren-Norce 4af7b8b
added project and key to IsActive function
JoelNygren-Norce 45a1113
added traces to redis
JoelNygren-Norce 68ff078
wip
JoelNygren-Norce 6796dd5
Merge branch 'release/0.0.9' into feature/PROD-2955/Add-Traces-to-HzC…
JoelNygren-Norce 9451786
added activities
JoelNygren-Norce 7168cba
added activity
JoelNygren-Norce 7576b55
add activity
JoelNygren-Norce 69a0fb3
fixed tests
JoelNygren-Norce 0adac58
removed version nr.
JoelNygren-Norce 5441419
fixed null exception
JoelNygren-Norce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
|
||
namespace HzCache.Diagnostics | ||
{ | ||
public static class Activities | ||
{ | ||
public static ActivitySource? Source => new(HzCacheDiagnostics.ActivitySourceName, HzCacheDiagnostics.HzCacheVersion); | ||
|
||
public static class Names | ||
{ | ||
public const string Set = "set from cache"; | ||
public const string SetRedis = "set to redis"; | ||
public const string Get = "get from cache"; | ||
public const string GetRedis = "get from redis"; | ||
public const string GetOrSet = "get or set from cache"; | ||
public const string GetOrSetBatch = "get or set batch from cache"; | ||
public const string GetBatchRedis = "get batch from redis"; | ||
public const string Remove = "remove"; | ||
public const string RemoveByPattern = "remove by pattern"; | ||
public const string RemoveRedis = "remove from redis"; | ||
public const string RemoveByPatternRedis = "remove by pattern from redis"; | ||
public const string RemoveItem = "remove item"; | ||
public const string Clear = "clear"; | ||
public const string ExecuteFactory = "execute factory"; | ||
|
||
public const string NotifyItemChange = "notify item change"; | ||
public const string Subscribe = "subscribe"; | ||
public const string ValueChanged = "value changed"; | ||
public const string EvictExpired = "evict expired"; | ||
public const string GetStatistics = "get statistics"; | ||
public const string ProcessExpiredEviction = "process expired eviction"; | ||
|
||
public const string AcquireLock = "acquire lock"; | ||
public const string GetSemaphore = "get semaphore"; | ||
public const string ReleaseLock = "release lock"; | ||
|
||
|
||
} | ||
|
||
public static class Area | ||
{ | ||
public const string HzMemoryCache = "HzMemoryCache"; | ||
public const string HzCacheMemoryLocker = "HzCacheMemoryLocker"; | ||
public const string RedisBackedHzCache = "RedisBackedHzCache"; | ||
public const string Redis = "RedisCache"; | ||
} | ||
|
||
private static IEnumerable<KeyValuePair<string, object>> GetCommonTags(string? key, string project, bool async, string? pattern, bool? sendNotification) | ||
{ | ||
var res = new List<KeyValuePair<string, object?>> | ||
{ | ||
new KeyValuePair<string, object?>(Tags.Names.OperationKey, key), | ||
new KeyValuePair<string, object?>(Tags.Names.Project, project), | ||
new KeyValuePair<string, object?>(Tags.Names.Async, async), | ||
new KeyValuePair<string, object?>(Tags.Names.Pattern, pattern), | ||
new KeyValuePair<string, object?>(Tags.Names.SendNotification, sendNotification), | ||
}; | ||
|
||
return res; | ||
} | ||
|
||
public static Activity? StartActivityWithCommonTags(this ActivitySource source, string activityName, string project, bool async = false, string? key = null, string? pattern = null, bool? sendNotification = null) | ||
{ | ||
if (source.HasListeners() == false || !HzCacheTracesInstrumentationOptions.Instance.IsActive(activityName, project, key)) | ||
return null; | ||
|
||
return source.StartActivity( | ||
ActivityKind.Internal, | ||
tags: GetCommonTags(key, project, async, pattern, sendNotification), | ||
name: activityName | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace HzCache.Diagnostics | ||
{ | ||
public static class HzCacheDiagnostics | ||
{ | ||
public const string HzCacheVersion = "0.0.9"; | ||
public const string ActivitySourceName = "HzMemoryCache"; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
HzMemoryCache/Diagnostics/HzCacheTracesInstrumentationOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using static HzCache.Diagnostics.Activities; | ||
|
||
namespace HzCache.Diagnostics | ||
{ | ||
public class HzCacheTracesInstrumentationOptions | ||
{ | ||
public static HzCacheTracesInstrumentationOptions Instance { get; } = new(); | ||
public Func<string, string, string, bool> Active { private get; set; } | ||
|
||
public bool IsActive(string activityName,string project, string? key) => Active(activityName, project, key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace HzCache.Diagnostics | ||
{ | ||
internal static class Tags | ||
{ | ||
internal static class Names | ||
{ | ||
public const string OperationKey = "hzcache.operation.key"; | ||
public const string Pattern = "hzcache.pattern"; | ||
public const string SendNotification = "hzcache.sendNotification"; | ||
public const string Project = "hzcache.project"; | ||
public const string Async = "hzcache.operation.async"; | ||
public const string AcquiredLock = "hzcache.result.lock.acquired"; | ||
public const string ReleasedLock = "hzcache.result.lock.released"; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
HzMemoryCache/Diagnostics/TracerProviderBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using OpenTelemetry.Trace; | ||
using System; | ||
|
||
namespace HzCache.Diagnostics | ||
{ | ||
public static class TracerProviderBuilderBuilderExtensions | ||
{ | ||
public static TracerProviderBuilder AddHzCacheMemoryInstrumentation(this TracerProviderBuilder builder, | ||
Action<HzCacheTracesInstrumentationOptions>? configure = null) | ||
{ | ||
if (builder is null) | ||
throw new ArgumentNullException(nameof(builder)); | ||
|
||
var options = HzCacheTracesInstrumentationOptions.Instance; | ||
configure?.Invoke(options); | ||
|
||
builder.AddSource(HzCacheDiagnostics.ActivitySourceName); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely this will be 0.0.10 once this is merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maby we should remove this as no one will keep it updated?