Merged
Conversation
Member
$client = new Client();
$spanContext = new SpanContext();
$spanContext->setOp('http.client');
$spanContext->setDescription('GET http://google.com');
trace(
function (Scope $scope) use ($client) {
return $client->get('http://google.com');
},
$spanContext,
);$spanContext = new SpanContext();
$spanContext->setOp('http.client');
$spanContext->setDescription('GET http://google.com');
$transaction = SentrySdk::getCurrentHub()->getTransaction();
$span = $transaction->startChild($spanContext);
$client = new Client();
$client->get('http://google.com');
$span->finish();A small improvement, but it is an improvement! |
cleptric
approved these changes
Mar 14, 2023
Collaborator
Author
|
Yeah, the context thing is unfortunate. If it had a fluent syntax we could so some really cool things like: trace(...)
->op('some.op')
->description('Something to trace')
->run()Which honestly might be attainable actually... without breaking changes. Worth it? |
Member
|
Not sure tbh. We now have a way better span creator, called profiling 😛 I still think it's worth going this route in v4, but would be ok with the current approach for now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the
tracehelper function that reduces a lot of boilerplate of adding spans for user code, allowing users to quickly wrap existing calls with a span and it looks something like this:The
SpanContextis a unfortunate object in our API at the moment and doesn't have a fluent interface so I've used thetap()helper from Laravel to keep it a little more readable in the example.This was originally coined in Laravel (getsentry/sentry-laravel#598) but is general enough for all of PHP to benefit from.