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
2 changes: 1 addition & 1 deletion src/a365/exporter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const MESSAGE_ROLE_SYSTEM = "system";
* Known genAI operation names produced by the SDK scopes and auto-instrumentation.
* Only spans whose gen_ai.operation.name matches one of these values are exported.
*/
const GEN_AI_OPERATION_NAMES: ReadonlySet<string> = new Set([
export const GEN_AI_OPERATION_NAMES: ReadonlySet<string> = new Set([
GEN_AI_OPERATION_INVOKE_AGENT, // 'invoke_agent'
GEN_AI_OPERATION_EXECUTE_TOOL, // 'execute_tool'
GEN_AI_OPERATION_OUTPUT_MESSAGES, // 'output_messages'
Expand Down
21 changes: 15 additions & 6 deletions src/a365/processors/A365SpanProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
ReadableSpan,
} from "@opentelemetry/sdk-trace-base";
import { OpenTelemetryConstants } from "../constants.js";
import { GEN_AI_OPERATION_NAMES } from "../exporter/utils.js";
import { GENERIC_ATTRIBUTES, INVOKE_AGENT_ATTRIBUTES } from "./util.js";

/**
Expand All @@ -31,6 +32,9 @@ export class A365SpanProcessor implements BaseSpanProcessor {
/**
* Called when a span is started.
* Copies relevant baggage entries to span attributes.
* Only GenAI spans are processed (those with a known `gen_ai.operation.name`
* span attribute: invoke_agent, execute_tool, chat, output_messages);
* all other spans pass through unmodified.
*/
onStart(span: Span, parentContext?: Context): void {
const ctx = parentContext;
Expand All @@ -56,6 +60,16 @@ export class A365SpanProcessor implements BaseSpanProcessor {
return;
}

// Only process GenAI spans — those with a known gen_ai.operation.name
// span attribute (invoke_agent, execute_tool, chat, output_messages).
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const operationNameAttr = (span as any).attributes?.[
OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY
];
if (!GEN_AI_OPERATION_NAMES.has(operationNameAttr)) {
return;
}

const baggageMap = new Map<string, string>();
baggage.getAllEntries().forEach(([key, entry]) => {
if (entry.value) {
Expand All @@ -64,15 +78,10 @@ export class A365SpanProcessor implements BaseSpanProcessor {
});

// Determine if this is an invoke_agent operation
const operationName =
baggageMap.get(OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY) ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(span as any).attributes?.[OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const spanName = (span as any).name || "";
const isInvokeAgent =
operationName === OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME ||
operationNameAttr === OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME ||
spanName.startsWith(OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME);

// Build target key set
Expand Down
Loading
Loading