Documentation
¶
Index ¶
- Constants
- func Do(ctx context.Context, sensor instana.TracerLogger, p graphql.Params) *graphql.Result
- func ResultCallbackFn(sensor instana.TracerLogger, fn handler.ResultCallbackFn) handler.ResultCallbackFn
- func Subscribe(ctx context.Context, sensor instana.TracerLogger, p graphql.Params) chan *graphql.Result
- type ExpiringMap
Examples ¶
Constants ¶
View Source
const Version = "1.20.0"
Version is the instrumentation module semantic version
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do wraps the original graphql.Do, traces the GraphQL query and returns the result of the original graphql.Do
Example ¶
package main import ( "context" "fmt" "log" "github.com/graphql-go/graphql" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instagraphql" ) func main() { // create an instance of the Instana collector c := instana.InitCollector(&instana.Options{ Service: "go-graphql", }) // setup GraphQL normally fields := graphql.Fields{ "myfield": &graphql.Field{ Type: graphql.String, }, } rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields} schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} schema, err := graphql.NewSchema(schemaConfig) if err != nil { log.Fatalf("failed to create new schema, error: %v", err) } query := `query myQuery { myfield }` params := graphql.Params{Schema: schema, RequestString: query} // Call instagraphql.Do instead of the original graphql.Do. // Make sure to provide a valid context (usually an HTTP req.Context()) if any. r := instagraphql.Do(context.Background(), c, params) fmt.Println("do something with the result", r) }
Output:
func ResultCallbackFn ¶
func ResultCallbackFn(sensor instana.TracerLogger, fn handler.ResultCallbackFn) handler.ResultCallbackFn
ResultCallbackFn traces the GraphQL query and executes the original handler.ResultCallbackFn if fn is provided.
Example ¶
package main import ( "context" "fmt" "log" "net/http" "github.com/graphql-go/graphql" "github.com/graphql-go/handler" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instagraphql" ) func main() { // create an instance of the Instana collector c := instana.InitCollector(&instana.Options{ Service: "go-graphql", }) defer instana.ShutdownCollector() // setup GraphQL normally fields := graphql.Fields{ "myfield": &graphql.Field{ Type: graphql.String, }, } rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields} schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} schema, err := graphql.NewSchema(schemaConfig) if err != nil { log.Fatalf("failed to create new schema, error: %v", err) } // Setup the handler // The original ResultCallbackFn function if you have one. Otherwise, just pass nil var fn handler.ResultCallbackFn = func(ctx context.Context, params *graphql.Params, result *graphql.Result, responseBody []byte) { fmt.Println("Original callback function") } h := handler.New(&handler.Config{ Schema: &schema, Pretty: true, GraphiQL: true, // instagraphql.ResultCallbackFn instruments the code and returns the original function, if any. ResultCallbackFn: instagraphql.ResultCallbackFn(c, fn), }) http.Handle("/graphql", h) if err := http.ListenAndServe("0.0.0.0:9191", nil); err != nil { log.Fatal(err) } }
Output:
Types ¶
type ExpiringMap ¶
ExpiringMap holds a map of spans that are automatically removed from this map after the provided duration expires. The expiration time is renewed if the map is set with the same key before the original time exipres.
Click to show internal directories.
Click to hide internal directories.