sentry-symfony icon indicating copy to clipboard operation
sentry-symfony copied to clipboard

Unusable trace data called in a callback

Open jokaorgua opened this issue 2 years ago • 9 comments

Environment

How do you use Sentry? Self-hosted (Sentry 21.11.0)

Which SDK and version? PHP 4.2.8

Used config for sentry in symfony

tracing:
        enabled: true
        dbal: # DB queries
            enabled: true
        cache:
            enabled: true
        twig: # templating engine
            enabled: true

Steps to Reproduce

  1. Create any kind of a controller for symfony for any kind of a route (POST, GET)
  2. Provide a CacheInterface to it (I used redis as an adapter)
  3. use code similar to

return $this->cache->get(
            function (ItemInterface $item) {
                $item->expiresAfter($this->cacheTime);

                return $this->handler->handle($someDataWhatever);
            }
        );

Expected Result

Trace in sentry with normal function names. At least $this->handler->handle took 50ms or similar

Actual Result

image

jokaorgua avatar Apr 27 '22 12:04 jokaorgua

If I understand correctly, what you are reporting is that the span has a random name (that hash is not something we’re generating in the SDK) while it should probably be the name of the retrieved key, right?

ste93cry avatar May 11 '22 14:05 ste93cry

@ste93cry not only that. I'm expecting that span will have information about the total working time of the wrapped cache function. In our case, this is the handle function.

and I like you idea of renaming the spans for including the cache key in it. Or maybe other way to understand which key was requested

jokaorgua avatar May 11 '22 14:05 jokaorgua

I'm expecting that span will have information about the total working time of the wrapped cache function. In our case, this is the handle function.

I’m not sure I get what’s the problem right now. The span is already wrapping the execution of whatever method is called internally, so it measures and reports its execution time already

ste93cry avatar May 11 '22 14:05 ste93cry

I'm expecting that span will have information about the total working time of the wrapped cache function. In our case, this is the handle function.

I’m not sure I get what’s the problem right now. The span is already wrapping the execution of whatever method is called internally, so it measures and reports its execution time already

I do not see such functionality. At least my sentry does not show anything related to handler function in traces

image this is all that I see

jokaorgua avatar May 11 '22 14:05 jokaorgua

I think I'm getting a grasp of what you want. I completely missed the fact that $this->handler->handle() was your own code and not something part of the SDK. In this case, its execution time is of course measured as part of the parent $this->cache->get() call, but if what you're looking for is a child span that specifically measures its execution time only then you won't find it because, well, the SDK cannot instrument something that it doesn't know about. If you want to trace your own code, you have to instrument it yourself. The documentation is a good place to start from to see how you can do it

ste93cry avatar May 11 '22 18:05 ste93cry

Of course if I need to measure my own code I will add spans manually into the handler itself.

Maybe it would be possible to change the sdk to include cache key into the span ? As you proposed above. At least this could help to find the needed cache-get span where the handler has been executed.

jokaorgua avatar May 11 '22 18:05 jokaorgua

Maybe it would be possible to change the sdk to include cache key into the span

Absolutely. I would classify this as a bug, because when I coded the integration I actually meant to log the cache key, but then I must have forgot it during the implementation

ste93cry avatar May 11 '22 18:05 ste93cry

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jun 21 '22 00:06 github-actions[bot]

No stale. This is a bug

jokaorgua avatar Jun 21 '22 04:06 jokaorgua

Hey @jokaorgua I know it's been a while, but I looked into this.

Screenshot 2022-11-21 at 19 48 46

We could add the cache key as the span description, would this be helpful? I still have to figure out the format of these keys, I had to do some urlencode to make them look half decent.

cleptric avatar Nov 21 '22 18:11 cleptric

@cleptric awesome. Maybe would be better to have a line too ?

jokaorgua avatar Nov 21 '22 18:11 jokaorgua

I'm not sure if we have access to the line number here. Or did I get your question wrong?

cleptric avatar Nov 21 '22 19:11 cleptric

@cleptric my bad. I though this is a path of a caller. And this is a cache key. Sorry. Your idea is great. Would be awesome.

jokaorgua avatar Nov 21 '22 19:11 jokaorgua

I opened https://github.com/getsentry/sentry-symfony/pull/677. Would be happy if you can try it out and report back 👍

cleptric avatar Nov 21 '22 19:11 cleptric

Released via 4.8.0

cleptric avatar May 02 '23 09:05 cleptric