With version 2.3.1 _before_send_ event seems to no longer be raised for "traces sample" case.
Do you have suggestions on how I can rename the transaction in this case or add spans in event ?
Thanks
__Originally posted by @illambo in https://github.com/getsentry/sentry-laravel/issues/415#issuecomment-761759121__
In order to attach spans I used this in a middleware e seems work:
$transaction = SentrySdk::getCurrentHub()->getTransaction();
if ($transaction instanceof Transaction) {
// @see https://docs.sentry.io/platforms/php/guides/laravel/performance/#retrieving-a-transaction
$transaction->setName('Foo'); // not work
$transaction->setData([ // not work
'action' => 'Bar',
'name' => 'Foo',
]);
if (defined('LARAVEL_START') && request()->header('X-Request-Start')) {
$xRequestStart = floatval(str_replace('t=', '', request()->header('X-Request-Start')));
$spanContext = new SpanContext();
$spanContext->setOp('queuing'); // queuing time
$spanContext->setStartTimestamp($xRequestStart);
$spanContext->setEndTimestamp(LARAVEL_START); // microtime(true)
$transaction->startChild($spanContext);
}
}
Is this the best best practice ? Why the _setName_ method doesn't work (i followed this) ?
Hi @illambo, thanks for raising this issue.
I think you are doing it right but the order of operations are messing up your efforts.
First, the before_send no longer works because of this PR: https://github.com/getsentry/sentry-php/pull/1158. The before_send should have never worked for transactions.
Transactions should not go through beforeSend. However, they are still processed by Event Processors. This is a compromise between some flexibility in dealing with the current implementation of transactions as events, and leaving room for different lifetime hooks for transactions and spans.
With that out of the way I can say that you are doing the right thing renaming transactions but I think the Laravel SDK is overwriting those values here:
This code is called just before the transactions is finished (and sent):
So your code will always be too early or too late.
I am discussing with the PHP team what is the best way to do this or that we want to change our order of operations in the SDK to allow you to set a custom transaction name.
I'll get back to you on that but I hope this explains why it's not working what you are trying to do at the moment!
Ok, it's clear, thanks.
I think this in graphql scenario it is usefull in order to differentiate the performance (in the meantime I use the tags).
May I ask what GraphQL library you are using, I am considering implementing "native" support for surfacing transaction names for Lighthouse (either from the Laravel SDK or their package). But if you are using another I might want to check that out too!
I am currently using rebing/graphql-laravel.
Do you have a temporary solution ?
And maybe is better move this as an issue because not match the provided documentation.
What do you think?
Thanks
I have created #442 to hopefully resolve your issue, if you are able to test it out that would be great.
I did a quick test, it works great and thanks!
Awesome, I don't want to release this today if it's okay since it's Friday here.
I'll try and get this out on Monday!
Thanks for your testing and patience 馃憤
Hey @stayallive, I was looking into setting this up for Lighthouse.
Did you do any work on it?