diff --git a/CHANGELOG.md b/CHANGELOG.md index 033153a7fa5..216052f8cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ All notable changes to Sourcegraph are documented in this file. ### Removed - +- The deprecated GraphQL field `SearchResults.resultCount` has been removed in favor of its replacement, `matchCount`. [#31573](https://github.com/sourcegraph/sourcegraph/pull/31573) +- The deprecated site-config field `UseJaeger` has been removed. Use `"observability.tracing": { "sampling": "all" }` instead [#31294](https://github.com/sourcegraph/sourcegraph/pull/31294/commits/6793220d6cf1200535a2610d79d2dd9e18c67dca) ## 3.37.0 diff --git a/cmd/frontend/internal/app/ui/router.go b/cmd/frontend/internal/app/ui/router.go index 5d352221235..baa6e2ea0f2 100644 --- a/cmd/frontend/internal/app/ui/router.go +++ b/cmd/frontend/internal/app/ui/router.go @@ -16,6 +16,7 @@ import ( "github.com/inconshreveable/log15" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" + muxtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux" "github.com/sourcegraph/sourcegraph/cmd/frontend/envvar" "github.com/sourcegraph/sourcegraph/cmd/frontend/globals" @@ -126,8 +127,8 @@ func InitRouter(db database.DB, codeIntelResolver graphqlbackend.CodeIntelResolv var mockServeRepo func(w http.ResponseWriter, r *http.Request) -func newRouter() *mux.Router { - r := mux.NewRouter() +func newRouter() *muxtrace.Router { + r := muxtrace.NewRouter() r.StrictSlash(true) // Top-level routes. @@ -224,8 +225,8 @@ func brandNameSubtitle(titles ...string) string { return strings.Join(append(titles, globals.Branding().BrandName), " - ") } -func initRouter(db database.DB, router *mux.Router, codeIntelResolver graphqlbackend.CodeIntelResolver) { - uirouter.Router = router // make accessible to other packages +func initRouter(db database.DB, router *muxtrace.Router, codeIntelResolver graphqlbackend.CodeIntelResolver) { + uirouter.Router = router.Router // make accessible to other packages brandedIndex := func(titles string) http.Handler { return handler(db, serveBrandedPageString(db, titles, nil, index)) diff --git a/doc/admin/observability/tracing.md b/doc/admin/observability/tracing.md index 7906d3a1ab8..db862cab636 100644 --- a/doc/admin/observability/tracing.md +++ b/doc/admin/observability/tracing.md @@ -51,6 +51,17 @@ itself](https://www.jaegertracing.io/docs/1.17/sampling/), and even then, the vo traffic caused by Jaeger spans being sent to the collector may disrupt the performance of the overall Sourcegraph instance. +## Using Datadog (experimental) + +Modify the site configuration to specify type "datadog" within `observability.tracing`. + + ``` + "observability.tracing": { + "type": "datadog" + } + ``` +When Datadog tracing is enabled, the `sampling` field currently has no effect. + ### GraphQL Requests To receive a traceID on a GraphQL request, include the header `X-Sourcegraph-Should-Trace: true` with the request. @@ -88,4 +99,3 @@ there, click **Requests** to view the traces for that service. See the following docs on how to connect Sourcegraph to an external Jaeger instance: 1. [For Kubernetes Deployments](../install/kubernetes/configure.md) 2. For Docker-Compose Deployments - Currently not available - diff --git a/doc/dependency_decisions.yml b/doc/dependency_decisions.yml index 7217c6cfd72..4e2c1355931 100644 --- a/doc/dependency_decisions.yml +++ b/doc/dependency_decisions.yml @@ -353,3 +353,10 @@ :why: Used by argparse :versions: [] :when: 2021-10-12 11:17:37.706276000 Z +- - :license + - github.com/DataDog/sketches-go + - Apache 2.0 + - :who: + :why: + :versions: [] + :when: 2022-02-18 21:09:06.289293214 Z diff --git a/go.mod b/go.mod index 5993448dbb6..c4c7f84228e 100644 --- a/go.mod +++ b/go.mod @@ -168,6 +168,7 @@ require ( google.golang.org/api v0.66.0 google.golang.org/genproto v0.0.0-20220202230416-2a053f022f0d google.golang.org/protobuf v1.27.1 + gopkg.in/DataDog/dd-trace-go.v1 v1.36.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/yaml.v2 v2.4.0 @@ -180,6 +181,10 @@ require ( require ( cloud.google.com/go/compute v1.1.0 // indirect cloud.google.com/go/iam v0.1.1 // indirect + github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583 // indirect + github.com/DataDog/datadog-go v4.8.2+incompatible // indirect + github.com/DataDog/datadog-go/v5 v5.0.2 // indirect + github.com/DataDog/sketches-go v1.0.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/sprig v2.22.0+incompatible // indirect github.com/agext/levenshtein v1.2.3 // indirect @@ -200,8 +205,10 @@ require ( github.com/muesli/termenv v0.9.0 // indirect github.com/mwitkow/go-proto-validators v0.3.2 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect + github.com/philhofer/fwd v1.1.1 // indirect github.com/pseudomuto/protokit v0.2.0 // indirect github.com/smacker/go-tree-sitter v0.0.0-20220209044044-0d3022e933c3 // indirect + github.com/tinylib/msgp v1.1.2 // indirect github.com/yuin/goldmark v1.4.4 // indirect github.com/yuin/goldmark-emoji v1.0.1 // indirect sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect diff --git a/go.sum b/go.sum index dcda3a127ad..8bb8441e757 100644 --- a/go.sum +++ b/go.sum @@ -149,6 +149,15 @@ github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EF github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w= github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= +github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583 h1:3nVO1nQyh64IUY6BPZUpMYMZ738Pu+LsMt3E0eqqIYw= +github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583/go.mod h1:EP9f4GqaDJyP1F5jTNMtzdIpw3JpNs3rMSJOnYywCiw= +github.com/DataDog/datadog-go v4.8.2+incompatible h1:qbcKSx29aBLD+5QLvlQZlGmRMF/FfGqFLFev/1TDzRo= +github.com/DataDog/datadog-go v4.8.2+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/DataDog/datadog-go/v5 v5.0.2 h1:UFtEe7662/Qojxkw1d6SboAeA0CPI3naKhVASwFn+04= +github.com/DataDog/datadog-go/v5 v5.0.2/go.mod h1:ZI9JFB4ewXbw1sBnF4sxsR2k1H3xjV+PUAOUsHvKpcU= +github.com/DataDog/gostackparse v0.5.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM= +github.com/DataDog/sketches-go v1.0.0 h1:chm5KSXO7kO+ywGWJ0Zs6tdmWU8PBXSbywFVciL6BG4= +github.com/DataDog/sketches-go v1.0.0/go.mod h1:O+XkJHWk9w4hDwY2ZUDU31ZC9sNYlYo8DiFsxjYeo1k= github.com/DataDog/zstd v1.5.0 h1:+K/VEwIAaPcHiMtQvpLD4lqW7f0Gk3xdYZmI1hD+CXo= github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= @@ -1127,6 +1136,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210423192551-a2663126120b/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210506205249-923b5ab0fc1a/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= @@ -1794,6 +1804,8 @@ github.com/peterbourgon/ff/v3 v3.1.2/go.mod h1:XNJLY8EIl6MjMVjBS4F0+G0LYoAqs0DTa github.com/peterhellberg/link v1.1.0 h1:s2+RH8EGuI/mI4QwrWGSYQCRz7uNgip9BaM04HKu5kc= github.com/peterhellberg/link v1.1.0/go.mod h1:gtSlOT4jmkY8P47hbTc8PTgiDDWpdPbFYl75keYyBB8= github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d/go.mod h1:3OzsM7FXDQlpCiw2j81fOmAwQLnZnLGXVKUzeKQXIAw= +github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ= +github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= @@ -2106,6 +2118,8 @@ github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= github.com/timakin/bodyclose v0.0.0-20200424151742-cb6215831a94/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= +github.com/tinylib/msgp v1.1.2 h1:gWmO7n0Ys2RBEb7GPYB9Ujq8Mk5p2U08lRnmMcGy6BQ= +github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0= github.com/tj/assert v0.0.0-20190920132354-ee03d75cd160 h1:NSWpaDaurcAJY7PkL8Xt0PhZE7qpvbZl5ljd8r6U0bI= github.com/tj/assert v0.0.0-20190920132354-ee03d75cd160/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0= @@ -2986,6 +3000,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/DataDog/dd-trace-go.v1 v1.36.0 h1:t2KEcCXajtchpvoIGm0xU+Ytj8KkRyxsXVhWOGg6lEk= +gopkg.in/DataDog/dd-trace-go.v1 v1.36.0/go.mod h1:Cv0Bzs/zTzzrUDSw8Q+q/vC+uwPD+R530npGo0lfiCE= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alexcesaro/statsd.v2 v2.0.0 h1:FXkZSCZIH17vLCO5sO2UucTHsH9pc+17F6pl3JVCwMc= diff --git a/internal/honey/honey.go b/internal/honey/honey.go index 6275f713aed..216ee912a24 100644 --- a/internal/honey/honey.go +++ b/internal/honey/honey.go @@ -4,9 +4,9 @@ package honey import ( "log" - "os" "github.com/sourcegraph/sourcegraph/internal/env" + "github.com/sourcegraph/sourcegraph/internal/hostname" "github.com/honeycombio/libhoney-go" ) @@ -35,7 +35,7 @@ func init() { return } // HOSTNAME is the name of the pod on kubernetes. - if h := os.Getenv("HOSTNAME"); h != "" { + if h := hostname.Get(); h != "" { libhoney.AddField("pod_name", h) } } diff --git a/internal/tracer/doc.go b/internal/tracer/doc.go new file mode 100644 index 00000000000..03dee3d6fb2 --- /dev/null +++ b/internal/tracer/doc.go @@ -0,0 +1,9 @@ +// Package tracer initializes Sourcegraph's switchable tracing and log15 behavior. It also updates distributed +// tracing behavior in response to changes in site configuration. When the Init function of this +// package is invoked, opentracing.SetGlobalTracer is called (and subsequently called again after +// every Sourcegraph site configuration change). +// Programs should not invoke opentracing.SetGlobalTracer anywhere else unless called from this package +// (ie Datadog tracer package ) +// This package leverages switchableTracer to allow runtime changes of the underlying tracing provider +// To create spans, use the functions ot.StartSpan and ot.StartSpanFromContext from the ot package +package tracer diff --git a/internal/tracer/tracer.go b/internal/tracer/tracer.go index 92f8a64fb47..9a58cb4e895 100644 --- a/internal/tracer/tracer.go +++ b/internal/tracer/tracer.go @@ -1,8 +1,3 @@ -// Package tracer initializes distributed tracing and log15 behavior. It also updates distributed -// tracing behavior in response to changes in site configuration. When the Init function of this -// package is invoked, opentracing.SetGlobalTracer is called (and subsequently called again after -// every Sourcegraph site configuration change). Importing programs should not invoke -// opentracing.SetGlobalTracer anywhere else. package tracer import ( @@ -17,6 +12,8 @@ import ( jaegercfg "github.com/uber/jaeger-client-go/config" jaegermetrics "github.com/uber/jaeger-lib/metrics" "go.uber.org/automaxprocs/maxprocs" + ddopentracing "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer" + ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" "github.com/sourcegraph/sourcegraph/internal/conf/conftypes" "github.com/sourcegraph/sourcegraph/internal/env" @@ -37,73 +34,85 @@ func init() { } } -// Options control the behavior of a tracer. -type Options struct { +// options control the behavior of a tracerType +type options struct { + tracerType + externalURL string + debug bool + // these values are not configurable at runtime serviceName string + version string + env string } -// If this idiom seems strange: -// https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md -type Option func(*Options) +type tracerType string -func ServiceName(s string) Option { - return func(o *Options) { - o.serviceName = s +const ( + None tracerType = "" + Datadog tracerType = "datadog" + Ot tracerType = "opentracing" +) + +func (t tracerType) isValid() bool { + switch t { + case None, Datadog, Ot: + return true } + return false } -func Init(c conftypes.WatchableSiteConfig, options ...Option) { - opts := &Options{} - for _, setter := range options { - setter(opts) - } - if opts.serviceName == "" { - opts.serviceName = env.MyName +// Init should be called from the main function of service +func Init(c conftypes.WatchableSiteConfig) { + opts := &options{} + opts.serviceName = env.MyName + if version.IsDev(version.Version()) { + opts.env = "dev" } + opts.version = version.Version() - initTracer(opts.serviceName, c) -} - -type jaegerOpts struct { - ServiceName string - ExternalURL string - Enabled bool - Debug bool + initTracer(opts, c) } // initTracer is a helper that should be called exactly once (from Init). -func initTracer(serviceName string, c conftypes.WatchableSiteConfig) { +func initTracer(opts *options, c conftypes.WatchableSiteConfig) { globalTracer := newSwitchableTracer() opentracing.SetGlobalTracer(globalTracer) - // initial tracks if its our first run of conf.Watch. This is used to - // prevent logging "changes" when its the first run. + // initial tracks if it's our first run of conf.Watch. This is used to + // prevent logging "changes" when it's the first run. initial := true // Initially everything is disabled since we haven't read conf yet. - oldOpts := jaegerOpts{ - ServiceName: serviceName, - Enabled: false, - Debug: false, + oldOpts := options{ + serviceName: opts.serviceName, + version: opts.version, + env: opts.env, + // the values below may change + tracerType: None, + debug: false, + externalURL: "", } // Watch loop go c.Watch(func() { siteConfig := c.SiteConfig() - // Set sampling strategy samplingStrategy := ot.TraceNone shouldLog := false + setTracer := None if tracingConfig := siteConfig.ObservabilityTracing; tracingConfig != nil { switch tracingConfig.Sampling { case "all": samplingStrategy = ot.TraceAll + setTracer = Ot case "selective": samplingStrategy = ot.TraceSelective + setTracer = Ot + } + if t := tracerType(tracingConfig.Type); t.isValid() { + setTracer = t } shouldLog = tracingConfig.Debug - } else if siteConfig.UseJaeger { - samplingStrategy = ot.TraceAll } if tracePolicy := ot.GetTracePolicy(); tracePolicy != samplingStrategy && !initial { log15.Info("opentracing: TracePolicy", "oldValue", tracePolicy, "newValue", samplingStrategy) @@ -111,39 +120,54 @@ func initTracer(serviceName string, c conftypes.WatchableSiteConfig) { initial = false ot.SetTracePolicy(samplingStrategy) - opts := jaegerOpts{ - ServiceName: serviceName, - ExternalURL: siteConfig.ExternalURL, - Enabled: samplingStrategy == ot.TraceAll || samplingStrategy == ot.TraceSelective, - Debug: shouldLog, + opts := options{ + externalURL: siteConfig.ExternalURL, + tracerType: setTracer, + debug: shouldLog, + serviceName: opts.serviceName, + version: opts.version, + env: opts.env, } if opts == oldOpts { // Nothing changed return } - + prevTracer := oldOpts.tracerType oldOpts = opts - tracer, closer, err := newTracer(&opts) + t, closer, err := newTracer(&opts, prevTracer) if err != nil { - log15.Warn("Could not initialize jaeger tracer", "error", err.Error()) + log15.Warn("Could not initialize tracer", "tracer", opts.tracerType, "error", err.Error()) return } - - globalTracer.set(tracer, closer, opts.Debug) + globalTracer.set(t, closer, opts.debug) }) } -func newTracer(opts *jaegerOpts) (opentracing.Tracer, io.Closer, error) { - if !opts.Enabled { - log15.Info("opentracing: Jaeger disabled") +// TODO Use openTelemetry https://github.com/sourcegraph/sourcegraph/issues/27386 +func newTracer(opts *options, prevTracer tracerType) (opentracing.Tracer, io.Closer, error) { + if opts.tracerType == None { + log15.Info("tracing disabled") + if prevTracer == Datadog { + ddtracer.Stop() + } return opentracing.NoopTracer{}, nil, nil } + if opts.tracerType == Datadog { + log15.Info("Datadog: tracing enabled") + tracer := ddopentracing.New(ddtracer.WithService(opts.serviceName), + ddtracer.WithDebugMode(opts.debug), + ddtracer.WithServiceVersion(opts.version), ddtracer.WithEnv(opts.env)) + return tracer, nil, nil + } + if prevTracer == Datadog { + ddtracer.Stop() + } - log15.Info("opentracing: Jaeger enabled") + log15.Info("opentracing: enabled") cfg, err := jaegercfg.FromEnv() - cfg.ServiceName = opts.ServiceName + cfg.ServiceName = opts.serviceName if err != nil { return nil, nil, errors.Wrap(err, "jaegercfg.FromEnv failed") } @@ -174,44 +198,46 @@ func (l log15Logger) Infof(msg string, args ...interface{}) { log15.Info(fmt.Sprintf(msg, args...)) } -// switchableTracer implements opentracing.Tracer. The underlying tracer used is switchable (set via +// move to OpenTelemetry https://github.com/sourcegraph/sourcegraph/issues/27386 +// switchableTracer implements opentracing.Tracer. The underlying opentracer used is switchable (set via // the `set` method). type switchableTracer struct { mu sync.RWMutex - tracer opentracing.Tracer + opentracer opentracing.Tracer tracerCloser io.Closer log bool } +// move to OpenTelemetry https://github.com/sourcegraph/sourcegraph/issues/27386 func newSwitchableTracer() *switchableTracer { - return &switchableTracer{tracer: opentracing.NoopTracer{}} + return &switchableTracer{opentracer: opentracing.NoopTracer{}} } func (t *switchableTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { t.mu.RLock() defer t.mu.RUnlock() if t.log { - log15.Info("opentracing: StartSpan", "operationName", operationName, "tracer", fmt.Sprintf("%T", t.tracer)) + log15.Info("opentracing: StartSpan", "operationName", operationName, "opentracer", fmt.Sprintf("%T", t.opentracer)) } - return t.tracer.StartSpan(operationName, opts...) + return t.opentracer.StartSpan(operationName, opts...) } func (t *switchableTracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error { t.mu.RLock() defer t.mu.RUnlock() if t.log { - log15.Info("opentracing: Inject", "tracer", fmt.Sprintf("%T", t.tracer)) + log15.Info("opentracing: Inject", "opentracer", fmt.Sprintf("%T", t.opentracer)) } - return t.tracer.Inject(sm, format, carrier) + return t.opentracer.Inject(sm, format, carrier) } func (t *switchableTracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error) { t.mu.RLock() defer t.mu.RUnlock() if t.log { - log15.Info("opentracing: Extract", "tracer", fmt.Sprintf("%T", t.tracer)) + log15.Info("opentracing: Extract", "tracer", fmt.Sprintf("%T", t.opentracer)) } - return t.tracer.Extract(format, carrier) + return t.opentracer.Extract(format, carrier) } func (t *switchableTracer) set(tracer opentracing.Tracer, tracerCloser io.Closer, log bool) { @@ -223,6 +249,6 @@ func (t *switchableTracer) set(tracer opentracing.Tracer, tracerCloser io.Closer } t.tracerCloser = tracerCloser - t.tracer = tracer + t.opentracer = tracer t.log = log } diff --git a/schema/schema.go b/schema/schema.go index ef055c2d382..d8113c93985 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -1180,6 +1180,8 @@ type ObservabilityTracing struct { Debug bool `json:"debug,omitempty"` // Sampling description: Determines the requests for which distributed traces are recorded. "none" (default) turns off tracing entirely. "selective" sends traces whenever `?trace=1` is present in the URL. "all" sends traces on every request. Note that this only affects the behavior of the distributed tracing client. The Jaeger instance must be running for traces to be collected (as described in the Sourcegraph installation instructions). Additional downsampling can be configured in Jaeger, itself (https://www.jaegertracing.io/docs/1.17/sampling) Sampling string `json:"sampling,omitempty"` + // Type description: Determines what tracing provider to enable. Supports "datadog" or "opentracing" + Type string `json:"type,omitempty"` } // OnQuery description: A Sourcegraph search query that matches a set of repositories (and branches). Each matched repository branch is added to the list of repositories that the batch change will be run on. @@ -1797,8 +1799,6 @@ type SiteConfiguration struct { SearchLimits *SearchLimits `json:"search.limits,omitempty"` // UpdateChannel description: The channel on which to automatically check for Sourcegraph updates. UpdateChannel string `json:"update.channel,omitempty"` - // UseJaeger description: DEPRECATED. Use `"observability.tracing": { "sampling": "all" }`, instead. Enables Jaeger tracing. - UseJaeger bool `json:"useJaeger,omitempty"` // UserReposMaxPerSite description: The site wide maximum number of repos that can be added by non site admins UserReposMaxPerSite int `json:"userRepos.maxPerSite,omitempty"` // UserReposMaxPerUser description: The per user maximum number of repos that can be added by non site admins diff --git a/schema/site.schema.json b/schema/site.schema.json index d6b6a98aa85..f4537e638ec 100644 --- a/schema/site.schema.json +++ b/schema/site.schema.json @@ -933,15 +933,16 @@ "type": "string", "examples": ["https://sourcegraph.example.com"] }, - "useJaeger": { - "description": "DEPRECATED. Use `\"observability.tracing\": { \"sampling\": \"all\" }`, instead. Enables Jaeger tracing.", - "type": "boolean", - "group": "Misc." - }, "observability.tracing": { "description": "Controls the settings for distributed tracing.", "type": "object", "properties": { + "type": { + "description": "Determines what tracing provider to enable. Supports \"datadog\" or \"opentracing\"", + "type": "string", + "enum": ["datadog", "opentracing"], + "default": "opentracing" + }, "sampling": { "description": "Determines the requests for which distributed traces are recorded. \"none\" (default) turns off tracing entirely. \"selective\" sends traces whenever `?trace=1` is present in the URL. \"all\" sends traces on every request. Note that this only affects the behavior of the distributed tracing client. The Jaeger instance must be running for traces to be collected (as described in the Sourcegraph installation instructions). Additional downsampling can be configured in Jaeger, itself (https://www.jaegertracing.io/docs/1.17/sampling)", "type": "string",