Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use Testkube logs for telemetry #4014

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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