Skip to content

Commit 0df8132

Browse files
committed
remove unused codes
1 parent c843797 commit 0df8132

7 files changed

Lines changed: 33 additions & 108 deletions

File tree

connector/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func StartCustom[Configuration any, State any](
9191

9292
return server.ListenAndServe(serveCLI.Serve.Port)
9393
default:
94-
ctx := NewContextLogger(context.Background(), logger)
94+
ctx := otelutils.NewContextWithLogger(context.Background(), logger)
9595

9696
return cli.Execute(ctx, command)
9797
}

connector/http.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"time"
1515

1616
"github.com/google/uuid"
17+
"github.com/hasura/gotel/otelutils"
1718
"github.com/hasura/ndc-sdk-go/v2/schema"
1819
"github.com/hasura/ndc-sdk-go/v2/utils"
1920
"go.opentelemetry.io/otel"
@@ -232,7 +233,7 @@ func (rt *router) createHandleFunc( //nolint:gocognit
232233
}
233234

234235
logger := rt.logger.With(slog.String("request_id", requestID))
235-
req := r.WithContext(NewContextLogger(ctx, logger))
236+
req := r.WithContext(otelutils.NewContextWithLogger(ctx, logger))
236237
writer := newCustomResponseWriter(r, w)
237238

238239
for _, h := range handlers {

connector/logger.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

connector/middleware.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66

77
"github.com/Masterminds/semver/v3"
8+
"github.com/hasura/gotel"
89
"github.com/hasura/ndc-sdk-go/v2/schema"
910
"go.opentelemetry.io/otel/metric"
1011
)
@@ -13,7 +14,7 @@ import (
1314
func (s *Server[Configuration, State]) withNDCVersionCheck(w http.ResponseWriter, r *http.Request) {
1415
requestedVersion := r.Header.Get(schema.XHasuraNDCVersion)
1516
if requestedVersion != "" {
16-
logger := GetLogger(r.Context())
17+
logger := gotel.GetLogger(r.Context())
1718

1819
parsedVersion, err := semver.NewVersion(requestedVersion)
1920
if err != nil {
@@ -60,7 +61,7 @@ func (s *Server[Configuration, State]) withNDCVersionCheck(w http.ResponseWriter
6061
}
6162

6263
func (s *Server[Configuration, State]) withAuth(w http.ResponseWriter, r *http.Request) {
63-
logger := GetLogger(r.Context())
64+
logger := gotel.GetLogger(r.Context())
6465
// authorize the secret token in the request header if exists.
6566
if s.options.ServiceTokenSecret != "" &&
6667
r.Header.Get("Authorization") != ("Bearer "+s.options.ServiceTokenSecret) {

connector/server.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/Masterminds/semver/v3"
2020
"github.com/hasura/gotel"
21+
"github.com/hasura/gotel/otelutils"
2122
"github.com/hasura/ndc-sdk-go/v2/schema"
2223
"github.com/prometheus/client_golang/prometheus/promhttp"
2324
"go.opentelemetry.io/otel/attribute"
@@ -132,7 +133,7 @@ func NewServer[Configuration any, State any](
132133
return nil, err
133134
}
134135

135-
ctx = NewContextLogger(ctx, telemetry.Logger)
136+
ctx = otelutils.NewContextWithLogger(ctx, telemetry.Logger)
136137

137138
configuration, err := connector.ParseConfiguration(ctx, options.Configuration)
138139
if err != nil {
@@ -165,7 +166,7 @@ func NewServer[Configuration any, State any](
165166

166167
// GetCapabilities get the connector's capabilities. Implement a handler for the /capabilities endpoint, GET method.
167168
func (s *Server[Configuration, State]) GetCapabilities(w http.ResponseWriter, r *http.Request) {
168-
logger := GetLogger(r.Context())
169+
logger := gotel.GetLogger(r.Context())
169170

170171
capabilities := s.connector.GetCapabilities(s.configuration)
171172
if capabilities == nil {
@@ -181,7 +182,7 @@ func (s *Server[Configuration, State]) GetCapabilities(w http.ResponseWriter, r
181182

182183
// Health checks the health of the connector. Implement a handler for the /health endpoint, GET method.
183184
func (s *Server[Configuration, State]) Health(w http.ResponseWriter, r *http.Request) {
184-
logger := GetLogger(r.Context())
185+
logger := gotel.GetLogger(r.Context())
185186
if err := s.connector.HealthCheck(r.Context(), s.configuration, s.state); err != nil {
186187
s.writeError(w, logger, err)
187188

@@ -193,7 +194,7 @@ func (s *Server[Configuration, State]) Health(w http.ResponseWriter, r *http.Req
193194

194195
// GetSchema implements a handler for the /schema endpoint, GET method.
195196
func (s *Server[Configuration, State]) GetSchema(w http.ResponseWriter, r *http.Request) {
196-
logger := GetLogger(r.Context())
197+
logger := gotel.GetLogger(r.Context())
197198

198199
schemaResult, err := s.connector.GetSchema(r.Context(), s.configuration, s.state)
199200
if err != nil {
@@ -216,7 +217,7 @@ func (s *Server[Configuration, State]) GetSchema(w http.ResponseWriter, r *http.
216217
// Query implements a handler for the /query endpoint, POST method that executes a query.
217218
func (s *Server[Configuration, State]) Query(w http.ResponseWriter, r *http.Request) {
218219
startTime := time.Now()
219-
logger := GetLogger(r.Context())
220+
logger := gotel.GetLogger(r.Context())
220221
span := trace.SpanFromContext(r.Context())
221222

222223
var body schema.QueryRequest
@@ -263,7 +264,7 @@ func (s *Server[Configuration, State]) Query(w http.ResponseWriter, r *http.Requ
263264
// QueryExplain implements a handler for the /query/explain endpoint, POST method that explains a query by creating an execution plan.
264265
func (s *Server[Configuration, State]) QueryExplain(w http.ResponseWriter, r *http.Request) {
265266
startTime := time.Now()
266-
logger := GetLogger(r.Context())
267+
logger := gotel.GetLogger(r.Context())
267268
span := trace.SpanFromContext(r.Context())
268269

269270
var body schema.QueryRequest
@@ -317,7 +318,7 @@ func (s *Server[Configuration, State]) MutationExplain( //nolint:dupl
317318
r *http.Request,
318319
) {
319320
startTime := time.Now()
320-
logger := GetLogger(r.Context())
321+
logger := gotel.GetLogger(r.Context())
321322
span := trace.SpanFromContext(r.Context())
322323

323324
var body schema.MutationRequest
@@ -376,7 +377,7 @@ func (s *Server[Configuration, State]) Mutation( //nolint:dupl
376377
r *http.Request,
377378
) {
378379
startTime := time.Now()
379-
logger := GetLogger(r.Context())
380+
logger := gotel.GetLogger(r.Context())
380381
span := trace.SpanFromContext(r.Context())
381382

382383
var body schema.MutationRequest
@@ -451,12 +452,17 @@ func (s *Server[Configuration, State]) unmarshalBodyJSON(
451452

452453
err := json.NewDecoder(requestReader).Decode(body)
453454
if err != nil {
454-
writeJson(w, GetLogger(r.Context()), http.StatusUnprocessableEntity, schema.ErrorResponse{
455-
Message: "failed to decode json request body",
456-
Details: map[string]any{
457-
"cause": err.Error(),
455+
writeJson(
456+
w,
457+
gotel.GetLogger(r.Context()),
458+
http.StatusUnprocessableEntity,
459+
schema.ErrorResponse{
460+
Message: "failed to decode json request body",
461+
Details: map[string]any{
462+
"cause": err.Error(),
463+
},
458464
},
459-
})
465+
)
460466

461467
counter.Add(r.Context(), 1, metric.WithAttributes(
462468
failureStatusAttribute,
@@ -481,7 +487,7 @@ func (s *Server[Configuration, State]) validateMaxBodySize(
481487

482488
err := fmt.Errorf("request body size exceeded %d MB(s)", s.options.ServerMaxBodyMegabytes)
483489

484-
writeJson(w, GetLogger(r.Context()), http.StatusUnprocessableEntity, schema.ErrorResponse{
490+
writeJson(w, gotel.GetLogger(r.Context()), http.StatusUnprocessableEntity, schema.ErrorResponse{
485491
Message: err.Error(),
486492
Details: map[string]any{},
487493
})

connector/telemetry.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ func SetSpanHeaderAttributes(
151151
allowedHeaders ...string,
152152
) {
153153
headers := otelutils.NewTelemetryHeaders(httpHeaders, allowedHeaders...)
154-
155154
otelutils.SetSpanHeaderAttributes(span, prefix, headers)
156155
}
156+
157+
// GetLogger gets the logger instance from context.
158+
func GetLogger(ctx context.Context) *slog.Logger {
159+
return gotel.GetLogger(ctx)
160+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ require (
1212
github.com/klauspost/compress v1.18.4
1313
github.com/prometheus/client_golang v1.23.2
1414
github.com/prometheus/common v0.67.5
15-
go.opentelemetry.io/contrib/bridges/otelslog v0.17.0
1615
go.opentelemetry.io/otel v1.42.0
1716
go.opentelemetry.io/otel/metric v1.42.0
18-
go.opentelemetry.io/otel/sdk/log v0.18.0
1917
go.opentelemetry.io/otel/trace v1.42.0
2018
gotest.tools/v3 v3.5.2
2119
)
@@ -32,6 +30,7 @@ require (
3230
github.com/prometheus/otlptranslator v1.0.0 // indirect
3331
github.com/prometheus/procfs v0.20.1 // indirect
3432
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
33+
go.opentelemetry.io/contrib/bridges/otelslog v0.17.0 // indirect
3534
go.opentelemetry.io/contrib/propagators/b3 v1.42.0 // indirect
3635
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.18.0 // indirect
3736
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.18.0 // indirect
@@ -43,6 +42,7 @@ require (
4342
go.opentelemetry.io/otel/exporters/prometheus v0.64.0 // indirect
4443
go.opentelemetry.io/otel/log v0.18.0 // indirect
4544
go.opentelemetry.io/otel/sdk v1.42.0 // indirect
45+
go.opentelemetry.io/otel/sdk/log v0.18.0 // indirect
4646
go.opentelemetry.io/otel/sdk/metric v1.42.0 // indirect
4747
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
4848
go.yaml.in/yaml/v2 v2.4.4 // indirect

0 commit comments

Comments
 (0)