Skip to content

Commit

Permalink
[MM-51269] Log errors from telemetry events (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Mar 23, 2023
1 parent ad1d267 commit 69abca9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
26 changes: 15 additions & 11 deletions server/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import (
"github.com/gorilla/mux"
pluginapi "github.com/mattermost/mattermost-plugin-api"
"github.com/mattermost/mattermost-plugin-api/experimental/flow"
"github.com/mattermost/mattermost-plugin-api/experimental/telemetry"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/pkg/errors"

"github.com/mattermost/mattermost-plugin-gitlab/server/gitlab"
)

type Tracker interface {
TrackEvent(event string, properties map[string]interface{})
TrackUserEvent(event, userID string, properties map[string]interface{})
}

type FlowManager struct {
client *pluginapi.Client
pluginURL string
Expand All @@ -25,7 +29,7 @@ type FlowManager struct {
getGitlabUserInfoByMattermostID func(userID string) (*gitlab.UserInfo, *APIErrorResponse)
getGitlabClient func() gitlab.Gitlab

tracker telemetry.Tracker
tracker Tracker

setupFlow *flow.Flow
oauthFlow *flow.Flow
Expand All @@ -43,7 +47,7 @@ func (p *Plugin) NewFlowManager() *FlowManager {
getGitlabUserInfoByMattermostID: p.getGitlabUserInfoByMattermostID,
getGitlabClient: p.getGitlabClient,

tracker: p.tracker,
tracker: p,
}

fm.setupFlow = fm.newFlow("setup").WithSteps(
Expand Down Expand Up @@ -216,14 +220,14 @@ func (fm *FlowManager) StartSetupWizard(userID string, delegatedFrom string) err
}

func (fm *FlowManager) trackStartSetupWizard(userID string, fromInvite bool) {
_ = fm.tracker.TrackUserEvent("setup_wizard_start", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("setup_wizard_start", userID, map[string]interface{}{
"from_invite": fromInvite,
"time": model.GetMillis(),
})
}

func (fm *FlowManager) trackCompleteSetupWizard(userID string) {
_ = fm.tracker.TrackUserEvent("setup_wizard_complete", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("setup_wizard_complete", userID, map[string]interface{}{
"time": model.GetMillis(),
})
}
Expand All @@ -242,13 +246,13 @@ func (fm *FlowManager) StartOauthWizard(userID string) error {
}

func (fm *FlowManager) trackStartOauthWizard(userID string) {
_ = fm.tracker.TrackUserEvent("oauth_wizard_start", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("oauth_wizard_start", userID, map[string]interface{}{
"time": model.GetMillis(),
})
}

func (fm *FlowManager) trackCompleteOauthWizard(userID string) {
_ = fm.tracker.TrackUserEvent("oauth_wizard_complete", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("oauth_wizard_complete", userID, map[string]interface{}{
"time": model.GetMillis(),
})
}
Expand Down Expand Up @@ -564,13 +568,13 @@ func (fm *FlowManager) StartWebhookWizard(userID string) error {
}

func (fm *FlowManager) trackStartWebhookWizard(userID string) {
_ = fm.tracker.TrackUserEvent("webhook_wizard_start", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("webhook_wizard_start", userID, map[string]interface{}{
"time": model.GetMillis(),
})
}

func (fm *FlowManager) trackCompleteWebhookWizard(userID string) {
_ = fm.tracker.TrackUserEvent("webhook_wizard_complete", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("webhook_wizard_complete", userID, map[string]interface{}{
"time": model.GetMillis(),
})
}
Expand Down Expand Up @@ -715,13 +719,13 @@ func (fm *FlowManager) StartAnnouncementWizard(userID string) error {
}

func (fm *FlowManager) trackStartAnnouncementWizard(userID string) {
_ = fm.tracker.TrackUserEvent("announcement_wizard_start", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("announcement_wizard_start", userID, map[string]interface{}{
"time": model.GetMillis(),
})
}

func (fm *FlowManager) trackCompletAnnouncementWizard(userID string) {
_ = fm.tracker.TrackUserEvent("announcement_wizard_complete", userID, map[string]interface{}{
fm.tracker.TrackUserEvent("announcement_wizard_complete", userID, map[string]interface{}{
"time": model.GetMillis(),
})
}
Expand Down
16 changes: 15 additions & 1 deletion server/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ const (
keysPerPage = 1000
)

func (p *Plugin) TrackEvent(event string, properties map[string]interface{}) {
err := p.tracker.TrackEvent(event, properties)
if err != nil {
p.API.LogDebug("Error sending telemetry event", "event", event, "error", err.Error())
}
}

func (p *Plugin) TrackUserEvent(event, userID string, properties map[string]interface{}) {
err := p.tracker.TrackUserEvent(event, userID, properties)
if err != nil {
p.API.LogDebug("Error sending user telemetry event", "event", event, "error", err.Error())
}
}

func (p *Plugin) SendDailyTelemetry() {
config := p.getConfiguration()

Expand All @@ -19,7 +33,7 @@ func (p *Plugin) SendDailyTelemetry() {
p.API.LogWarn("Failed to get the number of connected users for telemetry", "error", err)
}

_ = p.tracker.TrackEvent("stats", map[string]interface{}{
p.TrackEvent("stats", map[string]interface{}{
"connected_user_count": connectedUserCount,
"is_oauth_configured": config.IsOAuthConfigured(),
"is_sass": config.IsSASS(),
Expand Down

0 comments on commit 69abca9

Please sign in to comment.