Skip to content

Commit

Permalink
cleaned otel server instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dheidemann committed Jul 11, 2024
1 parent dd8f2da commit 858cad4
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/riandyrn/otelchi"
"github.com/robfig/cron/v3"
"github.com/rs/cors"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

const (
Expand Down Expand Up @@ -71,7 +70,6 @@ func main() {
// [/api]: JSON API endpoint
// [/playground]: GraphQL Playground
// [/confirm/{sessionID}]: Confirm email addresses

router := chi.NewRouter()
router.Use(
cors.New(cors.Options{
Expand All @@ -88,17 +86,13 @@ func main() {
router.Use(middleware.Logger)

frontendUrl, _ := url.Parse("http://frontend:3000")
proxy := httputil.NewSingleHostReverseProxy(frontendUrl)
router.Handle("/*", otelhttp.NewHandler(proxy, "frontend-proxy"))
router.Handle("/*", httputil.NewSingleHostReverseProxy(frontendUrl))

router.MethodFunc(http.MethodGet, "/confirm/{sessionID}", otelhttp.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
router.Get("/confirm/{sessionID}", func(w http.ResponseWriter, r *http.Request) {
email.Confirm(ctx, w, r, db)
}), "confirm-email").ServeHTTP)

gqlResolvers := graph.Resolver{
DB: db,
}
})

gqlResolvers := graph.Resolver{DB: db}
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &gqlResolvers}))
router.With(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -108,7 +102,7 @@ func main() {
}
h.ServeHTTP(w, r)
})
}).Handle("/api", otelhttp.NewHandler(srv, "graphql-api"))
}).Handle("/api", srv)
srv.Use(otelgqlgen.Middleware(otelgqlgen.WithTracerProvider(apiTracer)))

router.Handle("/playground", playground.Handler("GraphQL playground", "/api"))
Expand Down

0 comments on commit 858cad4

Please sign in to comment.