Skip to content

Commit

Permalink
Track environment provider in telemetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed May 23, 2024
1 parent 50fdfff commit ad852ff
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Helpers/TelemetryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private function getTelemetryUserData(): array {
'ah_non_production' => getenv('AH_NON_PRODUCTION'),
'ah_realm' => getenv('AH_REALM'),
'CI' => getenv('CI'),
'env_provider' => $this->getEnvironmentProvider(),

Check warning on line 123 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L123

Added line #L123 was not covered by tests
'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION,
];
try {
Expand All @@ -134,6 +135,41 @@ private function getTelemetryUserData(): array {
return $data;
}

private function getEnvironmentProvider(): ?string {

Check warning on line 138 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L138

Added line #L138 was not covered by tests
// Define the environment variables associated with each provider.
$providers = [

Check warning on line 140 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L140

Added line #L140 was not covered by tests
// Assuming Acquia has a specific environment variable, just for example purposes.
'acquia' => ['ACQUIA_ENVIRONMENT'],
'bamboo' => ['BAMBOO_BUILDNUMBER'],
'bitbucket' => ['BITBUCKET_BRANCH'],
'circleci' => ['CIRCLECI'],
'codebuild' => ['CODEBUILD_BUILD_ID'],
'drone' => ['DRONE'],
'github' => ['GITHUB_ACTIONS'],
'gitlab' => ['GITLAB_CI'],
'heroku' => ['HEROKU_TEST_RUN_ID'],
'jenkins' => ['JENKINS_URL'],
'octopus' => ['OCTOPUS_DEPLOYMENT_ID'],
'teamcity' => ['TEAMCITY_VERSION'],
'travis' => ['TRAVIS'],
];

Check warning on line 155 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L142-L155

Added lines #L142 - L155 were not covered by tests

// Check for an Acquia environment first as it uses a method call rather than getenv.
if (AcquiaDrupalEnvironmentDetector::getAhEnv()) {
return 'acquia';

Check warning on line 159 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L158-L159

Added lines #L158 - L159 were not covered by tests
}

// Check for CI/CD environment variables.
foreach ($providers as $provider => $vars) {
foreach ($vars as $var) {
if (getenv($var) !== FALSE)
return $provider;

Check warning on line 166 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L163-L166

Added lines #L163 - L166 were not covered by tests
}
}

return NULL;

Check warning on line 170 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L170

Added line #L170 was not covered by tests
}

private function getUserId(): ?string {
$user = $this->getUserData();
if ($user && isset($user['uuid'])) {
Expand Down

0 comments on commit ad852ff

Please sign in to comment.