Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VIP_GO_APP_ID to telemetry event data #5922

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
11 changes: 6 additions & 5 deletions telemetry/tracks/class-tracks-event-dto.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
namespace Automattic\VIP\Telemetry\Tracks;

use AllowDynamicProperties;
use stdClass;
use WP_Error;
use Automattic\VIP\Support_User\User as Support_User;
use function Automattic\VIP\Logstash\log2logstash;

/**
* Class that holds necessary properties of Tracks events.
Expand All @@ -37,9 +33,14 @@ class Tracks_Event_DTO {
/** @var string */
public string $_via_ip; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

/** @var string VIP environment */
public string $vipgo_env;

public int $vipgo_org;
/** @var int VIP organization ID (from VIP_ORG_ID) */
public int $vip_org_id;

/** @var int VIP environment ID (also referenced as VIP_GO_APP_ID) */
public int $vip_env_id;

public bool $is_vip_user = false;
}
11 changes: 10 additions & 1 deletion telemetry/tracks/class-tracks-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,20 @@ protected function process_properties(
}
}

// Set VIP environment ID if it exists.
if ( defined( 'VIP_GO_APP_ID' ) ) {
// APP_ID is incorrectly named; it actually references the environment ID
$env_id = constant( 'VIP_GO_APP_ID' );
if ( is_integer( $env_id ) && $env_id > 0 ) {
$event->vip_env_id = $env_id;
}
}

// Set VIP organization if it exists.
if ( defined( 'VIP_ORG_ID' ) ) {
$org_id = constant( 'VIP_ORG_ID' );
if ( is_integer( $org_id ) && $org_id > 0 ) {
$event->vipgo_org = $org_id;
$event->vip_org_id = $org_id;
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/telemetry/tracks/test-class-tracks-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Tracks_Event_Test extends WP_UnitTestCase {

protected const VIP_ORG_ID = 17;

protected const VIP_GO_APP_ID = 2000;

private WP_User $user;

public function setUp(): void {
Expand All @@ -40,6 +42,7 @@ public function test_should_create_event() {
public function test_should_return_event_data() {
Constant_Mocker::define( 'VIP_TELEMETRY_SALT', self::VIP_TELEMETRY_SALT );
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', self::VIP_GO_APP_ENVIRONMENT );
Constant_Mocker::define( 'VIP_GO_APP_ID', self::VIP_GO_APP_ID );
Constant_Mocker::define( 'VIP_ORG_ID', self::VIP_ORG_ID );

$event = new Tracks_Event( 'prefix_', 'test_event', [
Expand All @@ -60,7 +63,8 @@ public function test_should_return_event_data() {
$this->assertSame( hash_hmac( 'sha256', $this->user->user_email, self::VIP_TELEMETRY_SALT ), $event->get_data()->_ui );
$this->assertSame( 'vip:user_email', $event->get_data()->_ut );
$this->assertSame( self::VIP_GO_APP_ENVIRONMENT, $event->get_data()->vipgo_env );
$this->assertSame( self::VIP_ORG_ID, $event->get_data()->vipgo_org );
$this->assertSame( self::VIP_GO_APP_ID, $event->get_data()->vip_env_id );
$this->assertSame( self::VIP_ORG_ID, $event->get_data()->vip_org_id );
$this->assertFalse( $event->get_data()->is_vip_user );
$this->assertTrue( $event->is_recordable() );
}
Expand Down
Loading