[csharp][generichost] Change logging category and add EventId#24274
Open
devhl-labs wants to merge 3 commits into
Open
[csharp][generichost] Change logging category and add EventId#24274devhl-labs wants to merge 3 commits into
devhl-labs wants to merge 3 commits into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please merge this first: #24273
Problem
Generated C# generichost clients had two observability issues:
In generated
ApiResponseclasses,ILogger<T>should always point to the owning API type. If the category drifts, filtering and correlation drift with it.The logger category matters because logging providers route and filter by category. If the wrong type ends up in
ILogger<T>, logs from the response path appear under a different category than the rest of the API, breaking dashboard grouping, sink routing, and structured queries.The category should be the API class, not the response class. Users think in terms of API operations, not response wrapper types. Setting
"PetApi": "Debug"inappsettings.jsonto capture all traffic from that surface is intuitive. Hunting for generated response type names is not. The log events — request completed, failed, deserialization error — are semantically owned by the API call, not the response object that carries the result.Event IDs give each log path a stable machine-readable identity, so alerts and queries remain reliable even when message text changes.
Solution
The template now stabilizes classname reuse in the duplicated-operation block before logger declarations are emitted.
The bin/configs/csharp-generichost-latest-tags.yaml sample exposed an edge case: when an operation is duplicated across multiple API classes, Mustache context at the point of logger declaration resolves to the wrong classname. Three small keyed text cache/recall lambdas (
lambda.cache,lambda.recall,lambda.recallOnce) were added purely to work around this, keeping classname resolution deterministic in that case.Result
Generated generichost response classes now consistently use the intended API logger category. Log events carry stable event IDs, making them reliable targets for alerts, queries, and dashboards regardless of future message text changes.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.