@@ -6,9 +6,28 @@ import (
66)
77
88// Client implement Diagnostic IPC Protocol client.
9- // https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md#CollectStreaming
9+ // https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md
1010type Client struct {
1111 addr string
12+ dial Dialer
13+ }
14+
15+ // Dialer establishes connection to the given address. Due to the potential for
16+ // an optional continuation in the Diagnostics IPC Protocol, each successful
17+ // connection between the runtime and a Diagnostic Port is only usable once.
18+ //
19+ // Note that the dialer is OS-specific, refer to documentation for details:
20+ // https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md#transport
21+ type Dialer func (addr string ) (net.Conn , error )
22+
23+ // Option overrides default Client parameters.
24+ type Option func (* Client )
25+
26+ // WithDialer overrides default dialer function with d.
27+ func WithDialer (d Dialer ) Option {
28+ return func (c * Client ) {
29+ c .dial = d
30+ }
1231}
1332
1433// Session represents EventPipe stream of NetTrace data created with
@@ -44,16 +63,23 @@ type CollectTracingConfig struct {
4463//
4564// Refer to documentation for details:
4665// https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md#transport
47- func NewClient (addr string ) * Client {
48- return & Client {addr : addr }
66+ func NewClient (addr string , options ... Option ) * Client {
67+ c := & Client {addr : addr }
68+ for _ , option := range options {
69+ option (c )
70+ }
71+ if c .dial == nil {
72+ c .dial = DefaultDialer ()
73+ }
74+ return c
4975}
5076
5177// CollectTracing creates a new EventPipe session stream of NetTrace data.
5278func (c * Client ) CollectTracing (config CollectTracingConfig ) (s * Session , err error ) {
5379 // Every session has its own IPC connection which cannot be reused for any
5480 // other purposes; in order to close the connection another connection
5581 // to be opened - see `StopTracing`.
56- conn , err := dial (c .addr )
82+ conn , err := c . dial (c .addr )
5783 if err != nil {
5884 return nil , err
5985 }
@@ -89,7 +115,7 @@ func (c *Client) CollectTracing(config CollectTracingConfig) (s *Session, err er
89115
90116// StopTracing stops the given streaming session started with CollectTracing.
91117func (c * Client ) StopTracing (sessionID uint64 ) error {
92- conn , err := dial (c .addr )
118+ conn , err := c . dial (c .addr )
93119 if err != nil {
94120 return err
95121 }
0 commit comments