forked from newrelic/go-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (36 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"log"
"net/http"
"os"
graphql "github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/relay"
"github.com/newrelic/go-agent/v3/integrations/nrgraphgophers"
newrelic "github.com/newrelic/go-agent/v3/newrelic"
)
type query struct{}
func (*query) Hello() string { return "Hello, world!" }
func main() {
// First create your New Relic Application:
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("GraphQL App"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
newrelic.ConfigDebugLogger(os.Stdout),
)
if nil != err {
panic(err)
}
s := `type Query { hello: String! }`
// Then add a graphql.Tracer(nrgraphgophers.NewTracer()) option to your
// schema parsing to get field and query segment instrumentation:
opt := graphql.Tracer(nrgraphgophers.NewTracer())
schema := graphql.MustParseSchema(s, &query{}, opt)
// Finally, instrument your request handler using newrelic.WrapHandle
// to create transactions for requests:
http.Handle(newrelic.WrapHandle(app, "/graphql", &relay.Handler{Schema: schema}))
// To test, run:
// curl -X POST -d '{"query": "query HelloOperation { hello }" }' localhost:8000/graphql
log.Fatal(http.ListenAndServe(":8000", nil))
}