v1.60.3 Latest Latest

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 14 Imported by: 2



Package graphql provides functions to trace the graph-gophers/graphql-go package (

We use the tracing mechanism available in the subpackage. Create a new Tracer with `NewTracer` and pass it as an additional option to `MustParseSchema`.

// 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 (
// Copyright 2016 Datadog, Inc.

package main

import (

	graphqltrace ""

	graphql ""

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),
	http.Handle("/query", &relay.Handler{Schema: schema})
	log.Fatal(http.ListenAndServe(":8080", nil))

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




This section is empty.


This section is empty.


func NewTracer

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

NewTracer creates a new Tracer.


type Option

type Option func(*config)

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

func WithAnalytics added in v1.11.0

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate added in v1.11.0

func WithAnalyticsRate(rate float64) Option

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

func WithOmitTrivial added in v1.27.0

func WithOmitTrivial() Option

WithOmitTrivial enables omission of graphql fields marked as trivial. This also opts trivial fields out of Threat Detection (and blocking).

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the given service name for the client.

func WithTraceVariables added in v1.60.0

func WithTraceVariables() Option

WithTraceVariables enables tracing of variables passed into GraphQL queries and resolvers.

type Tracer

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

func (t *Tracer) TraceField(ctx context.Context, _, typeName, fieldName string, trivial bool, arguments map[string]interface{}) (context.Context, tracer.FieldFinishFunc)

TraceField traces a GraphQL field access.

func (*Tracer) TraceQuery

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

TraceQuery traces a GraphQL query.

Jump to

Keyboard shortcuts

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