-
Notifications
You must be signed in to change notification settings - Fork 5k
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
M-Hietala
wants to merge
2
commits into
main
Choose a base branch
from
m-hietala/adding_function_tracing_utility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
adding function tracer #50990
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
|
@@ -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 are 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 are is a sample sync function that we want to trace: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
```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: | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:".
Copilot uses AI. Check for mistakes.