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 @@ -77,12 +77,12 @@ export function getTargetAgentBaggagePairs(turnContext: TurnContext): Array<[str
const agentId = recipient.agenticAppId;
const agentName = recipient.name;
const aadObjectId = recipient.aadObjectId;
const agentDescription = recipient.role;
const agentDescription = recipient.role;
const pairs: Array<[string, string | undefined]> = [
[OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY, agentId],
[OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY, agentName],
[OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY, agentDescription],
[OpenTelemetryConstants.GEN_AI_AGENT_AUID_KEY, aadObjectId],
[OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY, agentDescription]
];
return normalizePairs(pairs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class OpenTelemetryConstants {

public static readonly GEN_AI_AGENT_ID_KEY = 'gen_ai.agent.id';
public static readonly GEN_AI_AGENT_NAME_KEY = 'gen_ai.agent.name';
public static readonly GEN_AI_AGENT_TYPE_KEY = 'gen_ai.agent.type';
public static readonly GEN_AI_AGENT_DESCRIPTION_KEY = 'gen_ai.agent.description';
public static readonly GEN_AI_AGENT_PLATFORM_ID_KEY = 'gen_ai.agent.platformid';
public static readonly GEN_AI_CONVERSATION_ID_KEY = 'gen_ai.conversation.id';
Expand Down
3 changes: 3 additions & 0 deletions packages/agents-a365-observability/src/tracing/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export interface AgentDetails {
/** The human-readable name of the AI agent */
agentName?: string;

/** Optional type of the AI agent */
agentType?: string;

/** A description of the AI agent's purpose or capabilities */
agentDescription?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ export class BaggageBuilder {
return this;
}

/**
* Set the agent type baggage value.
* @param value The agent type
* @returns Self for method chaining
*/
agentType(value: string | null | undefined): BaggageBuilder {
this.set(OpenTelemetryConstants.GEN_AI_AGENT_TYPE_KEY, value);
return this;
}

/**
* Set the agent description baggage value.
* @param value The agent description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const GENERIC_ATTRIBUTES: readonly string[] = [
consts.GEN_AI_OPERATION_NAME_KEY,
consts.GEN_AI_AGENT_ID_KEY,
consts.GEN_AI_AGENT_NAME_KEY,
consts.GEN_AI_AGENT_TYPE_KEY,
consts.GEN_AI_AGENT_DESCRIPTION_KEY,
consts.SESSION_DESCRIPTION_KEY,
consts.GEN_AI_AGENT_USER_ID_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export abstract class OpenTelemetryScope implements Disposable {
if (agentDetails) {
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY, agentDetails.agentId);
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY, agentDetails.agentName);
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_AGENT_TYPE_KEY, agentDetails.agentType);
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY, agentDetails.agentDescription);
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_AGENT_PLATFORM_ID_KEY, agentDetails.platformId);
this.setTagMaybe(OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, agentDetails.conversationId);
Expand Down
12 changes: 12 additions & 0 deletions tests/observability/core/BaggageBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('BaggageBuilder', () => {
.agentId('agent-456')
.correlationId('corr-789')
.agentName('TestAgent')
.agentType('assistant')
.agentPlatformId('platform-xyz-123')
.conversationId('conv-001');

Expand All @@ -57,6 +58,17 @@ describe('BaggageBuilder', () => {
expect(bag?.getEntry(OpenTelemetryConstants.GEN_AI_AGENT_PLATFORM_ID_KEY)?.value).toBe('platform-abc-456');
});

it('should set agent type', () => {
const builder = new BaggageBuilder();
builder.agentType('assistant');

const scope = builder.build();
expect(scope).toBeInstanceOf(BaggageScope);

const bag = propagation.getBaggage((scope as any).contextWithBaggage);
expect(bag?.getEntry(OpenTelemetryConstants.GEN_AI_AGENT_TYPE_KEY)?.value).toBe('assistant');
});

it('should set caller agent platform ID via fluent API', () => {
const builder = new BaggageBuilder();
builder.callerAgentPlatformId('caller-platform-xyz');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('BaggageBuilderUtils', () => {
expect(asObj[OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY]).toBe('agent-app-1');
expect(asObj[OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY]).toBe('Agent One');
expect(asObj[OpenTelemetryConstants.GEN_AI_AGENT_AUID_KEY]).toBe('aad-object-2');
expect(asObj[OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY]).toBe('agent');
expect(asObj[OpenTelemetryConstants.GEN_AI_AGENT_BLUEPRINT_ID_KEY]).toBe('blueprint-123');
expect(asObj[OpenTelemetryConstants.GEN_AI_AGENT_UPN_KEY]).toBe(undefined);
expect(asObj[OpenTelemetryConstants.TENANT_ID_KEY]).toBe('tenant1');
Expand Down
12 changes: 6 additions & 6 deletions tests/observability/extension/hosting/scope-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ function makeTurnContext(

describe('ScopeUtils.populateFromTurnContext', () => {
let spy: jest.SpyInstance;
beforeEach(() => {
beforeEach(() => {
spy = jest.spyOn(OpenTelemetryScope.prototype as any, 'setTagMaybe');
});

afterEach(() => {
spy.mockRestore();
});

test('build InferenceScope based on turn context', () => {
test('build InferenceScope based on turn context', () => {
const details = { operationName: 'inference', model: 'gpt-4o', providerName: 'openai' } as any;
const ctx = makeTurnContext('input text', 'web', 'https://web', 'conv-A');
const scope = ScopeUtils.populateInferenceScopeFromTurnContext(details, ctx) as InferenceScope;
Expand All @@ -64,8 +64,8 @@ describe('ScopeUtils.populateFromTurnContext', () => {
[OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, 'conv-A'],
[OpenTelemetryConstants.GEN_AI_EXECUTION_SOURCE_NAME_KEY, 'web'],
[OpenTelemetryConstants.GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY, 'https://web'],
[OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY, 'Agent One'],
[OpenTelemetryConstants.GEN_AI_AGENT_AUID_KEY, 'agent-oid'],
[OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY, 'Agent One'],
[OpenTelemetryConstants.GEN_AI_AGENT_AUID_KEY, 'agent-oid'],
[OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY, 'agent-1'],
[OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY, 'assistant'],
[OpenTelemetryConstants.TENANT_ID_KEY, 'tenant-123'],
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('ScopeUtils.populateFromTurnContext', () => {
});
});

test('build InvokeAgentScope based on turn context', () => {
test('build InvokeAgentScope based on turn context', () => {
const details = { operationName: 'invoke', model: 'n/a', providerName: 'internal' } as any;
const ctx = makeTurnContext('invoke message', 'teams', 'https://teams', 'conv-B');
ctx.activity.from!.role = RoleTypes.AgenticUser;
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('ScopeUtils.populateFromTurnContext', () => {
[OpenTelemetryConstants.TENANT_ID_KEY, 'tenant-123']
])
);
scope?.dispose();
scope?.dispose();
});
});

Expand Down