optel

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMongoMonitor

func NewMongoMonitor() *event.CommandMonitor

NewMongoMonitor returns a new *event.CommandMonitor for the mongodb client

The returned event monitor is meant to be set in the mongoDB clientOptions through the mongo.NewMonitor function

Example:

 c := &Client{}
 clientOptions := options.Client().
	 ApplyURI(uri)
 clientOptions.SetMonitor(optel.NewMongoMonitor())
 c.conn, err = mongo.Connect(ctx, clientOptions)

func SetMonitor added in v0.7.2

func SetMonitor(co *options.ClientOptions)

SetMonitor receives a *options.ClientOptions as an argument, and sets a mongo opentelemetry monitor to the client The monitor is just configured if there is a globalTracer initialized. This is the preferred way to configure mongoDB monitoring Example:

	 c := &Client{}
	 clientOptions := options.Client().
		 ApplyURI(uri)
  optel.SetMonitor(clientOptions)
	 c.conn, err = mongo.Connect(ctx, clientOptions)

func ShutdownOptelConnection

func ShutdownOptelConnection() (err error)

ShutdownOptelConnection runs every shutdown routined registered by the StartOptelConnection function. It is recommended to run this function using defer afte running StartOptelConnection Example:

err := StartOptelConnection(ctx, myConfig)
if err != nil {
  handleErrorFunction(err)
}
defer ShutdownOptelConnection()

func StartOptelConnection

func StartOptelConnection(ctx context.Context, c OptelConfiguration) (err error)

StartOptelConnection creates all the necessary resources to send monitoring information to a OpenTelemetry colletor Even though this function returns an error if the setup fails, it is not recommended to kill the application in case of monitoring failure It is essential to run ShutdownOptelConnection when before stopping the application.

func StartTrack

func StartTrack(ctx context.Context, n string) func()

StartTrack is used to start a new span (checkpoint) in the application trace.

The function starts tracking as soon as it is called, but it is essential to call the returned end function using defer.

One-liner example (preferred usage):

defer StartTrack(ctx, "myEventName")()

Verbose example:

endFunction := StartTrack(ctx, "myEventName")
defer endFunction()

func StartTrackEntrypoint added in v0.7.3

func StartTrackEntrypoint(ctx context.Context, n string) (context.Context, func())

func TraceIdFromContext

func TraceIdFromContext(ctx context.Context) string

func TraceMiddlewares

func TraceMiddlewares(appName string, r chi.Routes) (middlewares []func(next http.Handler) http.Handler)

TraceMiddlewares returns a slice of Chi middlewares that implement OpenTelemetry tracing and integrate with the dm-go/middleware/request_id.

It is best to apply this middleware right after the request_id middleware in the middleware chain.

Example:

r := chi.NewRouter()
r.Use(optel.TraceMiddlewares("rochelle-coupon", r)...) // Unpack the slice before passing it as an argument.

Types

type OptelConfiguration

type OptelConfiguration struct {
	Appname     string
	TraceConfig TraceConfiguration
}

type TraceConfiguration

type TraceConfiguration struct {
	CTXAttributes    map[any]string
	ExporterProtocol string
	Endpoint         string
}

Jump to

Keyboard shortcuts

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