Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions cmd/flux/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import (
"github.com/influxdata/flux/fluxinit"
"github.com/influxdata/flux/internal/errors"
"github.com/influxdata/flux/repl"
"github.com/opentracing/opentracing-go"
"github.com/spf13/cobra"
jaegercfg "github.com/uber/jaeger-client-go/config"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.20.0"

// Include the sqlite3 driver for vanilla Flux
_ "github.com/mattn/go-sqlite3"
Expand Down Expand Up @@ -74,31 +78,52 @@ func runE(cmd *cobra.Command, args []string) error {
func configureTracing(ctx context.Context) (context.Context, func(), error) {
if flags.Trace == "" {
return ctx, func() {}, nil
} else if flags.Trace != "jaeger" {
} else if flags.Trace == "jaeger" {
fmt.Fprintln(os.Stderr, "Warning: jaeger tracing is no longer supported, use --trace=otlp instead. Continuing without tracing.")
return ctx, func() {}, nil
} else if flags.Trace != "otlp" {
return nil, nil, errors.Newf(codes.Invalid, "unknown tracer name: %s", flags.Trace)
}

cfg, err := jaegercfg.FromEnv()
// Create OTLP exporter - uses OTEL_EXPORTER_OTLP_ENDPOINT env var by default
exporter, err := otlptracegrpc.New(ctx)
if err != nil {
return nil, nil, err
}
if cfg.ServiceName == "" {
cfg.ServiceName = "flux"
return nil, nil, fmt.Errorf("failed to create OTLP exporter: %w", err)
}
if cfg.Sampler.Type == "" {
cfg.Sampler.Type = "const"
cfg.Sampler.Param = 1.0

// Get service name from environment or use default
serviceName := "flux"
if name := os.Getenv("OTEL_SERVICE_NAME"); name != "" {
serviceName = name
}

tracer, closer, err := cfg.NewTracer()
// Create resource with service name
res, err := resource.New(ctx,
resource.WithAttributes(
semconv.ServiceNameKey.String(serviceName),
),
)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("failed to create resource: %w", err)
}

opentracing.SetGlobalTracer(tracer)
// Create TracerProvider with the exporter
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(res),
sdktrace.WithSampler(sdktrace.AlwaysSample()),
)

// Set as global tracer provider
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
))

return ctx, func() {
if err := closer.Close(); err != nil {
fmt.Printf("error closing tracer: %s.\n", err)
if err := tp.Shutdown(context.Background()); err != nil {
fmt.Printf("error shutting down tracer provider: %s.\n", err)
}
}, nil
}
Expand All @@ -120,9 +145,9 @@ func main() {
}
fluxCmd.Flags().BoolVarP(&flags.ExecScript, "exec", "e", false, "Interpret file argument as a raw flux script")
fluxCmd.Flags().BoolVarP(&flags.EnableSuggestions, "enable-suggestions", "", false, "enable suggestions in the repl")
fluxCmd.Flags().StringVar(&flags.Trace, "trace", "", "Trace query execution")
fluxCmd.Flags().StringVar(&flags.Trace, "trace", "", "Trace query execution (otlp)")
fluxCmd.Flags().StringVarP(&flags.Format, "format", "", "cli", "Output format one of: cli,csv. Defaults to cli")
fluxCmd.Flag("trace").NoOptDefVal = "jaeger"
fluxCmd.Flag("trace").NoOptDefVal = "otlp"
fluxCmd.Flags().StringVar(&flags.Features, "features", "", "JSON object specifying the features to execute with. See internal/feature/flags.yml for a list of the current features")

fmtCmd := &cobra.Command{
Expand Down
10 changes: 5 additions & 5 deletions execute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
"github.com/influxdata/flux/memory"
"github.com/influxdata/flux/metadata"
"github.com/influxdata/flux/plan"
"github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -523,17 +525,15 @@ func (es *executionState) do() {
}
profileSpan := profile.StartSpan()

if span, spanCtx := opentracing.StartSpanFromContext(ctx, opName, opentracing.Tag{Key: "label", Value: src.Label()}); span != nil {
ctx = spanCtx
defer span.Finish()
}
ctx, span := otel.Tracer("flux").Start(ctx, opName, trace.WithAttributes(attribute.String("label", src.Label())))

defer wg.Done()

// Setup panic handling on the source goroutines
defer es.recover()
src.Run(ctx)
profileSpan.Finish()
span.End()

