Skip to content

OpenTelemetry instrumentation for 99designs/gqlgen

License

Notifications You must be signed in to change notification settings

rocket-connect/otelgqlgen

 
 

Repository files navigation

OpenTelemetry-Go gqlgen Instrumentation

ci Go Report Card codecov Go Reference

It is an OpenTelemetry instrumentation for Golang 99designs/gqlgen, a port from open-telemetry/opentelemetry-go-contrib#761.

It can only instrument traces for the present.

Installation

To install the otelgqlgen package, use the following command:

go get github.com/ravilushqa/otelgqlgen

Usage

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...
}

Configuration Options

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.

Example

See ./example.

Compatibility

This project is tested on the following systems.

OS Go Version Architecture
Ubuntu 1.20 amd64
Ubuntu 1.21 amd64
Ubuntu 1.20 386
Ubuntu 1.21 386
MacOS 1.20 amd64
MacOS 1.21 amd64
Windows 1.20 amd64
Windows 1.21 amd64
Windows 1.20 386
Windows 1.21 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.

References

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

About

OpenTelemetry instrumentation for 99designs/gqlgen

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 88.1%
  • Makefile 10.2%
  • Dockerfile 1.7%