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
Open
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
46 changes: 46 additions & 0 deletions sdk/ai/Azure.AI.Projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ See [full set of Agents samples](https://github.com/Azure/azure-sdk-for-net/tree
- [Connections operations](#connections-operations)
- [Dataset operations](#dataset-operations)
- [Indexes operations](#indexes-operations)
- [Telemetry](#telemetry)
- [Trace your own functions](#trace-your-own-functions)
- [Troubleshooting](#troubleshooting)
- [Next steps](#next-steps)
- [Contributing](#contributing)
Expand Down Expand Up @@ -360,6 +362,50 @@ Console.WriteLine("Delete the Index version created above:");
indexesClient.Delete(name: indexName, version: indexVersion);
```

## Telemetry

### Trace your own functions

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 is a sample async function that we want to trace:
```C# Snippet:AI_Projects_TelemetryAsyncFunctionExample
// Simple async function to trace
public static async Task<string> ProcessOrderAsync(string orderId, int quantity, decimal price)
{
await Task.Delay(100); // Simulate async work
var total = quantity * price;
return $"Order {orderId}: {quantity} items, Total: ${total:F2}";
}
```

You can trace async functions like this:
```C# Snippet:AI_Projects_TelemetryTraceFunctionExampleAsync
using (tracerProvider)
{
var asyncResult = await FunctionTracer.TraceAsync(() => ProcessOrderAsync("ORD-456", 3, 15.50m));
}
```

Here is a sample sync function that we want to trace:
```C# Snippet:AI_Projects_TelemetrySyncFunctionExample
// Simple sync function to trace
public static string ProcessOrder(string orderId, int quantity, decimal price)
{
var total = quantity * price;
return $"Order {orderId}: {quantity} items, Total: ${total:F2}";
}
```

Sync functions can be traced like this:
```C# Snippet:AI_Projects_TelemetryTraceFunctionExampleSync
using (tracerProvider)
{
var syncResult = FunctionTracer.Trace(() => ProcessOrder("ORD-123", 5, 29.99m));
}
```

## Troubleshooting

Any operation that fails will throw a [RequestFailedException][RequestFailedException]. The exception's `code` will hold the HTTP response status code. The exception's `message` contains a detailed message that may be helpful in diagnosing the issue:
Expand Down
4 changes: 4 additions & 0 deletions sdk/ai/Azure.AI.Projects/src/Azure.AI.Projects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@
<ItemGroup>
<None Include="..\tsp-location.yaml" Link="tsp-location.yaml" />
</ItemGroup>

<ItemGroup>
<Folder Include="Telemetry\" />
</ItemGroup>
</Project>
Loading
Loading