Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Migrate ddtrace references to telem package #32175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions cmd/installer-downloader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/oci"
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

const (
Expand Down Expand Up @@ -49,7 +48,7 @@ func main() {
defer func() { _ = t.Stop(ctx) }()
var err error
span, ctx := telemetry.StartSpanFromEnv(ctx, fmt.Sprintf("downloader-%s", Flavor))
defer func() { span.Finish(tracer.WithError(err)) }()
defer func() { span.Finish(err) }()
err = runDownloader(ctx, env, Version, Flavor)
if err != nil {
fmt.Fprintf(os.Stderr, "Installation failed: %v\n", err)
Expand Down
6 changes: 2 additions & 4 deletions cmd/installer/subcommands/installer/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
"github.com/DataDog/datadog-agent/pkg/version"
"github.com/spf13/cobra"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -89,7 +87,7 @@ func UnprivilegedCommands(_ *command.GlobalParams) []*cobra.Command {
type cmd struct {
t *telemetry.Telemetry
ctx context.Context
span ddtrace.Span
span telemetry.Span
env *env.Env
}

Expand All @@ -107,7 +105,7 @@ func newCmd(operation string) *cmd {
}

func (c *cmd) Stop(err error) {
c.span.Finish(tracer.WithError(err))
c.span.Finish(err)
if c.t != nil {
err := c.t.Stop(context.Background())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/installer/subcommands/installer/umask_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ package installer
import (
"syscall"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
)

// setInstallerUmask sets umask 0 to override any inherited umask
func setInstallerUmask(span ddtrace.Span) {
func setInstallerUmask(span telemetry.Span) {
oldmask := syscall.Umask(0)
span.SetTag("inherited_umask", oldmask)
}
6 changes: 2 additions & 4 deletions cmd/installer/subcommands/installer/umask_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

package installer

import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
)
import "github.com/DataDog/datadog-agent/pkg/fleet/telemetry"

// setInstallerUmask no-op on Windows
func setInstallerUmask(_ ddtrace.Span) {}
func setInstallerUmask(_ telemetry.Span) {}
54 changes: 20 additions & 34 deletions pkg/fleet/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
"sync"
"time"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/pkg/config/remote/client"
"github.com/DataDog/datadog-agent/pkg/config/utils"
Expand All @@ -34,6 +31,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/fleet/internal/cdn"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/exec"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/paths"
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
pbgo "github.com/DataDog/datadog-agent/pkg/proto/pbgo/core"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/version"
Expand Down Expand Up @@ -271,8 +269,8 @@ func (d *daemonImpl) Install(ctx context.Context, url string, args []string) err
}

func (d *daemonImpl) install(ctx context.Context, url string, args []string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "install")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "install")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand All @@ -293,8 +291,8 @@ func (d *daemonImpl) StartExperiment(ctx context.Context, url string) error {
}

func (d *daemonImpl) startExperiment(ctx context.Context, url string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "start_experiment")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "start_experiment")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand All @@ -308,8 +306,8 @@ func (d *daemonImpl) startExperiment(ctx context.Context, url string) (err error
}

func (d *daemonImpl) startInstallerExperiment(ctx context.Context, url string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "start_installer_experiment")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "start_installer_experiment")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand All @@ -334,8 +332,8 @@ func (d *daemonImpl) PromoteExperiment(ctx context.Context, pkg string) error {
}

func (d *daemonImpl) promoteExperiment(ctx context.Context, pkg string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "promote_experiment")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "promote_experiment")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand All @@ -356,8 +354,8 @@ func (d *daemonImpl) StopExperiment(ctx context.Context, pkg string) error {
}

func (d *daemonImpl) stopExperiment(ctx context.Context, pkg string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "stop_experiment")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "stop_experiment")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand All @@ -378,8 +376,8 @@ func (d *daemonImpl) StartConfigExperiment(ctx context.Context, url string, vers
}

func (d *daemonImpl) startConfigExperiment(ctx context.Context, url string, version string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "start_config_experiment")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "start_config_experiment")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand All @@ -400,8 +398,8 @@ func (d *daemonImpl) PromoteConfigExperiment(ctx context.Context, pkg string) er
}

func (d *daemonImpl) promoteConfigExperiment(ctx context.Context, pkg string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "promote_config_experiment")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "promote_config_experiment")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand All @@ -422,8 +420,8 @@ func (d *daemonImpl) StopConfigExperiment(ctx context.Context, pkg string) error
}

