Git Product home page Git Product logo

neos-debug's Introduction

CircleCI Latest Stable Version License

t3n.Neos.Debug

The t3n.Neos.Debug package is a small helper package to add a debug panel to your Neos CMS website. At this point in time you're able to debug your content cache configuration as well as sql queries. Additionally, the Server-Timing http header can be enabled that will add request timings to responses. Those then can be viewed in the browser network tab.

Note: This is still a very early rough version. Contributions are welcome in any Error. Nevertheless, it's already adding value to your debug experience

Neos CMS Demo Site with enabled debug console Server-Timing header in the browser network tab

Installation & configuration

Install the package via composer

composer require t3n/neos-debug --dev

The debug mode is disabled by default. To enable it add this to your Settings.yaml

t3n:
  Neos:
    Debug:
      enabled: true

To bring up the debug panel run this command in your js console:

__enable_neos_debug__()

Disclaimer: Once the debug mode is enabled you might expose sensitive data. Make sure to not use this in production. At least be warned

In a previous version of this package your current user needed a specific role as well. We dropped this requirement for now as you could not use this package if you don't have a frontend login on your site. Once the package is active it will render some metadata in your html output.

To get the debugger running you now need to include some javascript and css to acutally render the debug console. This package ships two fusion prototypes to include all resources. If your Document extends Neos.Neos:Page you don't need to include anything. We already added the resources to Neos.Neos:Page prototype.

HTTP Server-Timing header

The header is disabled by default. To enable it add this to your Settings.yaml

t3n:
  Neos:
    Debug:
      serverTimingHeader:
        enabled: true

If you only want the header with all timings but not the debug mode, do this:

t3n:
  Neos:
    Debug:                                                  
      enabled: true
      htmlOutput:
        enabled: false
      serverTimingHeader:
        enabled: true

Usage

To enable the cache visualization open your browsers developer console and execute __enable_neos_debug__(). This will bring up the debug console at the bottom of your screen.

🔦 Inspect

Once you enable the inspect mode a visualization will pop up and add overlays on your cached parts. Cached parts are marked green, uncached red and dynamic caches are marked yellow. If you hover the loupe you will also see some meta data regarding the cache.

⚡️ Cache

This module will add a new modal including some statistics regarding cache hits and misses as well as a table of all rendered cache entries.

🗄 SQL

In addition to the content cache we're also exposing some debug SQL informations and statistics. It will also detect slow queries. You can configure from when a query should be marked as slow:

t3n:
  Neos:
    Debug:
      sql:
        # Set when a query should be considered as slow query. In ms
        slowQueryAfter: 10

🚫 Close

To shutdown the debug console simply close it. If you'd like to persist the active debug state you can add a true to the method

__enable_neos_debug__(true)

This will set a cookie and the debug mode will still be active after a page refresh.

neos-debug's People

Contributors

daniellienert avatar dependabot-preview[bot] avatar dependabot-support avatar johannessteu avatar jonnitto avatar mficzel avatar mwuest avatar sebobo avatar torsten85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neos-debug's Issues

Flush caches

Would be cool to flush single caches within the cache module

Support Neos 7

The two HTTP components need to be refactored to a middleware to further support Neos 7.
This means also a major release as it's not backward compatible.

See relative age of cache entry

Currently it's possible to see the createdDate as 09.09.2019 09:21:59, but it would be easier to check the age when inspecting many items if instead or additionally the output would show something like 10 minutes ago or similar.

Cookie “neos_debug” does not have a proper “SameSite” attribute value

Calling __enable_neos_debug__(true) leads to this:

Cookie “neos_debug” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite

Adding cache debug info to other formats as html

