Documentation ¶
Overview ¶
Package splunkdns provides OpenTelemetry instrumentation for the github.com/miekg/dns package.
Example (Client) ¶
package main import ( "fmt" "github.com/miekg/dns" "github.com/unionai/splunk-otel-go/instrumentation/github.com/miekg/dns/splunkdns" ) func main() { m := new(dns.Msg) m.SetQuestion("miek.nl.", dns.TypeMX) // Calling splunkdns.Exchange calls dns.Exchange and trace the request. reply, err := splunkdns.Exchange(m, "127.0.0.1:53") fmt.Println(reply, err) }
Output:
Example (Server) ¶
package main import ( "fmt" "github.com/miekg/dns" "github.com/unionai/splunk-otel-go/instrumentation/github.com/miekg/dns/splunkdns" ) func main() { mux := dns.NewServeMux() mux.HandleFunc(".", func(w dns.ResponseWriter, r *dns.Msg) { m := new(dns.Msg) m.SetReply(r) _ = w.WriteMsg(m) }) // Calling splunkdns.ListenAndServe calls dns.ListenAndServe and traces // all requests to handled by mux. if err := splunkdns.ListenAndServe(":dns", "udp", mux); err != nil { fmt.Println(err) } }
Output:
Index ¶
- func Exchange(m *dns.Msg, addr string, opts ...Option) (*dns.Msg, error)
- func ExchangeContext(ctx context.Context, m *dns.Msg, addr string, opts ...Option) (r *dns.Msg, err error)
- func ListenAndServe(addr, network string, handler dns.Handler, opts ...Option) error
- func ListenAndServeTLS(addr, certFile, keyFile string, handler dns.Handler, opts ...Option) error
- func Version() string
- type Client
- type Handler
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exchange ¶
Exchange performs a traced synchronous UDP query. It sends the message m to addr and waits for a reply. Exchange does not retry a failed query, nor will it fall back to TCP in case of truncation.
func ExchangeContext ¶
func ExchangeContext(ctx context.Context, m *dns.Msg, addr string, opts ...Option) (r *dns.Msg, err error)
ExchangeContext performs a traced synchronous UDP query, like Exchange. It additionally obeys deadlines from the passed Context.
func ListenAndServe ¶
ListenAndServe wraps the passed handler so all requests it servers are traced and starts a server on addr and network to handle incoming queries.
func ListenAndServeTLS ¶
ListenAndServeTLS wraps the passed handler so all requests it servers are traced and starts a server on addr and network to handle incoming queries using the passed TLS certFile and keyFile.
Types ¶
type Client ¶
A Client wraps a DNS Client so that requests are traced.
func WrapClient ¶
WrapClient returns a wraped DNS client.
Example ¶
package main import ( "fmt" "time" "github.com/miekg/dns" "github.com/unionai/splunk-otel-go/instrumentation/github.com/miekg/dns/splunkdns" ) func main() { // The Exchange or ExchangeContext functions can be used to handle simple // one-off client request. For more complex scenarios, a DNS Client can be // wrapped and all the requests it makes will be traced. client := splunkdns.WrapClient(&dns.Client{ Net: "tcp", ReadTimeout: time.Second * 10, }) m := new(dns.Msg) m.SetQuestion("miek.nl.", dns.TypeMX) reply, rtt, err := client.Exchange(m, "127.0.0.1:53") fmt.Println(reply, rtt, err) }
Output:
type Handler ¶
A Handler wraps a DNS Handler so that requests are traced.
func WrapHandler ¶
WrapHandler creates a new, wrapped DNS handler.
Example ¶
package main import ( "github.com/miekg/dns" "github.com/unionai/splunk-otel-go/instrumentation/github.com/miekg/dns/splunkdns" ) func main() { // The ListenAndServe or ListenAndServeTLS functions can be used to handle // simple server scenarios. For more complex servers, the handler used can // be wrapped and all the requests it handles will be traced. mux := dns.NewServeMux() mux.HandleFunc(".", func(w dns.ResponseWriter, r *dns.Msg) { m := new(dns.Msg) m.SetReply(r) _ = w.WriteMsg(m) }) server := &dns.Server{ Addr: ":dns", Net: "udp", Handler: splunkdns.WrapHandler(mux), } go func() { _ = server.ListenAndServe() }() }
Output:
type Option ¶
Option applies options to a configuration.
func WithAttributes ¶
WithAttributes returns an Option that appends attr to the attributes set for every span created with this instrumentation library.
func WithTracerProvider ¶
func WithTracerProvider(tp trace.TracerProvider) Option
WithTracerProvider returns an Option that sets the TracerProvider used with this instrumentation library.