Skip to content
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] Activity hit/miss tags #303

Closed
dotTrench opened this issue Sep 10, 2024 · 5 comments
Closed

[FEATURE] Activity hit/miss tags #303

dotTrench opened this issue Sep 10, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@dotTrench
Copy link

dotTrench commented Sep 10, 2024

Problem

Currently the tags for an activity does not contain any tags indicating whether a cache lookup resulted in a miss or a hit.
This would probably be applicable to the: TryGet, GetOrDefault, GetOrSet, MemoryGet, DistributedGet activities defined in Activities.Names.

Solution

Add tags indicating whether a cache to the activity before it's disposed. e.g. "fusioncache.operation.hit": true/false

Alternatives

The current workarounds I can figure out to indicate whether a cache hit occurs on an activity that I can figure out is to attach an event handler to the FusionCache instance and enrich the ongoing or a wrapping activity from there. e.g.

cache.Event.Hit += (_, _) => Activity.Current?.SetTag("cache.hit", true);
cache.Event.Miss += (_, _) => Activity.Current?.SetTag("cache.hit", false);

however this would also require me to set EnableSyncEventHandlersExecution to true to ensure that the activity is not disposed before setting the tag.

Additional context

I'm not really sure how this would interact with FailSafe as this is not something I personally use, but probably keep this in consideration.

@jodydonetti
Copy link
Collaborator

Hi @dotTrench , I think you are right.
Let me think about it a moment and will get back to you.
Thanks!

@jodydonetti
Copy link
Collaborator

I'm implementing this, will update later with some news about it.
Thanks again!

@jodydonetti
Copy link
Collaborator

Hi @dotTrench , I've added support for this, and 1 extra tag:

  • "fusioncache.hit" (bool)
  • "fusioncache.stale" (bool)

I was already using "fusioncache.hit" somewhere else, so I preferred uniformity, and also both are very general concepts (hit/miss and stale/fresh).

Will release the next version very soon, probably tomorrow.

@jodydonetti jodydonetti self-assigned this Sep 14, 2024
@jodydonetti jodydonetti added the enhancement New feature or request label Sep 14, 2024
@jodydonetti jodydonetti added this to the v1.4.0 milestone Sep 14, 2024
@dotTrench
Copy link
Author

Thank you, that's great man! The tags makes sense.

I really appreciate the work you've put into this library, it has saved me a lot of time and pain!

@jodydonetti
Copy link
Collaborator

Hi, v1.4.0 has been released 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants