-
Notifications
You must be signed in to change notification settings - Fork 893
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
Add tracing logs for Nexus HTTP request retries #7186
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5aad8c
Add tracing logs for Nexus HTTP request retries
pdoerner b0fa52d
refactor
pdoerner 803532d
Merge branch 'main' into nexus-http-tracing
pdoerner 3379de1
make dc global
pdoerner 39f910d
fx
pdoerner 5edc08b
lint
pdoerner 689f86c
handle nil provider
pdoerner f13064f
dynamic config cleanup
pdoerner abf9183
Merge branch 'main' into nexus-http-tracing
pdoerner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2025 Temporal Technologies Inc. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package nexus | ||
|
||
import ( | ||
"crypto/tls" | ||
"net/http/httptrace" | ||
"time" | ||
|
||
"go.temporal.io/server/common/log" | ||
"go.temporal.io/server/common/log/tag" | ||
) | ||
|
||
// NewHTTPClientTrace returns a *httptrace.ClientTrace which adds additional logging information at each point in the | ||
// HTTP request lifecycle. This trace must be added to the HTTP request context using httptrace.WithClientTrace for | ||
// the logging hooks to be invoked. The provided logger should already be tagged with relevant request information | ||
// e.g. using log.With(logger, tag.RequestID(id), tag.Operation(op), ...). | ||
func NewHTTPClientTrace(logger log.Logger) *httptrace.ClientTrace { | ||
logger.Info("starting trace for Nexus HTTP request") | ||
return &httptrace.ClientTrace{ | ||
GetConn: func(hostPort string) { | ||
logger.Info("attempting to get HTTP connection for Nexus request", | ||
tag.Timestamp(time.Now().UTC()), | ||
tag.Address(hostPort)) | ||
}, | ||
GotConn: func(info httptrace.GotConnInfo) { | ||
logger.Info("got HTTP connection for Nexus request", | ||
tag.Timestamp(time.Now().UTC()), | ||
tag.NewBoolTag("reused", info.Reused), | ||
tag.NewBoolTag("was-idle", info.WasIdle), | ||
tag.NewDurationTag("idle-time", info.IdleTime)) | ||
}, | ||
ConnectStart: func(network, addr string) { | ||
logger.Info("starting dial for new connection for Nexus request", | ||
tag.Timestamp(time.Now().UTC()), | ||
tag.Address(addr), | ||
tag.NewStringTag("network", network)) | ||
}, | ||
ConnectDone: func(network, addr string, err error) { | ||
logger.Info("finished dial for new connection for Nexus request", | ||
tag.Timestamp(time.Now().UTC()), | ||
tag.Address(addr), | ||
tag.NewStringTag("network", network), | ||
tag.Error(err)) | ||
}, | ||
DNSStart: func(info httptrace.DNSStartInfo) { | ||
logger.Info("starting DNS lookup for Nexus request", | ||
tag.Timestamp(time.Now().UTC()), | ||
tag.Host(info.Host)) | ||
}, | ||
DNSDone: func(info httptrace.DNSDoneInfo) { | ||
addresses := make([]string, len(info.Addrs)) | ||
for i, a := range info.Addrs { | ||
addresses[i] = a.String() | ||
} | ||
logger.Info("finished DNS lookup for Nexus request", | ||
tag.Timestamp(time.Now().UTC()), | ||
tag.Addresses(addresses), | ||
tag.Error(info.Err), | ||
tag.NewBoolTag("coalesced", info.Coalesced)) | ||
}, | ||
TLSHandshakeStart: func() { | ||
logger.Info("starting TLS handshake for Nexus request", tag.Timestamp(time.Now().UTC())) | ||
}, | ||
TLSHandshakeDone: func(state tls.ConnectionState, err error) { | ||
logger.Info("finished TLS handshake for Nexus request", | ||
tag.Timestamp(time.Now().UTC()), | ||
// TODO: consider other state info | ||
tag.NewBoolTag("handshake-complete", state.HandshakeComplete), | ||
tag.Error(err)) | ||
}, | ||
WroteRequest: func(info httptrace.WroteRequestInfo) { | ||
logger.Info("finished writing Nexus HTTP request", | ||
tag.Timestamp(time.Now().UTC()), | ||
tag.Error(info.Err)) | ||
}, | ||
GotFirstResponseByte: func() { | ||
logger.Info("got response to Nexus HTTP request", tag.AttemptEnd(time.Now().UTC())) | ||
}, | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
This should be disabled by default. Generally, I don't think the attempt number matters here, it's more about what to trace IMHO. E.g. whether
TLSHandshakeStart
should be traced or not. Ideally the config would be for a set of methods, but It'd be hard to express in dynamic config as a set without adding a lot of overhead. We could probably provide a config per method we support intercepting though.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 think attempt count is useful for limiting the overhead and the overall log spam. Without a notion of attempt count do you imagine we would log trace info for every retry?
Instead of adding a dynamic config per-hook, we could just use fx to provide the
httptrace.ClientTrace
. Then anyone who wants to change the behavior could do so with fx.replaceThere 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.
Discussed offline, agree that adding the counts is nice, also requested that we add the dynamic config and make it global so it can be efficiently cached (a limitation of the current DC implementation).