fasthttp

package
v1.60.3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package fasthttp provides functions to trace the valyala/fasthttp package (https://github.com/valyala/fasthttp)

Example
package main

import (
	"fmt"

	fasthttptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/valyala/fasthttp.v1"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

	"github.com/valyala/fasthttp"
)

func fastHTTPHandler(ctx *fasthttp.RequestCtx) {
	fmt.Fprintf(ctx, "Hello World!")
}

func main() {
	// Start the tracer
	tracer.Start()
	defer tracer.Stop()

	// Start fasthttp server
	fasthttp.ListenAndServe(":8081", fasthttptrace.WrapHandler(fastHTTPHandler))
}
Output:

Example (WithServiceName)
package main

import (
	"fmt"

	fasthttptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/valyala/fasthttp.v1"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

	"github.com/valyala/fasthttp"
)

func fastHTTPHandler(ctx *fasthttp.RequestCtx) {
	fmt.Fprintf(ctx, "Hello World!")
}

func main() {
	// Start the tracer
	tracer.Start()
	defer tracer.Stop()

	// Start fasthttp server
	fasthttp.ListenAndServe(":8081", fasthttptrace.WrapHandler(fastHTTPHandler, fasthttptrace.WithServiceName("fasthttp-server")))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapHandler

func WrapHandler(h fasthttp.RequestHandler, opts ...Option) fasthttp.RequestHandler

WrapHandler wraps a fasthttp.RequestHandler with tracing middleware

Types

type Option

type Option func(*config)

func WithIgnoreRequest

func WithIgnoreRequest(f func(fctx *fasthttp.RequestCtx) bool) Option

WithIgnoreRequest specifies a function to use for determining if the incoming HTTP request tracing should be skipped.

func WithResourceNamer

func WithResourceNamer(fn func(fctx *fasthttp.RequestCtx) string) Option

WithResourceNamer specifies a function which will be used to obtain the resource name for a given request

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the given service name for the router.

func WithSpanOptions

func WithSpanOptions(opts ...ddtrace.StartSpanOption) Option

WithSpanOptions applies the given set of options to the spans started by the router.

func WithStatusCheck

func WithStatusCheck(fn func(statusCode int) bool) Option

WithStatusCheck allows customization over which status code(s) to consider "error"

Jump to

Keyboard shortcuts

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