Skip to content

Commit 971515f

Browse files
committed
improve explain telemetry
1 parent 848a5bc commit 971515f

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

connector/server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (s *Server[RawConfiguration, Configuration, State]) QueryExplain(w http.Res
261261
attribute.String("reason", "json_decode"),
262262
}
263263
span.SetAttributes(attributes...)
264-
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
264+
s.telemetry.queryExplainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
265265
return
266266
}
267267
decodeSpan.End()
@@ -280,7 +280,7 @@ func (s *Server[RawConfiguration, Configuration, State]) QueryExplain(w http.Res
280280
attribute.String("reason", fmt.Sprintf("%d", status)),
281281
}
282282
span.SetAttributes(attributes...)
283-
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
283+
s.telemetry.queryExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
284284
return
285285
}
286286
execSpan.End()
@@ -290,10 +290,10 @@ func (s *Server[RawConfiguration, Configuration, State]) QueryExplain(w http.Res
290290
_, responseSpan := s.telemetry.Tracer.Start(ctx, "Response")
291291
writeJson(w, logger, http.StatusOK, response)
292292
responseSpan.End()
293-
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))
293+
s.telemetry.queryExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))
294294

295295
// record latency for success requests only
296-
s.telemetry.explainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
296+
s.telemetry.queryExplainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
297297
}
298298

299299
// MutationExplain implements a handler for the /mutation/explain endpoint, POST method that explains a mutation by creating an execution plan.
@@ -320,7 +320,7 @@ func (s *Server[RawConfiguration, Configuration, State]) MutationExplain(w http.
320320
attribute.String("reason", "json_decode"),
321321
}
322322
span.SetAttributes(attributes...)
323-
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
323+
s.telemetry.mutationExplainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
324324
return
325325
}
326326
decodeSpan.End()
@@ -343,7 +343,7 @@ func (s *Server[RawConfiguration, Configuration, State]) MutationExplain(w http.
343343
attribute.String("reason", fmt.Sprintf("%d", status)),
344344
}
345345
span.SetAttributes(attributes...)
346-
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
346+
s.telemetry.mutationExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
347347
return
348348
}
349349
execSpan.End()
@@ -353,10 +353,10 @@ func (s *Server[RawConfiguration, Configuration, State]) MutationExplain(w http.
353353
_, responseSpan := s.telemetry.Tracer.Start(ctx, "Response")
354354
writeJson(w, logger, http.StatusOK, response)
355355
responseSpan.End()
356-
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))
356+
s.telemetry.mutationExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))
357357

358358
// record latency for success requests only
359-
s.telemetry.explainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
359+
s.telemetry.mutationExplainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
360360
}
361361

362362
// Mutation implements a handler for the /mutation endpoint, POST method that executes a mutation.

connector/telemetry.go

+30-15
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ import (
2727
)
2828

2929
type TelemetryState struct {
30-
Tracer traceapi.Tracer
31-
Meter metricapi.Meter
32-
Shutdown func(context.Context) error
33-
queryCounter metricapi.Int64Counter
34-
mutationCounter metricapi.Int64Counter
35-
explainCounter metricapi.Int64Counter
36-
queryLatencyHistogram metricapi.Float64Histogram
37-
explainLatencyHistogram metricapi.Float64Histogram
38-
mutationLatencyHistogram metricapi.Float64Histogram
30+
Tracer traceapi.Tracer
31+
Meter metricapi.Meter
32+
Shutdown func(context.Context) error
33+
queryCounter metricapi.Int64Counter
34+
mutationCounter metricapi.Int64Counter
35+
queryExplainCounter metricapi.Int64Counter
36+
mutationExplainCounter metricapi.Int64Counter
37+
queryLatencyHistogram metricapi.Float64Histogram
38+
queryExplainLatencyHistogram metricapi.Float64Histogram
39+
mutationExplainLatencyHistogram metricapi.Float64Histogram
40+
mutationLatencyHistogram metricapi.Float64Histogram
3941
}
4042

4143
// setupOTelSDK bootstraps the OpenTelemetry pipeline.
@@ -226,9 +228,17 @@ func setupMetrics(telemetry *TelemetryState, metricsPrefix string) error {
226228
return err
227229
}
228230

229-
telemetry.explainCounter, err = meter.Int64Counter(
230-
fmt.Sprintf("%sexplain.total", metricsPrefix),
231-
metricapi.WithDescription("The total number of explain requests"),
231+
telemetry.queryExplainCounter, err = meter.Int64Counter(
232+
fmt.Sprintf("%squery.explain_total", metricsPrefix),
233+
metricapi.WithDescription("The total number of explain query requests"),
234+
)
235+
if err != nil {
236+
return err
237+
}
238+
239+
telemetry.mutationExplainCounter, err = meter.Int64Counter(
240+
fmt.Sprintf("%smutation.explain_total", metricsPrefix),
241+
metricapi.WithDescription("The total number of explain mutation requests"),
232242
)
233243
if err != nil {
234244
return err
@@ -250,9 +260,14 @@ func setupMetrics(telemetry *TelemetryState, metricsPrefix string) error {
250260
return err
251261
}
252262

253-
telemetry.explainLatencyHistogram, err = meter.Float64Histogram(
254-
fmt.Sprintf("%sexplain.total_time", metricsPrefix),
255-
metricapi.WithDescription("Total time taken to plan and execute an explain request, in seconds"),
263+
telemetry.queryExplainLatencyHistogram, err = meter.Float64Histogram(
264+
fmt.Sprintf("%squery.explain_total_time", metricsPrefix),
265+
metricapi.WithDescription("Total time taken to plan and execute an explain query request, in seconds"),
266+
)
267+
268+
telemetry.mutationExplainLatencyHistogram, err = meter.Float64Histogram(
269+
fmt.Sprintf("%smutation.explain_total_time", metricsPrefix),
270+
metricapi.WithDescription("Total time taken to plan and execute an explain mutation request, in seconds"),
256271
)
257272

258273
return err

0 commit comments

Comments
 (0)