Skip to content

Commit

Permalink
fix: use Testkube logs for telemetry (#4014)
Browse files Browse the repository at this point in the history
* fix: use Testkube logs for telemetry

* fix: golint
  • Loading branch information
vsukhin authored Jun 12, 2023
1 parent e4a86db commit 7f4fe81
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/telemetry/sender_sio.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package telemetry

import (
"fmt"
"net/http"
"os"

"github.com/segmentio/analytics-go/v3"

"github.com/kubeshop/testkube/pkg/log"
)

const SegmentioEnvVariableName = "TESTKUBE_SEGMENTIO_KEY"
Expand All @@ -14,6 +17,21 @@ const CloudEnvVariableName = "TESTKUBE_CLOUD_API_KEY"
var SegmentioKey = "jELokNFNcLeQhxdpGF47PcxCtOLpwVuu"
var CloudSegmentioKey = ""

func StdLogger() analytics.Logger {
return stdLogger{}
}

type stdLogger struct {
}

func (l stdLogger) Logf(format string, args ...interface{}) {
log.DefaultLogger.Debugw("sending telemetry data", "info", fmt.Sprintf(format, args...))
}

func (l stdLogger) Errorf(format string, args ...interface{}) {
log.DefaultLogger.Debugw("sending telemetry data", "error", fmt.Sprintf(format, args...))
}

// SegmentioSender sends ananymous telemetry data to segment.io
// TODO refactor Sender func as out is not needed (use debug loggers to log output)
func SegmentioSender(client *http.Client, payload Payload) (out string, err error) {
Expand All @@ -28,7 +46,10 @@ func SegmentioSender(client *http.Client, payload Payload) (out string, err erro
}
}

segmentio := analytics.New(SegmentioKey)
segmentio, err := analytics.NewWithConfig(SegmentioKey, analytics.Config{Logger: StdLogger()})
if err != nil {
return out, err
}
defer segmentio.Close()

for _, event := range payload.Events {
Expand Down

0 comments on commit 7f4fe81

Please sign in to comment.