diff --git a/pkg/telemetry/event.go b/pkg/telemetry/event.go index 766e7c908f..be226d80e7 100644 --- a/pkg/telemetry/event.go +++ b/pkg/telemetry/event.go @@ -9,30 +9,32 @@ const ( type Event interface { GetType() EventType - GetData() interface{} +} + +type CommandOption struct { + Name string `json:"name"` + AsCli bool `json:"asCli"` + AsEnv bool `json:"asEnv"` + Count int `json:"count"` } func NewCommandStarted(commandOptions []CommandOption) *CommandStarted { - return &CommandStarted{commandOptions: commandOptions} + return &CommandStarted{CommandOptions: commandOptions} } type CommandStarted struct { - commandOptions []CommandOption + CommandOptions []CommandOption `json:"commandOptions,omitempty"` } func (e *CommandStarted) GetType() EventType { return CommandStartedEvent } -func (e *CommandStarted) GetData() interface{} { - if len(e.commandOptions) > 0 { - return map[string]interface{}{"commandOptions": e.commandOptions} - } - return nil -} -func NewCommandExited(exitCode int) *CommandExited { return &CommandExited{exitCode: exitCode} } +func NewCommandExited(exitCode int, durationMs int64) *CommandExited { + return &CommandExited{ExitCode: exitCode, DurationMs: durationMs} +} type CommandExited struct { - exitCode int + ExitCode int `json:"exitCode"` + DurationMs int64 `json:"durationMs"` } -func (e *CommandExited) GetType() EventType { return CommandExitedEvent } -func (e *CommandExited) GetData() interface{} { return map[string]interface{}{"exitCode": e.exitCode} } +func (e *CommandExited) GetType() EventType { return CommandExitedEvent } diff --git a/pkg/telemetry/telemetrywerfio.go b/pkg/telemetry/telemetrywerfio.go index d59310b58d..da4f38c002 100644 --- a/pkg/telemetry/telemetrywerfio.go +++ b/pkg/telemetry/telemetrywerfio.go @@ -31,18 +31,12 @@ type TelemetryWerfIOInterface interface { CommandExited(ctx context.Context, exitCode int) } -type CommandOption struct { - Name string `json:"name"` - AsCli bool `json:"asCli"` - AsEnv bool `json:"asEnv"` - Count int `json:"count"` -} - type TelemetryWerfIO struct { handleErrorFunc func(err error) tracerProvider *sdktrace.TracerProvider traceExporter *otlptrace.Exporter + startedAt time.Time executionID string projectID string command string @@ -69,6 +63,7 @@ func NewTelemetryWerfIO(url string, opts TelemetryWerfIOOptions) (*TelemetryWerf ), traceExporter: e, executionID: uuid.New().String(), + startedAt: time.Now(), }, nil } @@ -124,7 +119,8 @@ func (t *TelemetryWerfIO) CommandStarted(ctx context.Context) { } func (t *TelemetryWerfIO) CommandExited(ctx context.Context, exitCode int) { - t.sendEvent(ctx, NewCommandExited(exitCode)) + duration := time.Now().Sub(t.startedAt) + t.sendEvent(ctx, NewCommandExited(exitCode, int64(duration/time.Millisecond))) } func (t *TelemetryWerfIO) getAttributes() map[string]interface{} { @@ -161,7 +157,7 @@ func (t *TelemetryWerfIO) sendEvent(ctx context.Context, event Event) error { span.SetAttributes(attribute.Key("eventType").String(string(event.GetType()))) - rawEventData, err := json.Marshal(event.GetData()) + rawEventData, err := json.Marshal(event) if err != nil { return fmt.Errorf("unable to marshal event data: %w", err) }