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 page cache bin, this seems odd, although $cid is also the page URL
  • Use $_SERVER['REQUEST_URI']
  • Something else?

Remaining tasks

  • Agree on approach
  • Fix

Comments

m4olivei created an issue. See original summary.

m4olivei’s picture

Status: Active » Needs review
StatusFileSize
new1.82 KB

Here is a patch for the NULL approach, which at least quels the errors.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

LGTM. My site uses Varnish without page cache so I missed this.

  • m4olivei committed 278bd5a on 8.x-1.x
    Issue #3113208 by m4olivei, moshe weitzman: Error: Call to a member...
m4olivei’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! I was wondering about that. That totally makes sense.

Committed to 8.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.