[azsdk-cli] Add telemetry to sample translation#14271
Conversation
…count) Co-authored-by: deyaaeldeen <6074665+deyaaeldeen@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds missing telemetry-related fields to the SampleTranslatorTool response so sample translation operations provide the same observability signals as sample generation.
Changes:
- Extends
TranslateSamplesInternalAsyncto return the targetPackageInfoand passes it intoPackageOperationResponse.CreateSuccess(...)so package metadata is populated on success responses. - Populates
response.Resultwithsamples_countto align with theSampleGeneratorToolresponse shape. - Adds a unit test ensuring
Language,PackageName,PackageType,Version, andsamples_countare present on a successful translation response.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Package/Samples/SampleTranslatorTool.cs | Includes target package metadata in success responses and adds samples_count into the result payload. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/Package/Samples/SampleTranslatorToolTests.cs | Adds coverage to verify the response carries the expected telemetry-relevant fields. |
| var response = result.TranslatedCount == 0 | ||
| ? PackageOperationResponse.CreateSuccess( | ||
| $"No samples found to translate from {result.SourceLanguage}.", | ||
| nextSteps: ["Verify the source package has sample files", "Check the samples directory exists"]); | ||
| } | ||
|
|
||
| return PackageOperationResponse.CreateSuccess( | ||
| $"Successfully translated {result.TranslatedCount} sample(s) from {result.SourceLanguage} to {result.TargetLanguage}: {result.FileNames}", | ||
| nextSteps: ["Review the translated samples", "Test the samples to ensure they compile and run correctly"]); | ||
| packageInfo: result.PackageInfo, | ||
| nextSteps: ["Verify the source package has sample files", "Check the samples directory exists"]) | ||
| : PackageOperationResponse.CreateSuccess( | ||
| $"Successfully translated {result.TranslatedCount} sample(s) from {result.SourceLanguage} to {result.TargetLanguage}: {result.FileNames}", | ||
| packageInfo: result.PackageInfo, | ||
| nextSteps: ["Review the translated samples", "Test the samples to ensure they compile and run correctly"]); |
There was a problem hiding this comment.
The success message for the TranslatedCount == 0 path always says "No samples found to translate", but TranslateSamplesInternalAsync can also return 0 when samples exist but none were written (e.g., Copilot returns an empty list, or all outputs already exist and overwrite is false). This can mislead users; consider returning additional state from TranslateSamplesInternalAsync (e.g., discovered count / skipped-existing count) or adjusting the message to reflect "no samples translated/written" rather than "no samples found".
| // Set samples_count for telemetry tracking (including 0 for failed translations) | ||
| response.Result = new { samples_count = result.TranslatedCount }; |
There was a problem hiding this comment.
The comment says samples_count is set "including 0 for failed translations", but this assignment only happens on the success path (after TranslateSamplesInternalAsync returns). Failures returned from the validation/exception handlers won't include samples_count. Please update the comment (or set samples_count in failure responses as well if that’s required).
SampleTranslatorToolwas missing the telemetry instrumentation already present inSampleGeneratorTool— no package info or sample count was captured for observability.Changes
SampleTranslatorToolTranslateSamplesInternalAsyncreturn tuple to includePackageInfo(target package)packageInfotoCreateSuccesssolanguage,package_name,version, andpackage_typeare promoted to telemetry tags viaTelemetryProcessorresponse.Result = new { samples_count = result.TranslatedCount }matching theSampleGeneratorToolconventionSampleTranslatorToolTestsTranslateSamples_PopulatesTelemetryFieldstest verifyingLanguage,PackageName,PackageType,Version, andsamples_countare all correctly populated on a successful translation responseOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.