Skip to content

Log remote/local endpoint details - #742

Merged
rhysparry merged 1 commit into
mainfrom
rhys/lev-983/log-net-details
Nov 22, 2026
Merged

rhysparry merged 1 commit into
mainfrom
rhys/lev-983/log-net-details

Conversation

@rhysparry

@rhysparry rhysparry commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Background

When diagnosing connectivity problems from Tentacle logs, we can see which remote address a connection went to (or came from), but never which local address and port were used. On hosts with multiple interfaces, or behind NAT, knowing the local side of the socket makes it much easier to match a connection up with firewall, load balancer or packet capture logs.

Halibut already logs the remote endpoint in a few places:

  • Outbound (polling) connections: Connection established to {remote} for {uri} (Trace) and Secure connection established. Server at {remote} identified by thumbprint: ... (Info)
  • Inbound (listening) connections: Accepted TCP client: {remote} / Accepted Web Socket client: {remote} (Info)

None of these include the local endpoint. For listening connections, the log context is the listener's bound address (for example listen://0.0.0.0:10933), which doesn't tell you which interface actually accepted the connection.

Results

Adds the local endpoint to the existing connection log messages:

  • TcpClientExtensions: new GetLocalEndpointString(), mirroring the existing GetRemoteEndpointString() (returns <none>/<error> rather than throwing).
  • TcpConnectionFactory:
    • Connection established to {remote} from {local} for {uri}
    • Secure connection established. Server at {remote} identified by thumbprint: {thumbprint}, using protocol {protocol}, from local endpoint {local}
    • Both now use the safe extension methods rather than reading client.Client.RemoteEndPoint directly.
  • SecureListener: Accepted TCP client: {remote} on local endpoint {local}
  • SecureWebSocketListener: Accepted Web Socket client: {remote} on local endpoint {local}

No log levels change, so the Info-level messages above will appear in Tentacle's log file at its default log level.

Notes:

  • When a polling connection goes through a proxy, the "remote" endpoint is the proxy, as before.
  • Outbound WebSocket polling connections aren't covered, because ClientWebSocket doesn't expose the local endpoint.

Part of LEV-983 (Tentacle will pick this up via a Halibut version bump, alongside adding the timezone offset to Tentacle's log timestamps).

Before

Accepted TCP client: 10.0.0.5:51234
Secure connection established. Server at 10.0.0.5:10943 identified by thumbprint: ABC123..., using protocol Tls12

After

Accepted TCP client: 10.0.0.5:51234 on local endpoint 10.0.0.20:10933
Secure connection established. Server at 10.0.0.5:10943 identified by thumbprint: ABC123..., using protocol Tls12, from local endpoint 10.0.0.20:49876

(Illustrative addresses, showing the message shapes.)

How to review this PR

Quality ✔️

Small, log-message-only change. Nothing in Halibut or Tentacle matches on these message strings.

Pre-requisites

  • I have read How we use GitHub Issues for help deciding when and where it's appropriate to make an issue.
  • I have considered informing or consulting the right people, according to the ownership map.
  • I have considered appropriate testing for my change.

🤖 Generated with Claude Code

🤖 Agent's description, endorsed by Rhys

@rhysparry
rhysparry marked this pull request as ready for review November 20, 2026 01:20
@rhysparry
rhysparry requested a review from a team as a code owner November 20, 2026 01:20
{
return client?.Client.LocalEndPoint?.ToString() ?? "<none>";
}
catch

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.

I wonder why this would ever throw?

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 don't think it can. It's following the pattern from GetRemoteEndpointString() below.

@rhysparry
rhysparry merged commit caaa23b into main Nov 22, 2026
13 checks passed
@rhysparry
rhysparry deleted the rhys/lev-983/log-net-details branch November 22, 2026 22:29
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.

2 participants