MCPcopy
hub / github.com/docker/docker-agent / newClient

Function newClient

pkg/telemetry/client.go:47–93  ·  view source on GitHub ↗
(ctx context.Context, logger *slog.Logger, enabled, debugMode bool, version string, customHTTPClient ...*http.Client)

Source from the content-addressed store, hash-verified

45}
46
47func newClient(ctx context.Context, logger *slog.Logger, enabled, debugMode bool, version string, customHTTPClient ...*http.Client) *Client {
48 telemetryLogger := NewTelemetryLogger(logger)
49
50 if !enabled {
51 return &Client{
52 logger: telemetryLogger,
53 enabled: false,
54 debugMode: debugMode,
55 version: version,
56 }
57 }
58
59 header := "x-api-key"
60
61 endpoint := "https://api.docker.com/events/v1/track"
62 apiKey := "Gxw1IjiDEP29dWm9DanuE2XhIKKzqDEY4iGlW1P0"
63
64 // Use staging configuration in debug mode
65 if debugMode {
66 endpoint = "https://api-stage.docker.com/events/v1/track"
67 apiKey = "z4sTQ8eDid2nJ53md8ptCaZlVxvIlhvf4AGR7oi5"
68 }
69
70 var httpClient *http.Client
71 if len(customHTTPClient) > 0 && customHTTPClient[0] != nil {
72 httpClient = customHTTPClient[0]
73 } else {
74 httpClient = &http.Client{Timeout: 30 * time.Second}
75 }
76
77 client := &Client{
78 logger: telemetryLogger,
79 userUUID: getUserUUID(),
80 desktopUUID: desktop.GetUUID(ctx),
81 enabled: enabled,
82 debugMode: debugMode,
83 httpClient: httpClient,
84 endpoint: endpoint,
85 apiKey: apiKey,
86 header: header,
87 version: version,
88 }
89
90 telemetryLogger.Debug("Enabled:", enabled)
91
92 return client
93}

Callers 12

TestNewClientFunction · 0.85
TestSessionTrackingFunction · 0.85
TestCommandTrackingFunction · 0.85
TestStructuredEventFunction · 0.85
TestAllEventTypesFunction · 0.85
TestTrackServerStartFunction · 0.85
TestTelemetryTagsFunction · 0.85

Calls 4

GetUUIDFunction · 0.92
NewTelemetryLoggerFunction · 0.85
getUserUUIDFunction · 0.85
DebugMethod · 0.80

Tested by 11

TestNewClientFunction · 0.68
TestSessionTrackingFunction · 0.68
TestCommandTrackingFunction · 0.68
TestStructuredEventFunction · 0.68
TestAllEventTypesFunction · 0.68
TestTrackServerStartFunction · 0.68
TestTelemetryTagsFunction · 0.68