otelgqlgen

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 12 Imported by: 2

README

status PkgGoDev

otelgqlgen

otelgqlgen provides 99designs/gqlgen's extension that collects OpenTelemetry traces.

Synopsis

import (
	"net/http"

	"github.com/99designs/gqlgen/graphql/handler"
	"github.com/aereal/otelgqlgen"
)

func main() {
	var srv *handler.Server // handler.Server initialized with your executable schema.
	srv.Use(otelgqlgen.New())
	_ = (&http.Server{Handler: srv}).ListenAndServe()

	// also you must instrument [OpenTelemetry SDK](https://opentelemetry.io/docs/instrumentation/go/) and OpenTelemetry collector properly.
}

Installation

go get github.com/aereal/otelgqlgen

Prior arts and comparison

ravilushqa/otelgqlgen is registered in the Registry.

It works enough for me, but I decide to create yet another instrumentation for below reasons:

  • studying
    • gqlgen extension study: I created some gqlgen extension in past, but I had not known recent extension API changes.
    • OpenTelemetry instrumentation study: I've used OpenTelemetry for private and work.
  • customizing
    • additional support: for example, APQ stats.

License

See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorSelector added in v0.10.0

type ErrorSelector func(err error) bool

ErrorSelector is a predicate that the error should be recorded.

The span records only errors that the function returns true. If the function returns false against all of the errors in the gqlgen response, the span status will be Unset instead of Error.

type Option

type Option func(c *config)

func TraceStructFields added in v0.2.0

func TraceStructFields(v bool) Option

TraceStructFields creates an Option that enforces Tracer to struct fields resolver.

default value: false The false means the Tracer only traces the resolvers runs against struct methods or resolver methods.

func WithComplexityLimitExtensionName

func WithComplexityLimitExtensionName(extName string) Option

WithComplexityLimitExtensionName creates an Option that tells Tracer to get complexity stats calculated by the extension identified by the given name.

func WithErrorSelector added in v0.10.0

func WithErrorSelector(fn ErrorSelector) Option

WithErrorSelector creates an Option that tells Tracer uses the given selector.

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) Option

WithTracerProvider creates an Optoin that tells Tracer to use given TracerProvider.

type Tracer

type Tracer struct {
	// contains filtered or unexported fields
}

Tracer is a gqlgen extension to collect traces from the resolver.

func New

func New(opts ...Option) Tracer

New returns a new Tracer with given options.

func (Tracer) ExtensionName

func (Tracer) ExtensionName() string

func (Tracer) InterceptField

func (t Tracer) InterceptField(ctx context.Context, next graphql.Resolver) (any, error)

func (Tracer) InterceptResponse

func (t Tracer) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response

func (Tracer) Validate

func (Tracer) Validate(_ graphql.ExecutableSchema) error

Directories

Path Synopsis
internal
test module

Jump to

Keyboard shortcuts

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