func (d *daemonImpl) stopConfigExperiment(ctx context.Context, pkg string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "stop_config_experiment")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "stop_config_experiment")
defer func() { span.Finish(err) }()
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand Down Expand Up @@ -455,7 +453,7 @@ func (d *daemonImpl) handleRemoteAPIRequest(request remoteAPIRequest) (err error
defer d.m.Unlock()
defer d.requestsWG.Done()
parentSpan, ctx := newRequestContext(request)
defer parentSpan.Finish(tracer.WithError(err))
defer parentSpan.Finish(err)
d.refreshState(ctx)
defer d.refreshState(ctx)

Expand Down Expand Up @@ -545,25 +543,13 @@ type requestState struct {
ErrorCode installerErrors.InstallerErrorCode
}

func newRequestContext(request remoteAPIRequest) (ddtrace.Span, context.Context) {
func newRequestContext(request remoteAPIRequest) (telemetry.Span, context.Context) {
ctx := context.WithValue(context.Background(), requestStateKey, &requestState{
Package: request.Package,
ID: request.ID,
State: pbgo.TaskState_RUNNING,
})

ctxCarrier := tracer.TextMapCarrier{
tracer.DefaultTraceIDHeader: request.TraceID,
tracer.DefaultParentIDHeader: request.ParentSpanID,
tracer.DefaultPriorityHeader: "2",
}
spanCtx, err := tracer.Extract(ctxCarrier)
if err != nil {
log.Debugf("failed to extract span context from install script params: %v", err)
return tracer.StartSpan("remote_request"), ctx
}

return tracer.StartSpanFromContext(ctx, "remote_request", tracer.ChildOf(spanCtx))
return telemetry.StartSpanFromIDs(ctx, "remote_request", request.TraceID, request.ParentSpanID)
}

func setRequestInvalid(ctx context.Context) {
Expand Down
15 changes: 7 additions & 8 deletions pkg/fleet/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/DataDog/datadog-agent/pkg/fleet/internal/cdn"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/paths"
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"

"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
installerErrors "github.com/DataDog/datadog-agent/pkg/fleet/installer/errors"
Expand All @@ -28,8 +29,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/fleet/internal/db"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/version"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

const (
Expand Down Expand Up @@ -164,9 +163,9 @@ func (i *installerImpl) Install(ctx context.Context, url string, args []string)
if err != nil {
return fmt.Errorf("could not download package: %w", err)
}
span, ok := tracer.SpanFromContext(ctx)
span, ok := telemetry.SpanFromContext(ctx)
if ok {
span.SetTag(ext.ResourceName, pkg.Name)
span.SetResourceName(pkg.Name)
span.SetTag("package_version", pkg.Version)
}
err = i.preparePackage(ctx, pkg.Name, args) // Preinst
Expand Down Expand Up @@ -471,9 +470,9 @@ func (i *installerImpl) Purge(ctx context.Context) {
}

// remove all from disk
span, _ := tracer.StartSpanFromContext(ctx, "remove_all")
span, _ := telemetry.StartSpanFromContext(ctx, "remove_all")
err = os.RemoveAll(i.packagesDir)
defer span.Finish(tracer.WithError(err))
defer span.Finish(err)
if err != nil {
log.Warnf("could not delete packages dir: %v", err)
}
Expand Down Expand Up @@ -659,8 +658,8 @@ func (i *installerImpl) configurePackage(ctx context.Context, pkg string) (err e
return nil
}

span, _ := tracer.StartSpanFromContext(ctx, "configure_package")
defer func() { span.Finish(tracer.WithError(err)) }()
span, _ := telemetry.StartSpanFromContext(ctx, "configure_package")
defer func() { span.Finish(err) }()

switch pkg {
case packageDatadogAgent, packageAPMInjector:
Expand Down
4 changes: 2 additions & 2 deletions pkg/fleet/installer/oci/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (
"github.com/google/go-containerregistry/pkg/v1/types"
"go.uber.org/multierr"
"golang.org/x/net/http2"
httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"

"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
installerErrors "github.com/DataDog/datadog-agent/pkg/fleet/installer/errors"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/tar"
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
"github.com/DataDog/datadog-agent/pkg/util/log"
)

Expand Down Expand Up @@ -241,7 +241,7 @@ func getRefAndKeychain(env *env.Env, url string) urlWithKeychain {
// If they are specified, the registry and authentication overrides are applied first.
// Then we try each registry in the list of default registries in order and return the first successful download.
func (d *Downloader) downloadRegistry(ctx context.Context, url string) (oci.Image, error) {
transport := httptrace.WrapRoundTripper(d.client.Transport)
transport := telemetry.WrapRoundTripper(d.client.Transport)
var err error
if d.env.Mirror != "" {
transport, err = newMirrorTransport(transport, d.env.Mirror)
Expand Down
34 changes: 17 additions & 17 deletions pkg/fleet/installer/packages/apm_inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (

"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/packages/embedded"
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
"github.com/DataDog/datadog-agent/pkg/util/log"
"go.uber.org/multierr"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

const (
Expand All @@ -32,26 +32,26 @@ const (

// SetupAPMInjector sets up the injector at bootstrap
func SetupAPMInjector(ctx context.Context) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "setup_injector")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "setup_injector")
defer func() { span.Finish(err) }()
installer := newAPMInjectorInstaller(injectorPath)
defer func() { installer.Finish(err) }()
return installer.Setup(ctx)
}

// RemoveAPMInjector removes the APM injector
func RemoveAPMInjector(ctx context.Context) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "remove_injector")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "remove_injector")
defer func() { span.Finish(err) }()
installer := newAPMInjectorInstaller(injectorPath)
defer func() { installer.Finish(err) }()
return installer.Remove(ctx)
}

// InstrumentAPMInjector instruments the APM injector
func InstrumentAPMInjector(ctx context.Context, method string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "instrument_injector")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "instrument_injector")
defer func() { span.Finish(err) }()
installer := newAPMInjectorInstaller(injectorPath)
installer.envs.InstallScript.APMInstrumentationEnabled = method
defer func() { installer.Finish(err) }()
Expand All @@ -60,8 +60,8 @@ func InstrumentAPMInjector(ctx context.Context, method string) (err error) {

// UninstrumentAPMInjector uninstruments the APM injector
func UninstrumentAPMInjector(ctx context.Context, method string) (err error) {
span, ctx := tracer.StartSpanFromContext(ctx, "uninstrument_injector")
defer func() { span.Finish(tracer.WithError(err)) }()
span, ctx := telemetry.StartSpanFromContext(ctx, "uninstrument_injector")
defer func() { span.Finish(err) }()
installer := newAPMInjectorInstaller(injectorPath)
installer.envs.InstallScript.APMInstrumentationEnabled = method
defer func() { installer.Finish(err) }()
Expand Down Expand Up @@ -148,8 +148,8 @@ func (a *apmInjectorInstaller) Setup(ctx context.Context) error {
}

func (a *apmInjectorInstaller) Remove(ctx context.Context) (err error) {
span, _ := tracer.StartSpanFromContext(ctx, "remove_injector")
defer func() { span.Finish(tracer.WithError(err)) }()
span, _ := telemetry.StartSpanFromContext(ctx, "remove_injector")
defer func() { span.Finish(err) }()

err = a.removeInstrumentScripts(ctx)
if err != nil {
Expand Down Expand Up @@ -277,8 +277,8 @@ func (a *apmInjectorInstaller) deleteLDPreloadConfigContent(_ context.Context, l
}

func (a *apmInjectorInstaller) verifySharedLib(ctx context.Context, libPath string) (err error) {
span, _ := tracer.StartSpanFromContext(ctx, "verify_shared_lib")
defer func() { span.Finish(tracer.WithError(err)) }()
span, _ := telemetry.StartSpanFromContext(ctx, "verify_shared_lib")
defer func() { span.Finish(err) }()
echoPath, err := exec.LookPath("echo")
if err != nil {
// If echo is not found, to not block install,
Expand All @@ -302,8 +302,8 @@ func (a *apmInjectorInstaller) verifySharedLib(ctx context.Context, libPath stri
// - Referenced in our public documentation, so we override them to use installer commands for consistency
// - Used on deb/rpm removal and may break the OCI in the process
func (a *apmInjectorInstaller) addInstrumentScripts(ctx context.Context) (err error) {
span, _ := tracer.StartSpanFromContext(ctx, "add_instrument_scripts")
defer func() { span.Finish(tracer.WithError(err)) }()
span, _ := telemetry.StartSpanFromContext(ctx, "add_instrument_scripts")
defer func() { span.Finish(err) }()

hostMutator := newFileMutator(
"/usr/bin/dd-host-install",
Expand Down Expand Up @@ -370,8 +370,8 @@ func (a *apmInjectorInstaller) addInstrumentScripts(ctx context.Context) (err er
// removeInstrumentScripts removes the install scripts that come with the APM injector
// if and only if they've been installed by the installer and not modified
func (a *apmInjectorInstaller) removeInstrumentScripts(ctx context.Context) (retErr error) {
span, _ := tracer.StartSpanFromContext(ctx, "remove_instrument_scripts")
defer func() { span.Finish(tracer.WithError(retErr)) }()
span, _ := telemetry.StartSpanFromContext(ctx, "remove_instrument_scripts")
defer func() { span.Finish(retErr) }()

for _, script := range []string{"dd-host-install", "dd-container-install", "dd-cleanup"} {
path := filepath.Join("/usr/bin", script)
Expand Down
Loading
Loading