Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -73,8 +73,7 @@ export class ObservabilityBuilder {
throw new Error('tokenResolver must be provided when Agent 365 exporter is enabled');
}
return new Agent365Exporter(
this.options.tokenResolver,
this.options.clusterCategory || 'prod'
this.options.tokenResolver
);
} else {
return new ConsoleSpanExporter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExportResult,ExportResultCode } from '@opentelemetry/core';
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';

import { PowerPlatformApiDiscovery, ClusterCategory } from '@microsoft/agents-a365-runtime';
import { PowerPlatformApiDiscovery } from '@microsoft/agents-a365-runtime';
import { partitionByIdentity, parseIdentityKey, hexTraceId, hexSpanId, kindName, statusName } from './utils';
import logger, {formatError} from '../../utils/logging';

Expand Down Expand Up @@ -72,19 +72,16 @@ export type TokenResolver = (agentId: string, tenantId: string) => string | null
*/
export class Agent365Exporter implements SpanExporter {
private readonly tokenResolver: TokenResolver;
private readonly clusterCategory: ClusterCategory;
private closed = false;

constructor(
tokenResolver: TokenResolver,
clusterCategory: ClusterCategory = 'prod'
) {
if (!tokenResolver) {
logger.error('[Agent365Exporter] token_resolver is not provided');
throw new Error('token_resolver must be provided.');
}
this.tokenResolver = tokenResolver;
this.clusterCategory = clusterCategory;
}

/**
Expand Down Expand Up @@ -139,8 +136,8 @@ export class Agent365Exporter implements SpanExporter {
const payload = this.buildExportRequest(spans);
const body = JSON.stringify(payload);

// Resolve endpoint + token
const discovery = new PowerPlatformApiDiscovery(this.clusterCategory);
// Resolve endpoint + token (hardcoded to production cluster 'prod')
const discovery = new PowerPlatformApiDiscovery('prod');
const endpoint = discovery.getTenantIslandClusterEndpoint(tenantId);
const url = `https://${endpoint}/maven/agent365/agents/${agentId}/traces?api-version=1`;
logger.info(`[Agent365Exporter] Resolved endpoint: ${endpoint}`);
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;
}
Loading