-
-
Notifications
You must be signed in to change notification settings - Fork 199
feat: 2.x #373
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
Conversation
* feat: Add Tracing Middleware Record sql queries as spans * feat: Auto prepend middleware Instrument view renders * ref: Change code comments * ref: Use terminate to send transaction * Rename view engine decorator * Improve transaction context name/description * Prevent crashes when using missing defines * Do not remove all leading `/` keep 1 * Add fallback autoload + bootstrap span * Set the transaction name from the event handler * Cleanup query span * Prevent errors on Laravel 5.3 and below * CS * feat: Use correct route and add data * ref: Add name * fix: Route naming * feat: Start transaction in serviceProvider Move all renders as a child * ref: Rename to view.render * ref: Move back to starting transaction in middleware Use fromTraceparent function to start a trace * ref: Small refactor * feat: Update composer.json * ref: Add traces_sample_rate * Refactor active span retrieval * Guard against the active span not being set * Docblock updates * Correctly return rendered view without span * Move tracing related code to the Tracing namespace * Improve the route name detection order * Do not use route names ending with a `.` * Fix not wrapping the view enines when resolver is already resolved * feat: Rework code to use transaction on the hub Co-authored-by: Alex Bouma <[email protected]>
|
Could you merge Laravel 8 support into this branch too? |
# Conflicts: # CHANGELOG.md # composer.json # src/Sentry/Laravel/Version.php
|
@arcdigital yep, done. |
|
Thanks! |
Co-authored-by: Alex Bouma <[email protected]>
|
Any ETA on this PR? |
|
Problem 1 |
|
@danijelk do you have |
|
@stayallive thanks for reply Indeed it's not in the list that's why the error is so weird. composer remove sentry/sdk but since 1.9 was installed that's why it couldn't upgrade, so had to composer remove old sentry/sentry-laravel, and then add it manually to composer.json - and first then upgrade it :) whups 👍 |
|
@HazAT what is the current roadmap for this PR? If you're willing to accept a feature requests:
|
* feat: Add publish command * fix: Typos
|
@georgeboot wrt to Transaction names, so this is probably only a matter of documentation. You can get the active transaction by calling and then change the name. $transaction = SentrySdk::getCurrentHub()->getTransaction();
if (null !== $transaction) {
$transaction->setName('your name instead');
}Hope this helps. |
|
@georgeboot Here is a middleware that you can use in some of your controllers to achieve what you want. <?php
namespace App\Http\Middleware;
use Closure;
use Sentry\SentrySdk;
use Sentry\Tracing\Transaction;
class SentryExcludeTransactionMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
if (app()->bound('sentry')) {
$transaction = SentrySdk::getCurrentHub()->getTransaction();
// Do additional checks here on $request->route() or whatever to decide
// if you want to send the transaction or not
if ($transaction instanceof Transaction) {
// $transaction->setSampled(false); // __DONT__ SEND TRANSACTION
// $transaction->setSampled(true); // __DO__ SEND TRANSACTION
$transaction->setSampled(false);
}
}
return $next($request);
}
} |
|
EDIT: getsentry/sentry-php#1096 How to instrument Guzzle HTTP Calls: <?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use Sentry\SentrySdk;
use Sentry\State\Scope;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Psr\Http\Message\RequestInterface;
use Sentry\Tracing\SpanContext;
use Sentry\Tracing\Transaction;
use GuzzleHttp\Handler\CurlHandler;
/**
* Class HomeController.
*/
class HomeController extends Controller
{
/**
* @return \Illuminate\View\View
*/
public function index()
{
function addSentrySpans() {
return function (callable $handler) {
return function (RequestInterface $request, array $options) use ($handler) {
$transaction = SentrySdk::getCurrentHub()->getTransaction();
$span = null;
if ($transaction instanceof Transaction) {
$spanContext = new SpanContext();
$spanContext->setOp('http.guzzle');
$spanContext->setDescription($request->getMethod() . ' ' . $request->getUri());
$span = $transaction->startChild($spanContext);
}
$result = $handler($request, $options);
if (null !== $span) {
$span->finish();
}
return $result;
};
};
}
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(addSentrySpans());
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'http://httpbin.org',
// You can set any number of default request options.
'timeout' => 2.0,
'handler' => $stack
]);
$response = $client->request('GET', '/get');
..... |
Installation
Read
https://docs.sentry.io/performance-monitoring/performance/
to understand the concept behind Tracing/Performance in Sentry.
Make sure you have following in you
composer.jsonAfter that run
composer update.After that add
'traces_sample_rate' => 1.0,to the file inconfig/sentry.php.Note that the value should be larger than
0.0and smaller or equal than1.0(to send everything).More info can be found here: https://docs.sentry.io/performance-monitoring/getting-started/
Connecting your frontend
To setup tracing for your Vue frontend, follow: https://docs.sentry.io/performance-monitoring/getting-started/?platform=vue
An additional step you should take is, add this to your blade template rendering the
<head>tag{!! Sentry\Laravel\Integration::sentryTracingMeta() !!}This adds a meta tag similar to
<meta name="sentry-trace" content="ae02a316231d490c870b14f27aba8d29-c4a72ffd39444c84-1"/>to your header and tells the frontend code to pick up the trace.