It is an OpenTelemetry instrumentation for Golang 99designs/gqlgen, a port from https://github.com/open-telemetry/opentelemetry-go-contrib/pull/761.
It can only instrument traces for the present.
To install the otelgqlgen package, use the following command:
go get github.com/ravilushqa/otelgqlgen
Below is a basic example of how to use otelgqlgen:
package main
import (
"github.com/99designs/gqlgen/graphql/handler"
"github.com/ravilushqa/otelgqlgen"
"github.com/myorg/mygqlgenapi/graph"
)
func main() {
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
// Add the otelgqlgen middleware to add OpenTelemetry tracing
srv.Use(otelgqlgen.Middleware())
// Your usual server setup code...
}
otelgqlgen provides several options to customize the tracing behavior:
WithTracerProvider(provider)
: Specifies a custom tracer provider. By default, the global OpenTelemetry tracer provider is used.WithComplexityExtensionName(name)
: Specifies a name for the complexity extension. By default, a name is automatically generated.WithRequestVariablesAttributesBuilder(builder)
: Specifies a custom function to build the attributes for the request variables.WithoutVariables()
: Disables the variables attributes.WithCreateSpanFromFields(predicate)
: Specifies a custom function to control whether a span should be created based on the GraphQL context fields.See ./example.
This project is tested on the following systems.
OS | Go Version | Architecture |
---|---|---|
Ubuntu | 1.21 | amd64 |
Ubuntu | 1.22 | amd64 |
Ubuntu | 1.21 | 386 |
Ubuntu | 1.22 | 386 |
MacOS | 1.21 | amd64 |
MacOS | 1.22 | amd64 |
Windows | 1.21 | amd64 |
Windows | 1.22 | amd64 |
Windows | 1.21 | 386 |
Windows | 1.22 | 386 |
While this project should work for other systems, no compatibility guarantees are made for those systems currently.
The project follows the Release Policy to support major Go releases.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.