splunkdns

package module
v0.0.0-...-4d63041 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Splunk instrumentation for github.com/miekg/dns

This instrumentation is for the github.com/miekg/dns package.

Getting Started

This package is designed to be used as a drop-in replacement for the use of the github.com/miekg/dns package. Both a server and client example can be found here.

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exchange

func Exchange(m *dns.Msg, addr string, opts ...Option) (*dns.Msg, error)

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

func ListenAndServe(addr, network string, handler dns.Handler, opts ...Option) error

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

func ListenAndServeTLS(addr, certFile, keyFile string, handler dns.Handler, opts ...Option) error

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.

func Version

func Version() string

Version returns the version of splunkdns.

Types

type Client

type Client struct {
	*dns.Client
	// contains filtered or unexported fields
}

A Client wraps a DNS Client so that requests are traced.

func WrapClient

func WrapClient(client *dns.Client, opts ...Option) *Client

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:

func (*Client) Exchange

func (c *Client) Exchange(m *dns.Msg, addr string) (*dns.Msg, time.Duration, error)

Exchange calls the underlying Client.Exchange and traces the request.

func (*Client) ExchangeContext

func (c *Client) ExchangeContext(ctx context.Context, m *dns.Msg, addr string) (resp *dns.Msg, rtt time.Duration, err error)

ExchangeContext calls the underlying Client.ExchangeContext and traces the request.

type Handler

type Handler struct {
	dns.Handler
	// contains filtered or unexported fields
}

A Handler wraps a DNS Handler so that requests are traced.

func WrapHandler

func WrapHandler(handler dns.Handler, opts ...Option) *Handler

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:

func (*Handler) ServeDNS

func (h *Handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg)

ServeDNS dispatches requests to the underlying Handler. All requests will be traced.

type Option

type Option interface {
	internal.Option
}

Option applies options to a configuration.

func WithAttributes

func WithAttributes(attr []attribute.KeyValue) Option

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.

Directories

Path Synopsis
test module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL