ravilushqa / otelgqlgen

OpenTelemetry instrumentation for 99designs/gqlgen
Apache License 2.0
66 stars 14 forks source link
golang gqlgen graphql hacktoberfest instrumentation opentelemetry

OpenTelemetry-Go gqlgen Instrumentation

ci Go Report Card codecov Go Reference

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.

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:

Example

See ./example.

Compatibility

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.

References

License

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