Skip to content

Remove use of html/template for DebugReports#118

Merged
rosstimothy merged 7 commits into
masterfrom
tross/dead_code
Apr 6, 2026
Merged

Remove use of html/template for DebugReports#118
rosstimothy merged 7 commits into
masterfrom
tross/dead_code

Conversation

@rosstimothy
Copy link
Copy Markdown
Contributor

Leveraging templates prevents dead code elimination for consumers of the trace library. The old method for generating the debug reports has been moved into trace_test.go and exposed via OldDebugReport functions so that the new handrolled reports can be validated against the templated version.

Leveraging templates prevents dead code elimination for consumers
of the trace library. The old method for generating the debug
reports has been moved into trace_test.go and exposed via OldDebugReport
functions so that the new handrolled reports can be validated against
the templated version.
@rosstimothy rosstimothy marked this pull request as ready for review February 26, 2026 01:44
zmb3
zmb3 previously approved these changes Feb 27, 2026
Comment thread trace.go
Comment thread trace.go Outdated
Comment thread trace_test.go

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.Equal(t, OldProxyErrorDebugReport(test.err), test.err.DebugReport())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture the output of the old functions and ditch them? I don't see much reason to keep all of that around, after this change lands this is it anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this but thought it would be better to leave the old behavior around to validate any future changes or corner cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move the old funcs to their own file, then? trace_olddebug_test.go?

Comment thread trace.go
@rosstimothy rosstimothy requested a review from codingllama March 30, 2026 13:28
codingllama
codingllama previously approved these changes Mar 30, 2026
@rosstimothy rosstimothy requested review from Copilot, espadolini and zmb3 and removed request for zmb3 March 30, 2026 14:14
Comment thread trace.go
Comment on lines +582 to +588
sb.WriteString("User Message: ")
sb.WriteString(html.EscapeString(wrappedErr.UserMessage()))
sb.WriteRune('\n')
} else {
sb.WriteString("User Message: ")
sb.WriteString(html.EscapeString(wrappedErr.UserMessage()))
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way the (lack of) trailing newline depending on Caught is relevant, right? Surely that's just an artifact of how we wrote reportTemplateText, and we can do the same thing in both cases here instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 I was trying to limit the behavioral changes to a minimum here.

Comment thread trace.go Outdated
Comment thread trace.go Outdated
Comment thread trace.go Outdated
Comment thread trace.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes the dependency on html/template from DebugReport generation to allow dead code elimination for downstream consumers, while keeping output parity validated via tests.

Changes:

  • Replaced templated DebugReport rendering with hand-rolled string building (with HTML escaping) for TraceErr and proxyError.
  • Moved the legacy template-based DebugReport generation into tests and added parity tests comparing old vs new outputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
trace.go Swaps template-based debug report formatting for manual formatting + escaping and removes html/template dependency.
trace_test.go Reintroduces the old template logic in tests only and adds golden/parity tests to ensure identical output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread trace_test.go
Comment thread trace.go Outdated
Inline the html strings.Replacer for more efficient debug reports.
This was validated by adding BenchmarkDebugReport. There is still
more room for improvement in the DebugReport implementations but
any further improvements are for a follow up change.

```
benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: github.com/gravitational/trace
cpu: Apple M2 Pro
               │   old.txt   │              new.txt              │
               │   sec/op    │   sec/op     vs base              │
DebugReport-12   22.53µ ± 3%   21.49µ ± 3%  -4.61% (p=0.001 n=10)

               │   old.txt    │               new.txt               │
               │     B/op     │     B/op      vs base               │
DebugReport-12   2.312Ki ± 0%   1.888Ki ± 0%  -18.37% (p=0.000 n=10)

               │  old.txt   │              new.txt              │
               │ allocs/op  │ allocs/op   vs base               │
DebugReport-12   38.00 ± 0%   29.00 ± 0%  -23.68% (p=0.000 n=10)
```
espadolini
espadolini previously approved these changes Apr 6, 2026
Comment thread trace.go Outdated
codingllama
codingllama previously approved these changes Apr 6, 2026
@rosstimothy rosstimothy dismissed stale reviews from codingllama and espadolini via 67510d9 April 6, 2026 13:54
@rosstimothy
Copy link
Copy Markdown
Contributor Author

@espadolini @codingllama pinging again for review. This repo appears to be configured to dismiss approvals for any changes made.

@rosstimothy rosstimothy merged commit a23ff52 into master Apr 6, 2026
5 checks passed
@espadolini espadolini deleted the tross/dead_code branch April 7, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants