Source file src/internal/nettrace/nettrace.go

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package nettrace contains internal hooks for tracing activity in
     6  // the net package. This package is purely internal for use by the
     7  // net/http/httptrace package and has no stable API exposed to end
     8  // users.
     9  package nettrace
    10  
    11  // TraceKey is a context.Context Value key. Its associated value should
    12  // be a *Trace struct.
    13  type TraceKey struct{}
    14  
    15  // LookupIPAltResolverKey is a context.Context Value key used by tests to
    16  // specify an alternate resolver func.
    17  // It is not exposed to outsider users. (But see issue 12503)
    18  // The value should be the same type as lookupIP:
    19  //     func lookupIP(ctx context.Context, host string) ([]IPAddr, error)
    20  type LookupIPAltResolverKey struct{}
    21  
    22  // Trace contains a set of hooks for tracing events within
    23  // the net package. Any specific hook may be nil.
    24  type Trace struct {
    25  	// DNSStart is called with the hostname of a DNS lookup
    26  	// before it begins.
    27  	DNSStart func(name string)
    28  
    29  	// DNSDone is called after a DNS lookup completes (or fails).
    30  	// The coalesced parameter is whether singleflight de-duped
    31  	// the call. The addrs are of type net.IPAddr but can't
    32  	// actually be for circular dependency reasons.
    33  	DNSDone func(netIPs []any, coalesced bool, err error)
    34  
    35  	// ConnectStart is called before a Dial, excluding Dials made
    36  	// during DNS lookups. In the case of DualStack (Happy Eyeballs)
    37  	// dialing, this may be called multiple times, from multiple
    38  	// goroutines.
    39  	ConnectStart func(network, addr string)
    40  
    41  	// ConnectStart is called after a Dial with the results, excluding
    42  	// Dials made during DNS lookups. It may also be called multiple
    43  	// times, like ConnectStart.
    44  	ConnectDone func(network, addr string, err error)
    45  }
    46  

View as plain text