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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ All notable changes to the Agent365 TypeScript SDK will be documented in this fi
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2025-12-08
## [1.1.0] - 2025-12-09

### Changed
- Remove ENABLE_A365_OBSERVABILITY or ENABLE_OBSERVABILITY. No longer need to use environment variable for recordAttributes, setTagMaybe, and addBaggage.
- Merged `EnhancedAgentDetails` into `AgentDetails` to unify agent detail typing across scopes and middleware.

### Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,14 @@ export class InvokeAgentScope extends OpenTelemetryScope {
* @param messages Array of input messages
*/
public recordInputMessages(messages: string[]): void {
if (InvokeAgentScope.enableTelemetry) {
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_INPUT_MESSAGES_KEY, messages.join(','));
}
}

/**
* Records the output messages for telemetry tracking.
* @param messages Array of output messages
*/
public recordOutputMessages(messages: string[]): void {
if (InvokeAgentScope.enableTelemetry) {
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_OUTPUT_MESSAGES_KEY, messages.join(','));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import { trace, SpanKind, Span, SpanStatusCode, Attributes, context } from '@opentelemetry/api';
import { OpenTelemetryConstants } from '../constants';
import { isAgent365TelemetryEnabled } from '../util';
import { AgentDetails, TenantDetails } from '../contracts';
import logger from '../../utils/logging';

Expand All @@ -16,9 +15,6 @@ export abstract class OpenTelemetryScope implements Disposable {

protected readonly span: Span;
private readonly startTime: number;

protected static enableTelemetry = isAgent365TelemetryEnabled();

private errorType?: string;
private exception?: Error;
private hasEnded = false;
Expand Down Expand Up @@ -85,31 +81,29 @@ export abstract class OpenTelemetryScope implements Disposable {
* @param error The error that occurred
*/
public recordError(error: Error): void {
if (OpenTelemetryScope.enableTelemetry) {
logger.error(`[A365Observability] Records an error that occurred during the operation span[${this.span.spanContext().spanId}]: ${error.message}`);
// Check if it's an HTTP error with status code
if ('status' in error && typeof error.status === 'number') {
this.errorType = error.status.toString();
} else {
this.errorType = error.constructor.name;
}
logger.error(`[A365Observability] Records an error that occurred during the operation span[${this.span.spanContext().spanId}]: ${error.message}`);
// Check if it's an HTTP error with status code
if ('status' in error && typeof error.status === 'number') {
this.errorType = error.status.toString();
} else {
this.errorType = error.constructor.name;
}

this.exception = error;
this.span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message
});
this.exception = error;
this.span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message
});

this.span.recordException(error);
}
this.span.recordException(error);
}

/**
* Records multiple attribute key/value pairs for telemetry tracking.
* @param attributes Collection of attribute key/value pairs (array or iterable of [key, value] or object map).
*/
public recordAttributes(attributes: Iterable<[string, any]> | Record<string, any> | null | undefined): void {
if (!OpenTelemetryScope.enableTelemetry || !attributes) return;
if (!attributes) return;
// Support both array/iterable of pairs and object maps
if (Array.isArray(attributes)) {
for (const [key, value] of attributes as Array<[string, any]>) {
Expand Down Expand Up @@ -141,7 +135,7 @@ export abstract class OpenTelemetryScope implements Disposable {
* @param value The tag value
*/
protected setTagMaybe<T extends string | number | boolean>(name: string, value: T | null | undefined): void {
if (OpenTelemetryScope.enableTelemetry && value != null) {
if (value != null) {
this.span.setAttributes({ [name]: value as string | number | boolean });
}
}
Expand All @@ -152,11 +146,9 @@ export abstract class OpenTelemetryScope implements Disposable {
* @param value The baggage value
*/
protected addBaggage(key: string, value: string): void {
if (OpenTelemetryScope.enableTelemetry) {
// Note: OpenTelemetry JS doesn't have direct baggage API in span
// This would typically be handled through the baggage API
this.span.setAttributes({ [`baggage.${key}`]: value });
}
// Note: OpenTelemetry JS doesn't have direct baggage API in span
// This would typically be handled through the baggage API
this.span.setAttributes({ [`baggage.${key}`]: value });
}

/**
Expand Down
15 changes: 0 additions & 15 deletions packages/agents-a365-observability/src/tracing/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,6 @@ export const isAgent365ExporterEnabled: () => boolean = (): boolean => {
);
};

/**
* Gets the enable telemetry configuration value
*/
export const isAgent365TelemetryEnabled: () => boolean = (): boolean => {
const enableObservability = process.env[OpenTelemetryConstants.ENABLE_OBSERVABILITY]?.toLowerCase();
const enableA365 = process.env[OpenTelemetryConstants.ENABLE_A365_OBSERVABILITY]?.toLowerCase();

return (
enableObservability === 'true' ||
enableObservability === '1' ||
enableA365 === 'true' ||
enableA365 === '1'
);
};

/**
* Single toggle to use custom domain for observability export.
* When true exporter will send traces to custom Agent365 service endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import { InvokeAgentScopeUtils } from '@microsoft/agents-a365-observability-host
import { InvokeAgentScope, OpenTelemetryScope, OpenTelemetryConstants } from '@microsoft/agents-a365-observability';

describe('InvokeAgentScopeUtils', () => {
beforeAll(() => {
// Also force static field in case module was already loaded
(OpenTelemetryScope as any).enableTelemetry = true;
});
afterAll(() => {
delete process.env[OpenTelemetryConstants.ENABLE_OBSERVABILITY];
(OpenTelemetryScope as any).enableTelemetry = false;
});
const mockTurnContext = {
activity: {
from: { id: 'user1', name: 'User One', agenticUserId: 'agentic-user-1', tenantId: 'tenant1', aadObjectId: 'aad-object-1', agenticAppBlueprintId: 'blueprint-123', role: 'user' },
Expand Down