Skip to content

Commit b2ea499

Browse files
authored
refactor: do not sample Docker traces (#158)
1 parent e8b82d2 commit b2ea499

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

internal/cmd/local/docker/docker.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/docker/docker/client"
2020
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2121
"github.com/pterm/pterm"
22+
"go.opentelemetry.io/otel/sdk/trace"
2223
)
2324

2425
// Version contains al the version information that is being tracked.
@@ -117,20 +118,26 @@ func newWithOptions(ctx context.Context, newPing newPing, goos string) (*Docker,
117118
// docker context, or if we've missed any common installation configs here.
118119
switch goos {
119120
case "darwin":
120-
potentialHosts = append(potentialHosts,
121+
potentialHosts = append(potentialHosts,
121122
"unix:///var/run/docker.sock",
122123
fmt.Sprintf("unix://%s/.docker/run/docker.sock", paths.UserHome),
123124
)
124125
case "windows":
125126
potentialHosts = append(potentialHosts, "npipe:////./pipe/docker_engine")
126127
default:
127-
potentialHosts = append(potentialHosts,
128+
potentialHosts = append(potentialHosts,
128129
"unix:///var/run/docker.sock",
129130
fmt.Sprintf("unix://%s/.docker/desktop/docker-cli.sock", paths.UserHome),
130131
)
131132
}
132133

133-
dockerOpts := []client.Opt{client.FromEnv, client.WithAPIVersionNegotiation()}
134+
// Do not sample Docker traces. Dockers Net/HTTP client has Otel instrumentation enabled.
135+
// URL's and other fields may contain PII, or sensitive information.
136+
noopTraceProvider := trace.NewTracerProvider(
137+
trace.WithSampler(trace.NeverSample()),
138+
)
139+
140+
dockerOpts := []client.Opt{client.FromEnv, client.WithAPIVersionNegotiation(), client.WithTraceProvider(noopTraceProvider)}
134141

135142
for _, host := range potentialHosts {
136143
dockerCli, err := createAndPing(ctx, newPing, host, dockerOpts)
@@ -140,7 +147,7 @@ func newWithOptions(ctx context.Context, newPing newPing, goos string) (*Docker,
140147
return &Docker{Client: dockerCli}, nil
141148
}
142149
}
143-
150+
144151
return nil, fmt.Errorf("%w: unable to create docker client", localerr.ErrDocker)
145152
}
146153

internal/cmd/local/docker/docker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestNewWithOptions(t *testing.T) {
5757
f := func(opts ...client.Opt) (pinger, error) {
5858
// as go doesn't have a way to compare to functions, count the number of functions we have
5959
// and compare those instead
60-
if d := cmp.Diff(3, len(opts)); d != "" {
60+
if d := cmp.Diff(4, len(opts)); d != "" {
6161
t.Error("unexpected client option count options", d)
6262
}
6363

0 commit comments

Comments
 (0)