Skip to content

adding agent tracing#38363

Draft
M-Hietala wants to merge 2 commits intomainfrom
m-hietala/adding_agent_tracing
Draft

adding agent tracing#38363
M-Hietala wants to merge 2 commits intomainfrom
m-hietala/adding_agent_tracing

Conversation

@M-Hietala
Copy link
Copy Markdown
Member

adding agent tracing

openaiClient.responses.create = ((...args: Parameters<typeof responsesCreate>) => {
const [body, options = {}] = args;
const nextBody = { ...body, ...(options.body || {}) };
const nextBody = { ...body, ...((options.body as Record<string, unknown>) || {}) };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems do not need this change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast is needed because options is inferred as unknown from the overloaded function signature. Without it, the browser build fails with TS2698: Spread types may only be created from object types.

return openaiClient;
}

function setCommonSpanAttributes(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move these util function to other files.

export async function _createDeserialize(result: PathUncheckedResponse): Promise<Agent> {
const expectedStatuses = ["200"];
if (!expectedStatuses.includes(result.status)) {
console.error("[DEBUG] agents.create failed with status:", result.status, "body:", JSON.stringify(result.body));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use @azure/logger for this

* Enable GenAI tracing for Azure AI Projects agent operations
* and response generation.
*/
export function enableGenAITracing(): void {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This system of enabling/disabling genAI tracing should not be needed or used. Our core-tracing implementation already no-ops by default and is safe to call. The end-user will enable OTel based tracing by configuring https://www.npmjs.com/package/@azure/opentelemetry-instrumentation-azure-sdk prior to loading @azure/ai-projects

By adding another flag we are duplicating what is already configurable at the Azure SDK level and adding another concept for users to learn and understand. There are also nuances to setting an in-memory value (side-by-side versioning, CJS/ESM compatibility, etc).

So the TL;DR is:

  • Use coreTracing.createTracingClient to create a properly configured tracing client (no-op by default, enabled if the user enables OTel tracing)
  • Wrap calls to be traced with tracingClient.withSpan
    • Access the inner span as needed to add custom attributes inside the callback, you are already doing this
    • Remove everything in this file and any conditionals based on these checks
    • You can wrap calls with tracingClient.withSpan, they are not expensive or harmful, and do nothing unless the user configured OTel instrumentation

As far as the environment variables, we do not use custom environment variables or introduce new environment variables unless absolutely necessary. We should have a discussion about what your needs are here and how we can best configure them.

Feel free to ping me with any questions!

*/
export function isContentRecordingEnabled(): boolean {
try {
return process.env.OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT === "true";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are tracing spans the right place for message content? Ideally we'd want to be careful with user provided content. We can use the Azure Logger at verbose level or I would think we can omit it entirely. The user can still create their own spans and capture the agent output as needed before/after calling into our SDK but maybe I missed a non-presumptive feature ask here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants