TrackServerStart immediately sends telemetry for server startup, then runs the server function (test-only method) This is for long-running commands that may never exit (api, mcp, etc.)
(ctx context.Context, commandInfo CommandInfo, fn func(context.Context) error)
| 293 | // TrackServerStart immediately sends telemetry for server startup, then runs the server function (test-only method) |
| 294 | // This is for long-running commands that may never exit (api, mcp, etc.) |
| 295 | func (tc *Client) TrackServerStart(ctx context.Context, commandInfo CommandInfo, fn func(context.Context) error) error { |
| 296 | if !tc.enabled { |
| 297 | return fn(ctx) |
| 298 | } |
| 299 | |
| 300 | ctx = WithClient(ctx, tc) |
| 301 | |
| 302 | // Send startup event immediately |
| 303 | startupEvent := CommandEvent{ |
| 304 | Action: commandInfo.Action, |
| 305 | Args: commandInfo.Args, |
| 306 | Success: true, // We assume startup succeeds if we reach this point |
| 307 | } |
| 308 | |
| 309 | // Send the startup telemetry event immediately |
| 310 | tc.Track(ctx, &startupEvent) |
| 311 | |
| 312 | // Now run the server function (which may run indefinitely) |
| 313 | return fn(ctx) |
| 314 | } |
| 315 | |
| 316 | // TestAllEventTypes tests all possible telemetry events with mock HTTP client |
| 317 | func TestAllEventTypes(t *testing.T) { |
no test coverage detected