fsotel

package module
v0.0.0-...-55100aa Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DialerTracer = &fsdialer.Interceptor{
	BeforeDialContext: func(ctx context.Context, net string, addr string) (c context.Context, n string, a string) {
		ctx, span := tracer.Start(ctx, "Dial")
		if span.IsRecording() {
			span.SetAttributes(
				attribute.String("network", net),
				attribute.String("address", addr),
			)
		}
		return ctx, net, addr
	},
	AfterDialContext: func(ctx context.Context, net string, addr string, conn net.Conn, err error) (net.Conn, error) {
		span := trace.SpanFromContext(ctx)
		if err != nil {
			span.RecordError(err)
		}
		if span.IsRecording() && conn != nil {
			span.SetAttributes(
				attribute.String("LocalAddr", conn.LocalAddr().String()),
				attribute.String("RemoteAddr", conn.RemoteAddr().String()),
			)
		}
		span.End()
		return conn, err
	},
}

DialerTracer 对拨号提供 otel 支持

View Source
var ResolverTracer = &fsresolver.Interceptor{
	BeforeLookupIP: func(ctx context.Context, network, host string) (c context.Context, n, h string) {
		ctx, span := tracer.Start(ctx, "LookupIP")
		if span.IsRecording() {
			span.SetAttributes(
				attribute.String("network", network),
				attribute.String("host", host),
			)
		}
		return ctx, network, host
	},
	AfterLookupIP: func(ctx context.Context, network, host string, ips []net.IP, err error) ([]net.IP, error) {
		span := trace.SpanFromContext(ctx)
		if err != nil {
			span.RecordError(err)
		}
		if span.IsRecording() {
			result := make([]string, len(ips))
			for i := 0; i < len(ips); i++ {
				result[i] = ips[i].String()
			}
			span.SetAttributes(attribute.StringSlice("ips", result))
		}
		span.End()
		return ips, err
	},
}

ResolverTracer 对 域名解析提供 otel 支持

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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