updateStats(func(stats *flux.Statistics) {
stats.Profiles = append(stats.Profiles, profile)
Expand Down
18 changes: 11 additions & 7 deletions execute/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
"github.com/influxdata/flux/internal/jaeger"
"github.com/influxdata/flux/interpreter"
"github.com/influxdata/flux/plan"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -64,7 +65,7 @@ type consecutiveTransport struct {
totalMsgs int32

initSpanOnce sync.Once
span opentracing.Span
span trace.Span
}

func newConsecutiveTransport(ctx context.Context, dispatcher Dispatcher, t Transformation, n plan.Node, logger *zap.Logger, mem memory.Allocator) *consecutiveTransport {
Expand Down Expand Up @@ -231,13 +232,16 @@ func (t *consecutiveTransport) transition(new int32) {

func (t *consecutiveTransport) initSpan(ctx context.Context) {
t.initSpanOnce.Do(func() {
t.span, _ = opentracing.StartSpanFromContext(ctx, t.profile.NodeType, opentracing.Tag{Key: "label", Value: t.profile.Label})
_, t.span = otel.Tracer("flux").Start(ctx, t.profile.NodeType, trace.WithAttributes(attribute.String("label", t.profile.Label)))
})
}

func (t *consecutiveTransport) finishSpan(err error) {
t.span.LogFields(log.Int("messages_processed", int(atomic.LoadInt32(&t.totalMsgs))), log.Error(err))
t.span.Finish()
if err != nil {
t.span.RecordError(err)
}
t.span.SetAttributes(attribute.Int("messages_processed", int(atomic.LoadInt32(&t.totalMsgs))))
t.span.End()
}

func (t *consecutiveTransport) processMessages(ctx context.Context, throughput int) {
Expand Down Expand Up @@ -559,7 +563,7 @@ func (t *consecutiveTransportTable) Do(f func(flux.ColReader) error) error {
}

ctx, logger := t.transport.ctx, t.transport.logger
if span := opentracing.SpanFromContext(ctx); span != nil {
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
if traceID, sampled, found := jaeger.InfoFromSpan(span); found {
fields = append(fields,
zap.String("tracing/id", traceID),
Expand Down
46 changes: 25 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/gofrs/uuid v3.3.0+incompatible
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec
github.com/google/flatbuffers v25.9.23+incompatible
github.com/google/go-cmp v0.6.0
github.com/google/go-cmp v0.7.0
github.com/influxdata/gosnowflake v1.9.0
github.com/influxdata/influxdb-client-go/v2 v2.3.1-0.20210518120617-5d1fff431040
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839
Expand All @@ -35,32 +35,34 @@ require (
github.com/jackc/pgx/v5 v5.7.6
github.com/mattn/go-sqlite3 v1.14.18
github.com/microsoft/go-mssqldb v1.9.4
github.com/opentracing/opentracing-go v1.2.0
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.53.0
github.com/segmentio/kafka-go v0.1.0
github.com/spf13/cobra v0.0.3
github.com/stretchr/testify v1.11.1
github.com/uber/athenadriver v1.1.4
github.com/uber/jaeger-client-go v2.28.0+incompatible
github.com/vertica/vertica-sql-go v1.1.1
go.opentelemetry.io/otel v1.38.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0
go.opentelemetry.io/otel/sdk v1.38.0
go.opentelemetry.io/otel/trace v1.38.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
golang.org/x/tools v0.38.0
gonum.org/v1/gonum v0.15.1
gonum.org/v1/gonum v0.16.0
google.golang.org/api v0.214.0
google.golang.org/grpc v1.71.0
google.golang.org/protobuf v1.36.5
google.golang.org/grpc v1.75.0
google.golang.org/protobuf v1.36.8
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
cel.dev/expr v0.19.1 // indirect
cel.dev/expr v0.24.0 // indirect
cloud.google.com/go/auth v0.13.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/bigquery v1.64.0 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
cloud.google.com/go/compute/metadata v0.7.0 // indirect
cloud.google.com/go/iam v1.2.2 // indirect
cloud.google.com/go/longrunning v0.6.2 // indirect
cloud.google.com/go/monitoring v1.21.2 // indirect
Expand All @@ -69,7 +71,6 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.2 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.0 // indirect
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/apache/arrow/go/v15 v15.0.2 // indirect
Expand All @@ -87,7 +88,8 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.8 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.54.4 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deepmap/oapi-codegen v1.6.0 // indirect
Expand All @@ -97,7 +99,8 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-jose/go-jose/v4 v4.1.1 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
Expand All @@ -108,6 +111,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
Expand All @@ -131,26 +135,26 @@ require (
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect
github.com/uber-go/tally v3.3.15+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/zeebo/errs v1.4.0 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
go.opentelemetry.io/otel/metric v1.38.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
Expand All @@ -159,6 +163,6 @@ require (
golang.org/x/time v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
)
Loading