fix(injector): resolve .AST.Fun.Name crash on SelectorExpr in wrap-expression templates#819
Merged
Merged
Conversation
…pression templates
When a function-call join-point matches a qualified call like http.Get(...),
the Fun field of the *dst.CallExpr is a *dst.SelectorExpr. Templates accessing
{{ .AST.Fun.Name }} crashed with "can't evaluate field Name in type dst.Expr"
because proxySelectorExpr had no Name field or method.
Add a Name() string method to proxySelectorExpr returning Sel.Name. This makes
{{ .AST.Fun.Name }} work transparently for both *dst.Ident (promoted field from
embedded *dst.Ident) and *dst.SelectorExpr (new method returning Sel.Name).
No dd-trace-go changes required — the existing template just starts working.
Constraint: Must not introduce new template API surface (no FuncName() helper)
that would force dd-trace-go to depend on a minimum orchestrion version
Rejected: Add FuncName() helper | breaks backwards compatibility between
dd-trace-go and orchestrion versions
Confidence: high
Scope-risk: narrow
|
🎯 Code Coverage (details) 🔗 Commit SHA: fa2c920 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
eliottness
commented
Apr 10, 2026
Co-authored-by: Eliott Bouhana <47679741+eliottness@users.noreply.github.com>
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #819 +/- ##
==========================================
+ Coverage 65.72% 69.66% +3.94%
==========================================
Files 113 117 +4
Lines 7926 6902 -1024
==========================================
- Hits 5209 4808 -401
+ Misses 2192 1545 -647
- Partials 525 549 +24
🚀 New features to boost your workflow:
|
RomainMuller
approved these changes
Apr 13, 2026
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.
What does this PR do?
Fixes a build crash (
can't evaluate field Name in type dst.Expr) that occurs when afunction-calljoin-point matches a qualified call likehttp.Get(...)and the advice template accesses{{ .AST.Fun.Name }}.Root cause:
proxyCallExpr.Fun()returnsdst.Expr(interface). When the underlying node is a*dst.SelectorExpr(e.g., forhttp.Get),proxySelectorExprhad noNamefield or method. Go'stext/templatecould not resolve.Name, crashing with the error above. The same template works fine for bare/dot-imported calls (Get(...)) whereFunis a*dst.Identwith a promotedNamefield.Fix: Add a
Name() stringmethod toproxySelectorExprin a hand-written companion file (dot_ast_extras.go) that returnsSel.Name. This makes{{ .AST.Fun.Name }}work transparently for both node types without any changes to dd-trace-go templates — fully backwards compatible.Motivation
Customer escalation APMS-19232: any user calling
http.Get(...),http.Head(...),http.Post(...), orhttp.PostForm(...)in a function with acontext.Contextparameter fails to build with orchestrion. The dd-trace-gonet/httpclient aspect (Get|Head|Post|PostForm) triggers the crash.Describe how you validated your changes
selector-expr-fun-name/that exercises exactly the failure path: afunction-calljoin-point onnet/http.Getwith input code that has acontext.Contextparameter, forcing the template branch that evaluates{{ .AST.Fun.Name }}on a*dst.SelectorExprgo test ./internal/injector/...(14 packages, 51s)golangci-lintcleanAdditional Notes
The fix lives in
dot_ast_extras.go, a hand-written companion to the auto-generateddot_ast.proxies.go. This separation keeps generated code untouched while allowing targeted extensions. A comment in the new file guides future maintainers to add similar extensions there.The alternative (adding a new
FuncName()template helper) was rejected because it would require dd-trace-go to depend on a minimum orchestrion version, breaking backwards compatibility.