From c01bb9df4e65fcf933ecc0b6623a9e2c6efc4a7f Mon Sep 17 00:00:00 2001 From: Nadia Santalla Date: Fri, 4 Oct 2024 15:48:29 +0200 Subject: [PATCH] probers: initiate traces for browser, scripted, and multihttp checks --- internal/prober/browser/browser.go | 8 ++++++++ internal/prober/multihttp/multihttp.go | 8 ++++++++ internal/prober/scripted/scripted.go | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/internal/prober/browser/browser.go b/internal/prober/browser/browser.go index bff751eae..152dec4e9 100644 --- a/internal/prober/browser/browser.go +++ b/internal/prober/browser/browser.go @@ -6,9 +6,11 @@ import ( "github.com/grafana/synthetic-monitoring-agent/internal/k6runner" "github.com/grafana/synthetic-monitoring-agent/internal/prober/logger" + "github.com/grafana/synthetic-monitoring-agent/internal/tracing" sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring" "github.com/prometheus/client_golang/prometheus" "github.com/rs/zerolog" + "go.opentelemetry.io/otel/attribute" ) const proberName = "browser" @@ -60,12 +62,18 @@ func (p Prober) Name() string { } func (p Prober) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) (bool, float64) { + ctx, probeSpan := tracing.TracerProvider(ctx).Tracer("").Start(ctx, "browser check") + defer probeSpan.End() + success, err := p.processor.Run(ctx, registry, logger, p.logger) if err != nil { p.logger.Error().Err(err).Msg("running probe") + probeSpan.RecordError(err) return false, 0 } + probeSpan.SetAttributes(attribute.Bool("success", success)) + // TODO(mem): implement custom duration extraction. return success, 0 } diff --git a/internal/prober/multihttp/multihttp.go b/internal/prober/multihttp/multihttp.go index 93970f7e0..77c168c45 100644 --- a/internal/prober/multihttp/multihttp.go +++ b/internal/prober/multihttp/multihttp.go @@ -8,9 +8,11 @@ import ( "github.com/grafana/synthetic-monitoring-agent/internal/k6runner" "github.com/grafana/synthetic-monitoring-agent/internal/prober/logger" + "github.com/grafana/synthetic-monitoring-agent/internal/tracing" sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring" "github.com/prometheus/client_golang/prometheus" "github.com/rs/zerolog" + "go.opentelemetry.io/otel/attribute" ) const proberName = "multihttp" @@ -83,12 +85,18 @@ func (p Prober) Name() string { } func (p Prober) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) (bool, float64) { + ctx, probeSpan := tracing.TracerProvider(ctx).Tracer("").Start(ctx, "multihttp check") + defer probeSpan.End() + success, err := p.processor.Run(ctx, registry, logger, p.logger) if err != nil { p.logger.Error().Err(err).Msg("running probe") + probeSpan.RecordError(err) return false, 0 } + probeSpan.SetAttributes(attribute.Bool("success", success)) + // TODO(mem): implement custom duration extraction. return success, 0 } diff --git a/internal/prober/scripted/scripted.go b/internal/prober/scripted/scripted.go index da50456ea..535a6fd54 100644 --- a/internal/prober/scripted/scripted.go +++ b/internal/prober/scripted/scripted.go @@ -6,9 +6,11 @@ import ( "github.com/grafana/synthetic-monitoring-agent/internal/k6runner" "github.com/grafana/synthetic-monitoring-agent/internal/prober/logger" + "github.com/grafana/synthetic-monitoring-agent/internal/tracing" sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring" "github.com/prometheus/client_golang/prometheus" "github.com/rs/zerolog" + "go.opentelemetry.io/otel/attribute" ) const proberName = "scripted" @@ -60,12 +62,17 @@ func (p Prober) Name() string { } func (p Prober) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) (bool, float64) { + ctx, probeSpan := tracing.TracerProvider(ctx).Tracer("").Start(ctx, "scripted check") + defer probeSpan.End() + success, err := p.processor.Run(ctx, registry, logger, p.logger) if err != nil { p.logger.Error().Err(err).Msg("running probe") + probeSpan.RecordError(err) return false, 0 } + probeSpan.SetAttributes(attribute.Bool("success", success)) // TODO(mem): implement custom duration extraction. return success, 0 }