the browser-facing portion of osu!
at master 1.6 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Http\Middleware; 7 8use ChaseConey\LaravelDatadogHelper\Middleware\LaravelDatadogMiddleware; 9use Datadog; 10use Symfony\Component\HttpFoundation\Request; 11use Symfony\Component\HttpFoundation\Response; 12 13class DatadogMetrics extends LaravelDatadogMiddleware 14{ 15 /** 16 * Logs the duration of a specific request through the application 17 * 18 * @param Request $request 19 * @param Response $response 20 * @param float $startTime 21 */ 22 protected static function logDuration(Request $request, Response $response, $startTime) 23 { 24 static $hostname; 25 if (!isset($hostname)) { 26 $hostname = gethostname(); 27 if (!is_string($hostname)) { 28 $hostname = 'unknown'; 29 } 30 } 31 32 $duration = microtime(true) - $startTime; 33 $tags = [ 34 'action' => 'error_page', 35 'api' => is_api_request() ? 'true' : 'false', 36 'controller' => 'error', 37 'namespace' => 'error', 38 'pod_name' => $hostname, 39 'section' => 'error', 40 'status_code' => $response->getStatusCode(), 41 'status_code_extra' => $request->attributes->get('status_code_extra'), 42 ]; 43 44 $tags = array_merge($tags, app('route-section')->getOriginal()); 45 46 Datadog::timing($GLOBALS['cfg']['datadog-helper']['prefix_web'].'.request_time', $duration, 1, $tags); 47 } 48}