otelresty

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 8

README

Go-resty OpenTelemetry Instrumentation

Docs

This repository aims to create a custom instrumentation for the go-resty project.

How to use

Usage is as simple as calling TraceClient passing a resty client and options, if needed.

TraceClient uses the OnBeforeRequest, OnAfterResponse and OnError hooks from the resty client to create spans and fill their attributes with request, response and error information.

Note that resty hooks follow a queue order, meaning the first hook hook added will run before the others, so make sure to call TraceClient after adding your custom hooks so that the span information will have the correct values (considering your hooks modify request/response information).

func main() {
  cli := resty.New()
  opts := []otelresty.Option{otelresty.WithTracerName("my-tracer")}

  otelresty.TraceClient(cli, opts...)
}

Documentation

Overview

Package otelresty instruments the go-resty/resty package (https://github.com/go-resty/resty).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SemVersion

func SemVersion() string

SemVersion is the semantic version to be supplied to tracer/meter creation.

func TraceClient

func TraceClient(client *resty.Client, options ...Option)

TraceClient instruments the resty client by adding OnBeforeRequest, OnAfterResponse and OnError hooks.

Example
cli := resty.New()
opts := []Option{WithTracerName("my-tracer")}
server := httptest.NewServer(testHandler())

// this hook is executed before the hook added by `TraceClient`
cli.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error {
	r.Header.Add("x-custom-header", "value")
	return nil
})

TraceClient(cli, opts...)

cli.R().Get(server.URL)
Output:

func Version

func Version() string

Version is the current release version of the go-resty instrumentation.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option applies a configuration value.

func WithPropagators

func WithPropagators(propagators propagation.TextMapPropagator) Option

WithPropagators specifies propagators to use for extracting information from the HTTP requests. If none are specified, global ones will be used.

func WithSkipper

func WithSkipper(skipper func(r *resty.Request) bool) Option

WithSkipper specifies a skipper function to determine if the middleware should not create a span for a determined request. If not specified, a span will always be created.

func WithSpanNameFormatter

func WithSpanNameFormatter(f func(operation string, r *resty.Request) string) Option

WithSpanNameFormatter takes a function that will be called on every request and the returned string will become the Span Name.

func WithSpanOptions

func WithSpanOptions(opts ...trace.SpanStartOption) Option

WithSpanOptions configures an additional set of trace.SpanOptions, which are applied to each new span.

func WithTracerName

func WithTracerName(name string) Option

WithTracerName sets the name of the tracer used to create spans. The default value is "github.com/dubonzi/otelresty".

func WithTracerProvider

func WithTracerProvider(provider oteltrace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

Jump to

Keyboard shortcuts

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