Skip to content

adding function tracer #50990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

M-Hietala
Copy link
Contributor

adding function tracer

@Copilot Copilot AI review requested due to automatic review settings July 1, 2025 16:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new FunctionTracer feature that captures and exports function call telemetry via OpenTelemetry, complete with sample code, utilities, tests, and documentation updates.

  • Introduces the FunctionTracer class in Telemetry/FunctionTracer.cs for automatic parameter and return-value tracing.
  • Adds test utilities (MemoryTraceExporter, GenAiTraceVerifier) and extensive FunctionTracerTests.
  • Updates project files for telemetry dependencies and expands the README with telemetry samples.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/ai/Azure.AI.Projects/tests/Utilities/MemoryTraceExporter.cs In-memory exporter for capturing Activity objects in tests
sdk/ai/Azure.AI.Projects/tests/Utilities/GenAITraceVerifier.cs Utility to verify span attributes and events in tests
sdk/ai/Azure.AI.Projects/tests/Samples/Telemetry/Sample_Telemetry_FunctionTracer.cs Sample code showing FunctionTracer usage for sync/async functions
sdk/ai/Azure.AI.Projects/tests/FunctionTracerTests.cs Comprehensive tests covering various tracing scenarios
sdk/ai/Azure.AI.Projects/tests/Azure.AI.Projects.Tests.csproj Adds telemetry exporter package references
sdk/ai/Azure.AI.Projects/src/Telemetry/FunctionTracer.cs Core implementation of the FunctionTracer API
sdk/ai/Azure.AI.Projects/src/Azure.AI.Projects.csproj Registers the Telemetry folder in the main project
sdk/ai/Azure.AI.Projects/README.md Inserts a Telemetry section with sample snippets
Comments suppressed due to low confidence (1)

sdk/ai/Azure.AI.Projects/tests/FunctionTracerTests.cs:153

  • The test calls _exporter.ForceFlush(), but MemoryTraceExporter does not implement ForceFlush. You should call _tracerProvider.ForceFlush() (or the tracer provider's flush) to ensure spans are exported.
        _exporter.ForceFlush();

using OpenTelemetry;
using OpenTelemetry.Trace;
using System.Diagnostics;
using Moq;
Copy link
Preview

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

Remove the unused using Moq; directive, as this file does not reference Moq.

Suggested change
using Moq;

Copilot uses AI. Check for mistakes.

A helper class is provided to trace your own functions. The trace functions in the class will log function parameters and the return value for supported types.
Note that this helper class will log the parameters and return value always when tracing is enabled, so be mindful with sensitive data.

Here are is a sample async function that we want to trace:
Copy link
Preview

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

Correct the grammar here to "Here is a sample async function that we want to trace:".

Suggested change
Here are is a sample async function that we want to trace:
Here is a sample async function that we want to trace:

Copilot uses AI. Check for mistakes.

}
```

Here are is a sample sync function that we want to trace:
Copy link
Preview

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

Correct the grammar here to "Here is a sample sync function that we want to trace:".

Suggested change
Here are is a sample sync function that we want to trace:
Here is a sample sync function that we want to trace:

Copilot uses AI. Check for mistakes.

Copy link

github-actions bot commented Jul 1, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

Azure.AI.Projects

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

Successfully merging this pull request may close these issues.

3 participants