Skip to content
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

Implementation of optional sentry tracing with twig #430

Merged
merged 5 commits into from Feb 22, 2021

Conversation

rjd22
Copy link
Contributor

@rjd22 rjd22 commented Jan 26, 2021

At last ;), the Twig tracing with tests. This also includes the same suggested dependencies fix as the DbalListener. Hopefully git can figure out the merge conflicts :D.

To use Twig tracing you will have to enable the following options:

sentry:
    tracing:
        twig:
            enabled: true

Good luck!

@ste93cry
Copy link
Collaborator

I never looked at the internals of Twig in depth, but looking at how the profiler is integrated in Symfony they extends the Twig\Extension\ProfilerExtension class. Does doing that have some advantages? Besides this, are you up to rebase this PR and at least align the main changes following the conventions used in the one for Doctrine DBAL?

@rjd22
Copy link
Contributor Author

rjd22 commented Feb 17, 2021

@ste93cry I actually did this first but decoupled it later on to lower the dependency and risk of breaking on changes there. There is no real advantage for us to extend it. I will rebase this one later this week to apply the changes of the DBAL integration.

@ste93cry
Copy link
Collaborator

ste93cry commented Feb 17, 2021

I will rebase this one later this week

Ok, only then I will review the code because doing it now would be useless as a lot of things are gonna change 😃

I actually did this first but decoupled it later on to lower the dependency and risk of breaking on changes there

I just checked and the class is not marked as @internal, so I expect it to not be changed by introducing BC changes between patch/minor versions. Anyway, we have to think broader: what if the user, for some reason, is already using that extension? I find it unlikely as I believe it's mostly used to fill the data for the profiler of Symfony, but you never know...

@rjd22
Copy link
Contributor Author

rjd22 commented Feb 17, 2021

@ste93cry AFAIK this should not be a problem. We register our own ProfilerNodeVisitor. The Twig\Extension\ProfilerExtension also caches calls on enter and leave. We're not using this data so using the ProfilerExtension was reserving unused memory.

After checking it again this was my reason for not using it. Registering your own extensions in Twig like the way I build it is how it is commonly done.

Edit:
I will need to check if there is some other reason the ProfilerExtension is used but I could not find one. @ste93cry Are you seeing something that I might be missing?

@rjd22
Copy link
Contributor Author

rjd22 commented Feb 17, 2021

After checking:

https://github.com/symfony/twig-bundle/blob/667d462b8b28d91e2a44b47712171d52b1a57579/Resources/config/twig.php#L91-L92

I feel unsure if we need to use the ProfilerExtension or not. Symfony registers their own and adds the Profiler dependency. Afaik registering our own extension does not interfere with this.

@Jean85
Copy link
Collaborator

Jean85 commented Feb 18, 2021

IMHO we should also check if the ProfilerExtension isn't bound to non-prod environments: from what I can remember, in Symfony default configs, all that stuff is shut down with debug: false, and we can't ask the user to switch on all that stuff!

@rjd22 rjd22 force-pushed the feature/twig-tracing-support branch 5 times, most recently from b5bd18a to a3f6cb8 Compare February 21, 2021 10:55
@rjd22 rjd22 force-pushed the feature/twig-tracing-support branch from a3f6cb8 to 6d29db8 Compare February 21, 2021 11:08
@rjd22
Copy link
Contributor Author

rjd22 commented Feb 21, 2021

@ste93cry @Jean85 I rebased it and modified it to how the Dbal tracing was build and added tests. This one is good to go.

phpstan-baseline.neon Outdated Show resolved Hide resolved
phpstan-baseline.neon Outdated Show resolved Hide resolved
src/DependencyInjection/Configuration.php Show resolved Hide resolved
src/Tracing/Twig/TwigTracingExtension.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@Jean85 Jean85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I solved the static analysis issues, LGTM now! 👍

@Jean85 Jean85 requested a review from ste93cry February 22, 2021 13:43
Copy link
Collaborator

@ste93cry ste93cry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, more features can always be added later if we will see there is need. LGTM!

@ste93cry ste93cry merged commit de86b84 into getsentry:develop Feb 22, 2021
@rjd22 rjd22 deleted the feature/twig-tracing-support branch February 23, 2021 09:24
@rjd22
Copy link
Contributor Author

rjd22 commented Feb 23, 2021

@ste93cry thanks a lot. I will rebase the the last one. :)

@VincentLanglet
Copy link

Hi @rjd22 Could some documentation of this option be added in the Readme ?
I don't understand what it does.

@Jean85
Copy link
Collaborator

Jean85 commented Apr 23, 2021

This adds tracing capabilities for Twig templates. For more info about tracing (which got released in 4.1) see https://docs.sentry.io/product/performance/distributed-tracing/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants