Problem/Motivation
I turned on the cache_metrics module locally with the New Relic agent on and piping into a trial account. I hit the following error right away on any page of the site:
The website encountered an unexpected error. Please try again later. Error: Call to a member function getBaseUrl() on null in Drupal\cache_metrics\CacheBackendWrapper->get() (line 77 of modules/contrib/cache_metrics/src/CacheBackendWrapper.php). Drupal\cache_metrics\CacheBackendWrapper->get('http://bravo.local/:', ) (Line: 306) Drupal\page_cache\StackMiddleware\PageCache->get(Object) (Line: 124) Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Seems like when the page cache bin is checked, it's too early in the request for the global request object to be on the stack, so $request here is NULL: https://git.drupalcode.org/project/cache_metrics/blob/8.x-1.x/src/CacheB...
Proposed resolution
I worked around this temporarily by blacklisting the page cache bin. However thats a bin I'd be really interested in monitoring metrics for.
Ideas:
- Pass a NULL URL. For
pagecache bin, this seems odd, although$cidis also the page URL - Use
$_SERVER['REQUEST_URI'] - Something else?
Remaining tasks
- Agree on approach
- Fix
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | call_to_getbaseurl_on_null-3113208-2.patch | 1.82 KB | m4olivei |
Comments
Comment #2
m4oliveiHere is a patch for the NULL approach, which at least quels the errors.
Comment #3
moshe weitzman commentedLGTM. My site uses Varnish without page cache so I missed this.
Comment #5
m4oliveiThanks! I was wondering about that. That totally makes sense.
Committed to 8.x-1.x.