dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/contrib/graph-gophers/graphql-go Index | Examples | Files

package graphql

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/graph-gophers/graphql-go"

Package graphql provides functions to trace the graph-gophers/graphql-go package (https://github.com/graph-gophers/graphql-go).

We use the tracing mechanism available in the https://godoc.org/github.com/graph-gophers/graphql-go/trace subpackage. Create a new Tracer with `NewTracer` and pass it as an additional option to `MustParseSchema`.

Code:

// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.

package main

import (
    "log"
    "net/http"

    graphql "github.com/graph-gophers/graphql-go"
    "github.com/graph-gophers/graphql-go/relay"
    graphqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/graph-gophers/graphql-go"
)

type resolver struct{}

func (*resolver) Hello() string { return "Hello, world!" }

func main() {
    s := `
		schema {
			query: Query
		}
		type Query {
			hello: String!
		}
	`
    schema := graphql.MustParseSchema(s, new(resolver),
        graphql.Tracer(graphqltrace.NewTracer()))
    http.Handle("/query", &relay.Handler{Schema: schema})
    log.Fatal(http.ListenAndServe(":8080", nil))

    // then:
    // $ curl -XPOST -d '{"query": "{ hello }"}' localhost:8080/query
}

Index

Examples

Package Files

graphql.go option.go

func NewTracer Uses

func NewTracer(opts ...Option) trace.Tracer

NewTracer creates a new Tracer.

type Option Uses

type Option func(*config)

Option represents an option that can be used customize the Tracer.

func WithAnalytics Uses

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) Option

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithServiceName Uses

func WithServiceName(name string) Option

WithServiceName sets the given service name for the client.

type Tracer Uses

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

A Tracer implements the graphql-go/trace.Tracer interface by sending traces to the Datadog tracer.

func (*Tracer) TraceField Uses

func (t *Tracer) TraceField(ctx context.Context, label string, typeName string, fieldName string, trivial bool, args map[string]interface{}) (context.Context, trace.TraceFieldFinishFunc)

TraceField traces a GraphQL field access.

func (*Tracer) TraceQuery Uses

func (t *Tracer) TraceQuery(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, varTypes map[string]*introspection.Type) (context.Context, trace.TraceQueryFinishFunc)

TraceQuery traces a GraphQL query.

Package graphql imports 11 packages (graph). Updated 2020-08-05. Refresh now. Tools for package owners.