Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Agent365Exporter implements SpanExporter {
const payload = this.buildExportRequest(spans);
const body = JSON.stringify(payload);

// Resolve endpoint + token
// Resolve endpoint + token based on cluster category (defaults to 'prod')
const discovery = new PowerPlatformApiDiscovery(this.clusterCategory);
const endpoint = discovery.getTenantIslandClusterEndpoint(tenantId);
const url = `https://${endpoint}/maven/agent365/agents/${agentId}/traces?api-version=1`;
Expand Down
131 changes: 59 additions & 72 deletions packages/agents-a365-runtime/src/environment-utils.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,59 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------------

/**
* Utility logic for environment-related operations.
*/

// Authentication scopes for different environments
export const TEST_OBSERVABILITY_SCOPE = 'https://api.test.powerplatform.com/.default';
export const PREPROD_OBSERVABILITY_SCOPE = 'https://api.preprod.powerplatform.com/.default';
export const PROD_OBSERVABILITY_SCOPE = 'https://api.powerplatform.com/.default';
export const PROD_MCP_PLATFORM_AUTHENTICATION_SCOPE = 'ea9ffc3e-8a23-4a7d-836d-234d7c7565c1/.default';

// Cluster categories for different environments
export const TEST_OBSERVABILITY_CLUSTER_CATEGORY = 'test';
export const PREPROD_OBSERVABILITY_CLUSTER_CATEGORY = 'preprod';
export const PROD_OBSERVABILITY_CLUSTER_CATEGORY = 'prod';

// Default environment names
export const PRODUCTION_ENVIRONMENT_NAME = 'production';
export const DEVELOPMENT_ENVIRONMENT_NAME = 'Development';

/**
* Returns the scope for authenticating to the observability service based on the current environment.
*
* @returns The authentication scope for the current environment.
*/
export function getObservabilityAuthenticationScope(): string[] {
const clusterCategory = getClusterCategory();

if (['local', 'dev', 'test', 'preprod'].includes(clusterCategory)) {
return [PREPROD_OBSERVABILITY_SCOPE];
} else {
// Default to production scope for 'prod' and any other values
return [PROD_OBSERVABILITY_SCOPE];
}
}

/**
* Gets the cluster category from environment variables.
*
* @returns The cluster category from CLUSTER_CATEGORY env var, defaults to 'prod'.
*/
export function getClusterCategory(): string {
const clusterCategory = process.env.CLUSTER_CATEGORY;

if (!clusterCategory) {
return 'prod';
}

return clusterCategory.toLowerCase();
}

/**
* Returns true if the current environment is a development environment.
*
* @returns True if the current environment is development, false otherwise.
*/
export function isDevelopmentEnvironment(): boolean {
const clusterCategory = getClusterCategory();
return ['local', 'dev'].includes(clusterCategory);
}

/**
* Gets the MCP platform authentication scope from environment variables.
*
* @returns The MCP platform authentication scope from MCP_PLATFORM_AUTHENTICATION_SCOPE env var, defaults to production scope.
*/
export function getMcpPlatformAuthenticationScope(): string {
return process.env.MCP_PLATFORM_AUTHENTICATION_SCOPE || PROD_MCP_PLATFORM_AUTHENTICATION_SCOPE;
}
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------------

/**
* Utility logic for environment-related operations.
*/

export const PROD_OBSERVABILITY_SCOPE = 'https://api.powerplatform.com/.default';
export const PROD_MCP_PLATFORM_AUTHENTICATION_SCOPE = 'ea9ffc3e-8a23-4a7d-836d-234d7c7565c1/.default';
export const PROD_OBSERVABILITY_CLUSTER_CATEGORY = 'prod';

// Default environment names
export const PRODUCTION_ENVIRONMENT_NAME = 'production';
export const DEVELOPMENT_ENVIRONMENT_NAME = 'Development';

/**
* Returns the scope for authenticating to the observability service
*
* @returns The authentication scope for the current environment.
Comment thread
fpfp100 marked this conversation as resolved.
*/
export function getObservabilityAuthenticationScope(): string[] {
// Always return production scope
return [PROD_OBSERVABILITY_SCOPE];
}

/**
* Gets the cluster category from environment variables.
*
* @returns The cluster category from CLUSTER_CATEGORY env var, defaults to 'prod'.
*/
export function getClusterCategory(): string {
const clusterCategory = process.env.CLUSTER_CATEGORY;

if (!clusterCategory) {
return 'prod';
}

return clusterCategory.toLowerCase();
}

/**
* Returns true if the current environment is a development environment.
*
* @returns True if the current environment is development, false otherwise.
*/
export function isDevelopmentEnvironment(): boolean {
const clusterCategory = getClusterCategory();
return ['local', 'dev'].includes(clusterCategory);
}

/**
* Gets the MCP platform authentication scope from environment variables.
*
* @returns The MCP platform authentication scope from MCP_PLATFORM_AUTHENTICATION_SCOPE env var, defaults to production scope.
*/
export function getMcpPlatformAuthenticationScope(): string {
return process.env.MCP_PLATFORM_AUTHENTICATION_SCOPE || PROD_MCP_PLATFORM_AUTHENTICATION_SCOPE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export class PowerPlatformApiDiscovery {
private _getEnvironmentApiHostNameSuffix(): string {
const apiHostNameSuffixMap: Readonly<Record<ClusterCategory, string>> = {
local: 'api.powerplatform.localhost',
dev: 'api.dev.powerplatform.com',
test: 'api.test.powerplatform.com',
preprod: 'api.preprod.powerplatform.com',
dev: 'api.powerplatform.com', //default to prod
Comment thread
fpfp100 marked this conversation as resolved.
test: 'api.powerplatform.com', //default to prod
Comment thread
fpfp100 marked this conversation as resolved.
preprod: 'api.powerplatform.com', //default to prod
Comment thread
fpfp100 marked this conversation as resolved.
firstrelease: 'api.powerplatform.com',
prod: 'api.powerplatform.com',
gov: 'api.gov.powerplatform.microsoft.us',
Expand Down
28 changes: 16 additions & 12 deletions tests/common/power-platform-api-discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ describe('getTokenAudience gets the correct token audiences for the environment'
expect(new PowerPlatformApiDiscovery('local').getTokenAudience()).toEqual(
'https://api.powerplatform.localhost'
);
// Non-production categories now default to production domain
expect(new PowerPlatformApiDiscovery('dev').getTokenAudience()).toEqual(
'https://api.dev.powerplatform.com'
'https://api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('test').getTokenAudience()).toEqual(
'https://api.test.powerplatform.com'
'https://api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('preprod').getTokenAudience()).toEqual(
'https://api.preprod.powerplatform.com'
'https://api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('firstrelease').getTokenAudience()).toEqual(
'https://api.powerplatform.com'
Expand Down Expand Up @@ -45,12 +46,13 @@ describe('getTokenEndpointHost gets the correct host for the environment', () =>
expect(new PowerPlatformApiDiscovery('local').getTokenEndpointHost()).toEqual(
'api.powerplatform.localhost'
);
expect(new PowerPlatformApiDiscovery('dev').getTokenEndpointHost()).toEqual('api.dev.powerplatform.com');
// Non-production categories now default to production domain
expect(new PowerPlatformApiDiscovery('dev').getTokenEndpointHost()).toEqual('api.powerplatform.com');
expect(new PowerPlatformApiDiscovery('test').getTokenEndpointHost()).toEqual(
'api.test.powerplatform.com'
'api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('preprod').getTokenEndpointHost()).toEqual(
'api.preprod.powerplatform.com'
'api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('firstrelease').getTokenEndpointHost()).toEqual(
'api.powerplatform.com'
Expand Down Expand Up @@ -80,14 +82,15 @@ describe('getTenantEndpoint generates the expected tenant endpoint', () => {
expect(new PowerPlatformApiDiscovery('local').getTenantEndpoint(tenantId)).toEqual(
'e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.localhost'
);
// Non-production categories now default to production domain
expect(new PowerPlatformApiDiscovery('dev').getTenantEndpoint(tenantId)).toEqual(
'e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.dev.powerplatform.com'
'e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('test').getTenantEndpoint(tenantId)).toEqual(
'e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.test.powerplatform.com'
'e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('preprod').getTenantEndpoint(tenantId)).toEqual(
'e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.preprod.powerplatform.com'
'e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('firstrelease').getTenantEndpoint(tenantId)).toEqual(
'e3064512cc6d4703be71a2ecaecaa9.8a.tenant.api.powerplatform.com'
Expand Down Expand Up @@ -142,14 +145,15 @@ describe('getTenantIslandClusterEndpoint generates the expected tenant island cl
expect(new PowerPlatformApiDiscovery('local').getTenantIslandClusterEndpoint(tenantId)).toEqual(
'il-e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.localhost'
);
// Non-production categories now default to production domain
expect(new PowerPlatformApiDiscovery('dev').getTenantIslandClusterEndpoint(tenantId)).toEqual(
'il-e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.dev.powerplatform.com'
'il-e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('test').getTenantIslandClusterEndpoint(tenantId)).toEqual(
'il-e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.test.powerplatform.com'
'il-e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('preprod').getTenantIslandClusterEndpoint(tenantId)).toEqual(
'il-e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.preprod.powerplatform.com'
'il-e3064512cc6d4703be71a2ecaecaa98.a.tenant.api.powerplatform.com'
);
expect(new PowerPlatformApiDiscovery('firstrelease').getTenantIslandClusterEndpoint(tenantId)).toEqual(
'il-e3064512cc6d4703be71a2ecaecaa9.8a.tenant.api.powerplatform.com'
Expand Down
Loading