Replies: 1 comment
-
You are using both cache and traceFunction higher-order functions together. The issue is that some fetch calls are happening multiple times even though you expect caching to prevent that. The cache function stores the result of the function based on its input parameters. When the same parameters are used again before the cache expires, the cached result is returned without calling the function again. The traceFunction wraps the original function to add tracing spans whenever the function is actually invoked. What likely happens is that when the cache is empty or expired, the function runs and the fetch call happens, creating a trace span. When the cache is still valid, the cached result is returned directly and the function is not called, so no new trace span is created. If you observe multiple fetches, it could be due to different input parameters, cache expiration, or unintentional parameter changes. To debug, make sure the inputs to your cached function are consistent. You can also add tracing inside the fetch itself to confirm how many times the network request runs. Remember that cache works by preventing the function from being called again for the same inputs within the cache duration. If you want to trace cache hits and misses, you will need to add instrumentation to the cache logic itself. Using cache with traceFunction is correct and will trace real function calls. If fetch calls happen multiple times, verify the inputs and cache expiration. Let me know if you want help with an example or debugging ideas! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm using both react
cache
and and thistraceFunction
as HOFs.I don't know if its just the instrumentation being replayed, or since it's cached as a HOF, then it's still being called, but with the same results.
The problem is that some of the things being cached are
fetch
calls from other service, which shows it's being called multiple times.I'm even adding this to the
fetch
calls:Example of use:
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions