-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Added support for Trace name truncation for traces #3689
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
Conversation
timoreimann
left a comment
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.
As discussed on Slack, we decided to introduce an option that allows users to define the span name length threshold, with the default being that no truncation happens. We also need this to ensure that we don't break existing clients.
The outlined behavior isn't reflected in the PR yet, or is it?
|
@timoreimann You are right, changed the default to be no truncation. |
mmatur
left a comment
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.
Thanks for your contribution @aantono.
First quick review
middlewares/tracing/entrypoint.go
Outdated
| opNameFunc := func(r *http.Request) string { | ||
| return fmt.Sprintf("Entrypoint %s %s", e.entryPoint, r.Host) | ||
| } | ||
| //opNameFunc := func(r *http.Request) string { |
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.
Could you remove these comments please
| package tracing | ||
|
|
||
| import ( | ||
| "github.com/opentracing/opentracing-go/ext" |
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.
Please sort your imports
| r *http.Request | ||
| next http.HandlerFunc | ||
| } | ||
| tests := []struct { |
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.
Could you please rename tests into testCases
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.desc, func(t *testing.T) { | ||
| defaultMockSpan.Reset() |
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.
Could you please run in parallel
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.
Those are run serial on purpose, as the Mock tracer is static and otherwise would be having race conditions.
| }, | ||
| }, | ||
| } | ||
| for _, tt := range tests { |
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.
Could you please rename tt in test
middlewares/tracing/tracing_test.go
Outdated
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.desc, func(t *testing.T) { | ||
| if got := ComputeHash(tt.text); got != tt.want { |
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.
Could you please run your test in parallel
middlewares/tracing/tracing_test.go
Outdated
| want: "f9b0078b", | ||
| }, | ||
| } | ||
| for _, tt := range tests { |
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.
Could you please add a new line before
middlewares/tracing/tracing_test.go
Outdated
| want: "some-service-100.slug.namespace.envi...", | ||
| }, | ||
| } | ||
| for _, tt := range tests { |
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.
Could you please add a new line before
middlewares/tracing/tracing_test.go
Outdated
| want: "some-service-100.slug.namespace.envi...", | ||
| }, | ||
| } | ||
| for _, tt := range tests { |
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.
Could you please rename tt into test
middlewares/tracing/tracing_test.go
Outdated
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.desc, func(t *testing.T) { | ||
| if got := TruncateString(tt.text, tt.limit); got != tt.want || len(got) > tt.limit { |
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.
Could you please run testCases in parallel
mmatur
left a comment
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.
mmatur
left a comment
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.
LGTM :)
Great PR @aantono :)
juliens
left a comment
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.
LGTM
dtomcej
left a comment
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.
HASH ALL THE THINGS
LGTM
![]()
|
Rebased against latest v1.7 |
timoreimann
left a comment
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.
Left some comments.
Shouldn't we need to update some documentation as well?
middlewares/tracing/entrypoint.go
Outdated
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.
Grammar: then -> than
middlewares/tracing/tracing.go
Outdated
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.
My brain mistook the - in Trace name - 8 for a minus shortly due to the other arithmetic operator (+) used here. Can we use a colon (:) instead?
middlewares/tracing/tracing.go
Outdated
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.
Colon here too please.
middlewares/tracing/entrypoint.go
Outdated
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.
Can we please add a GoDoc to the function explaining what it does, along with an example?
Please include why we do + 3 when we hit the spanLimit < EntryPointMaxLengthNumber case.
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.
I'd put this test case first: reading it first helps to understand the other cases.
middlewares/tracing/tracing.go
Outdated
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.
Trailing punctuation missing.
middlewares/tracing/tracing.go
Outdated
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.
The function does not need to be exported, does it?
middlewares/tracing/tracing.go
Outdated
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.
Trailing punctuation missing.
middlewares/tracing/tracing.go
Outdated
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.
Can be merged with previous line:
if err := has.Write(data); err != nil {
middlewares/tracing/tracing_test.go
Outdated
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.
Please put this test case first.
middlewares/tracing/entrypoint.go
Outdated
| span.Finish() | ||
| } | ||
|
|
||
| // generateEntryPointSpanName will return a Span name of an appropriate lenth based on the 'spanLimit' argument. If needed, it will be truncated, but will not be less than 24 characters |
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.
Trailing punctuation missing.
middlewares/tracing/forwarder.go
Outdated
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.
👍
middlewares/tracing/tracing.go
Outdated
| LogEventf(r, format, args...) | ||
| } | ||
|
|
||
| // TruncateString reduces the length of the 'str' argument to 'num' - 3 and adds a '...' suffix to the tail. |
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.
Unexport?
middlewares/tracing/forwarder.go
Outdated
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.
Gotcha, fine with me. 👍
| # | ||
| serviceName = "traefik" | ||
|
|
||
| # Span name limit allows for name truncation in case of very long Frontend/Backend names |
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.
Can we append something like
"This can prevent certain tracing providers from dropping such traces."
?
Similar below.
timoreimann
left a comment
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.

What does this PR do?
In many situations the trace name gets pretty large (over 100 chars, especially when using k8s provider). This provides an option to truncate the name to a configurable length to avoid dropped traces.
More