if ($htmlEndPosition === false) {
adds the debug info to formats that are not html.
This can currently not be turned off and causes issues when rendering files like robots.txt.
Of course in production the debugger is off and doesn't create the problem but having a broken robots.txt is still an issue when running local tests. This might affect other files which can also break the frontend.

Wouldn't it be better to disable it for non-html?

Caching information missing for uncached segments

Caching information is only collected when the entryIdentifier contains a "format = 'html'", uncached elements do not contain a 'format' in the entryIdentifier, this is only mandatory for 'cached' or 'dynamic'.

Offending lines:

// Add debug data only to html output
$segmentFormat = $info['entryIdentifier']['format'] ?? null;

if ($segmentFormat !== 'html') {
    return $segment;
}

See commit: b46cc51

Invalid return type in ContentCacheSegmentAspect

Currently there is an error in the ContentCacheSegmentAspect when a cached segment results in a non-string value (e.g. through being nulled by an @if expression):

Return value of t3n\Neos\Debug\Aspect\ContentCacheSegmentAspect_Original::renderCacheInfoIntoSegment() must be of the type string, null returned

As far as I can tell, this is due to the fact, that the renderCacheInfoIntoSegment method declares a non-nullable return type of string, but may return non-string values, as the $segment variable also might be of any type, just like stated in the belonging docblock:

/**
 * @param mixed $segment This is mixed as the RuntimeContentCache might also return none string values
 * @param mixed[] $info
 */
protected function renderCacheInfoIntoSegment($segment, array $info): string
{
    // ...
    // Add debug data only to html output
    $segmentFormat = $info['entryIdentifier']['format'] ?? null;

    if ($segmentFormat !== 'html') {
        return $segment;
    }

    // ...

Therefore, in case of any non-string value such as integers, objects or like in my initial case null, this throws the above error.
You can reproduce this behaviour with the following short fusion code i used for testing this bug:

prototype(Neos.Neos:Page) {
  body = Neos.Fusion:Value {
    value = ${null}
    //or: value = 25
    //or: value = ${node}

    @cache {
      mode = 'uncached'
      context {
        1 = 'node'
      }
    }
  }
}

The quickest solution I can think of would be to remove the return types alltogether as the return type can be nearly anything.
I am happy to create an appropriate merge request, provided there is no disagreement with my proposed solution.

BUG doesnt work in CLI context

round(): Argument #1 ($num) must be of type int|float, null given

  Type: TypeError
  File: Data/Temporary/Production/Cache/Code/Flow_Object_Classes/
        t3n_Neos_Debug_Aspect_CollectDebugInformationAspect.php
  Line: 95

but @Sebobo and me looked at the code and couldnt make sense of it why it can ever be null.

Instead we disabled the plugin in production mode ^^

(so this can be closed)

Compatibility with Neos 5.0

I really love this package! Thank you a lot for your awesome work. Unfortunately, it is not yet ready for Neos 5.0. Are there any plans?

Issues with Neos 3.3

Is this package supposed to work properly with Neos 3.3 / Php 7.2 ?
After requiring the package via composer, I get this error on cache warmup:

./flow flow:cache:warmup
The object "Doctrine\ORM\EntityManagerInterface" which was specified as a property in the object configuration of object "t3n\Neos\Debug\Aspect\CollectDebugInformationAspect" (automatically registered class) does not exist.
Check for spelling mistakes and if that dependency is correctly
configured.
...

By clicking through my installation I noticed that the mentioned class actually does exist, any idea what's happening here?

Refresh calculations on AJAX response

Analyzing content elements added on-the-fly via AJAX requests does not seem to be supported yet. Manually or automatically triggering a recalculation of the cache information would be great. Manual recalculation can currently be done by closing and reopening the debugging console, so the first and easiest function could be to add a refresh button to the console. Maybe there is also a nice solution for automatic recalculation?

Rewrite plugin frontend

It's getting harder and harder to extend the plugins frontend part.

As we anyway have to do some rewrites for the backend to support Neos 7
we might also switch to some lightweight frontend library to render
the debug interface.

I would like to try whether we could even use the Neos.Ui React components without
creating huge bundle and this way have a Neos theme.
But as the plugin is anyway only active in development, it shouldn't be a bis issue IMO.

Exception in ContentCacheSegmentAspect

Exception in line 92 of /data/Data/Temporary/Development/SubContextDocker/Cache/Code/Flow_Object_Classes/t3n_Neos_Debug_Aspect_ContentCacheSegmentAspect.php: Argument 1 passed to t3n\Neos\Debug\Aspect\ContentCacheSegmentAspect_Original::renderCacheInfoIntoSegment() must be of the type string, null given, called in /data/Data/Temporary/Development/SubContextDocker/Cache/Code/Flow_Object_Classes/t3n_Neos_Debug_Aspect_ContentCacheSegmentAspect.php on line 92

38 t3n\Neos\Debug\Aspect\ContentCacheSegmentAspect_Original::renderCacheInfoIntoSegment(NULL, array|5|)
37 t3n\Neos\Debug\Aspect\ContentCacheSegmentAspect_Original::wrapEvaluateUncached(Neos\Flow\Aop\JoinPoint)
36 Neos\Flow\Aop\Advice\AroundAdvice::invoke(Neos\Flow\Aop\JoinPoint)
35 Neos\Flow\Aop\Advice\AdviceChain::proceed(Neos\Flow\Aop\JoinPoint)
34 Neos\Fusion\Core\Cache\RuntimeContentCache::evaluateUncached("root<Neos.Fusion:Case>/default<Neos.Fusion:Matcher…ent>/body<Neos.Fusion:Template>/chooseCountryPopup", array|3|)
33 Neos\Fusion\Core\Cache\RuntimeContentCache_Original::Neos\Fusion\Core\Cache\{closure}("eval=root<Neos.Fusion:Case>/default<Neos.Fusion:Ma…ent>/body<Neos.Fusion:Template>/chooseCountryPopup", array|1|, Neos\Cache\Frontend\StringFrontend)
32 Neos\Fusion\Core\Cache\ContentCache_Original::Neos\Fusion\Core\Cache\{closure}(array|5|)
31 preg_replace_callback("/CONTENT_CACHE(?P<command>[^]+)CONTENT_CACHE(?P<data>[^]+)CONTENT_CACHE/", Closure, "HTTP/1.1 200 OK

<!DOCTYPE html>
<!--[if lt IE 8…ime":0,"created":"13.05.2019 08:07:18"} --></html>", -1, 6)
30 Neos\Fusion\Core\Cache\ContentCache_Original::replaceUncachedPlaceholders(Closure, "HTTP/1.1 200 OK

<!DOCTYPE html>
<!--[if lt IE 8…ime":0,"created":"13.05.2019 08:07:18"} --></html>")
29 Neos\Fusion\Core\Cache\ContentCache_Original::getCachedSegment(Closure, "root", array|13|, false, NULL)
28 Neos\Fusion\Core\Cache\ContentCache::getCachedSegment(Closure, "root", array|13|, false, NULL)
27 call_user_func_array(array|2|, array|5|)
26 Neos\Fusion\Core\Cache\ContentCache::Flow_Aop_Proxy_invokeJoinPoint(Neos\Flow\Aop\JoinPoint)
25 Neos\Fusion\Core\Cache\ContentCache::getCachedSegment(Closure, "root", array|13|, false, NULL)
24 call_user_func_array(array|2|, array|5|)
23 Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy::__call("getCachedSegment", array|5|)
22 Neos\Fusion\Core\Cache\RuntimeContentCache_Original::preEvaluate(array|6|, Neos\Fusion\FusionObjects\CaseImplementation)
21 Neos\Fusion\Core\Runtime_Original::evaluateObjectOrRetrieveFromCache(Neos\Fusion\FusionObjects\CaseImplementation, "root", array|16|, array|6|)
20 Neos\Fusion\Core\Runtime_Original::evaluateInternal("root", "Exception")
19 Neos\Fusion\Core\Runtime_Original::render("root")
18 Neos\Neos\View\FusionView_Original::render()
17 Neos\Neos\View\FusionView::render()
16 call_user_func_array(array|2|, array|0|)
15 Neos\Neos\View\FusionView::Flow_Aop_Proxy_invokeJoinPoint(Neos\Flow\Aop\JoinPoint)
14 Neos\Flow\Aop\Advice\AdviceChain::proceed(Neos\Flow\Aop\JoinPoint)
13 t3n\Neos\Debug\Aspect\CollectDebugInformationAspect_Original::addDebugValues(Neos\Flow\Aop\JoinPoint)
12 Neos\Flow\Aop\Advice\AroundAdvice::invoke(Neos\Flow\Aop\JoinPoint)
11 Neos\Flow\Aop\Advice\AdviceChain::proceed(Neos\Flow\Aop\JoinPoint)
10 Neos\Neos\View\FusionView::render()
9 Neos\Flow\Mvc\Controller\ActionController_Original::callActionMethod()
8 Neos\Flow\Mvc\Controller\ActionController_Original::processRequest(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
7 Neos\Flow\Mvc\Dispatcher_Original::initiateDispatchLoop(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
6 Neos\Flow\Mvc\Dispatcher_Original::dispatch(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
5 Neos\Flow\Mvc\DispatchComponent_Original::handle(Neos\Flow\Http\Component\ComponentContext)
4 Neos\Flow\Http\Component\ComponentChain_Original::handle(Neos\Flow\Http\Component\ComponentContext)
3 Neos\Flow\Http\Component\ComponentChain_Original::handle(Neos\Flow\Http\Component\ComponentContext)
2 Neos\Flow\Http\RequestHandler::handleRequest()
1 Neos\Flow\Core\Bootstrap::run()

Debug Exception in Flow CollectDebugInformationAspect

Hello,

I've found a bug where a value is not null checked, resulting in an exception.

Exception in line 35 of /app/Packages/Framework/Neos.Flow/Classes/Aop/Advice/AroundAdvice.php: Return value of t3n\Neos\Debug\Aspect\CollectDebugInformationAspect_Original::addDebugValues() must be of the type string, null returned

37 t3n\Neos\Debug\Aspect\CollectDebugInformationAspect_Original::addDebugValues(Neos\Flow\Aop\JoinPoint)
36 Neos\Flow\Aop\Advice\AroundAdvice::invoke(Neos\Flow\Aop\JoinPoint)
35 Neos\Flow\Aop\Advice\AdviceChain::proceed(Neos\Flow\Aop\JoinPoint)
34 Neos\Neos\View\FusionView::render()
33 Neos\Neos\Ui\Domain\Model\Feedback\Operations\ReloadContentOutOfBand_Original::renderContent(Neos\Flow\Mvc\Controller\ControllerContext)
32 Neos\Neos\Ui\Domain\Model\Feedback\Operations\ReloadContentOutOfBand_Original::serializePayload(Neos\Flow\Mvc\Controller\ControllerContext)
31 Neos\Neos\Ui\Domain\Model\AbstractFeedback::serialize(Neos\Flow\Mvc\Controller\ControllerContext)
30 Neos\Neos\Ui\Domain\Model\Feedback\Operations\ReloadContentOutOfBand_Original::serialize(Neos\Flow\Mvc\Controller\ControllerContext)
29 Neos\Neos\Ui\Domain\Model\FeedbackCollection_Original::jsonSerialize()

I think the issue is with the following line in the

app/Packages/Application/t3n.Neos.Debug/Classes/Aspect/CollectDebugInformationAspect.php

if ($htmlEndPosition === false) { return $output . $debugOutput; }

Neos Version: 4.3

t3n.Neos.Debug breaks Neos.Fusion:Http.ResponseHead

When t3n.Neos.Debug is enabled, any HTTP header set via Neos.Fusion:Http.ResponseHead won't get rendered.

I couldn't quite pinpoint what mechanism causes this, but I could verify that disabling t3n.Neos.Debug solves the issue.

To be more exact:

With t3n.Neos.Debug disabled, the Neos\Neos\Controller\Frontend\NodeController->showAction() receives a PSR-7-Response object from its fusion view containing all headers from Neos.Fusion:Http.ResponseHead.

With t3n.Neos.Debug enabled, Neos\Neos\Controller\Frontend\NodeController->showAction() receives a string instead, with all headers stripped.

Tasks before first release

  • General CSS/UI tweaks
  • Clenaup CSS
  • Cleanup JS
  • Add cicleci pipeline to ensure codestyle checks
  • Add cypress e2e tests to ensure the debug console is loaded etc
  • Update Readme
  • Add a better key visual in readme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.