Skip to content

Commit de42bd0

Browse files
committed
Log install per OS stats
1 parent 9332684 commit de42bd0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Controller/ApiController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ public function trackDownloadsAction(Request $request, StatsDClient $statsd, str
311311
$statsd->increment('installs.php_patch', 1, 1, [
312312
'php_patch' => $uaParser->getPhpVersion() ?: 'unknown',
313313
]);
314+
$statsd->increment('installs.os', 1, 1, [
315+
'os' => $uaParser->getOs() ?: 'unknown',
316+
'php_minor' => $uaParser->getPhpMinorVersion(),
317+
'ci' => $uaParser->getCI() ? 'true' : 'false',
318+
]);
314319
} elseif (
315320
// log only if user-agent header is well-formed (it sometimes contains the header name itself in the value)
316321
!str_starts_with($request->headers->get('User-Agent'), 'User-Agent:')

src/Util/UserAgentParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UserAgentParser
2525

2626
public function __construct(?string $userAgent)
2727
{
28-
if ($userAgent && Preg::isMatch('#^Composer/(?P<composer>[a-z0-9.+-]+) \((?P<os>[^\s;]+)[^;]*?; [^;]*?; (?P<engine>HHVM|PHP) (?P<php>[0-9.]+)[^;]*(?:; (?P<http>streams|curl \d+\.\d+)[^;)]*)?(?:; Platform-PHP (?P<platform_php>[0-9.]+)[^;]*)?(?P<ci>; CI)?#i', $userAgent, $matches)) {
28+
if ($userAgent && Preg::isMatch('#^Composer/(?P<composer>[a-z0-9.+-]+) \((?P<os>[^\s;]+)[^;]*?; (?P<osversion>[^;]*?); (?P<engine>HHVM|PHP) (?P<php>[0-9.]+)[^;]*(?:; (?P<http>streams|curl \d+\.\d+)[^;)]*)?(?:; Platform-PHP (?P<platform_php>[0-9.]+)[^;]*)?(?P<ci>; CI)?#i', $userAgent, $matches)) {
2929
assert(isset($matches['composer'], $matches['engine'], $matches['os'], $matches['php']));
3030
if ($matches['composer'] === 'source' || Preg::isMatch('{^[a-f0-9]{40}$}', $matches['composer'])) {
3131
$matches['composer'] = 'pre-1.8.5';
@@ -34,6 +34,11 @@ public function __construct(?string $userAgent)
3434
$this->phpVersion = (strtolower($matches['engine']) === 'hhvm' ? 'hhvm-' : '') . $matches['php'];
3535
$this->platformPhpVersion = null !== $matches['platform_php'] ? (strtolower($matches['engine']) === 'hhvm' ? 'hhvm-' : '') . $matches['platform_php'] : null;
3636
$this->os = Preg::replace('{^cygwin_nt-.*}', 'cygwin', strtolower($matches['os']));
37+
if (str_contains('microsoft', strtolower((string) $matches['osversion']))) { // likely WSL 1 e.g. version-Microsoft
38+
$this->os = 'wsl';
39+
} elseif (str_contains('WSL', (string) $matches['osversion'])) { // likely WSL2 e.g. version-microsoft-standard-WSL2
40+
$this->os = 'wsl';
41+
}
3742
$this->httpVersion = null !== $matches['http'] ? strtolower($matches['http']) : null;
3843
$this->ci = (bool) ($matches['ci'] ?? null);
3944
}

0 commit comments

Comments
 (0)