generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Telemetry to MSCalendar * Update go.mod, move rudder client initialization, add rudder client closing, improve simplicity on NewRudderClient and add error logging to tracker * Add missing linebreak * Add dev credentials, missing telemetries, and make plugin implementation of the tracker more ubiquitous * Improve set status tracking * Add private and development key through environment variables, set "telemetryShortName" for the plugin and use "_" as separator instead of "-" * Move all makefile settings to custom.mk, and set production variable directly on CircleCI * Fix test * Change userID by UserActualID * Move tracking to the right place
- Loading branch information
Showing
15 changed files
with
218 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
# Include custom targets and environment variables here | ||
ifndef MM_RUDDER_WRITE_KEY | ||
MM_RUDDER_WRITE_KEY = 1d5bMvdrfWClLxgK1FvV3s4U1tg | ||
endif | ||
|
||
LDFLAGS += -X "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/telemetry.rudderWriteKey=$(MM_RUDDER_WRITE_KEY)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package mscalendarTracker | ||
|
||
import "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/telemetry" | ||
|
||
const ( | ||
welcomeFlowCompletionEvent = "welcomeFlowCompletion" | ||
userAuthenticatedEvent = "userAuthenticated" | ||
userDeauthenticatedEvent = "userDeauthenticated" | ||
automaticStatusUpdateEvent = "automaticStatusUpdate" | ||
dailySummarySentEvent = "dailySummarySent" | ||
) | ||
|
||
type Tracker interface { | ||
TrackWelcomeFlowCompletion(userID string) | ||
TrackUserAuthenticated(userID string) | ||
TrackUserDeauthenticated(userID string) | ||
TrackDailySummarySent(userID string) | ||
TrackAutomaticStatusUpdate(userID string, value bool, location string) | ||
} | ||
|
||
func New(t telemetry.Tracker) Tracker { | ||
return &tracker{ | ||
tracker: t, | ||
} | ||
} | ||
|
||
type tracker struct { | ||
tracker telemetry.Tracker | ||
} | ||
|
||
func (t *tracker) TrackWelcomeFlowCompletion(userID string) { | ||
t.tracker.TrackUserEvent(welcomeFlowCompletionEvent, userID, map[string]interface{}{}) | ||
} | ||
|
||
func (t *tracker) TrackUserAuthenticated(userID string) { | ||
t.tracker.TrackUserEvent(userAuthenticatedEvent, userID, map[string]interface{}{}) | ||
} | ||
|
||
func (t *tracker) TrackUserDeauthenticated(userID string) { | ||
t.tracker.TrackUserEvent(userDeauthenticatedEvent, userID, map[string]interface{}{}) | ||
} | ||
|
||
func (t *tracker) TrackDailySummarySent(userID string) { | ||
t.tracker.TrackUserEvent(dailySummarySentEvent, userID, map[string]interface{}{}) | ||
} | ||
|
||
func (t *tracker) TrackAutomaticStatusUpdate(userID string, value bool, location string) { | ||
properties := map[string]interface{}{ | ||
"value": value, | ||
"location": location, | ||
} | ||
t.tracker.TrackUserEvent(automaticStatusUpdateEvent, userID, properties) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package telemetry | ||
|
||
import rudder "github.com/rudderlabs/analytics-go" | ||
|
||
const rudderDataPlaneURL = "https://pdat.matterlytics.com" | ||
|
||
var rudderWriteKey string | ||
|
||
func NewRudderClient() (Client, error) { | ||
return NewRudderClientWithCredentials(rudderWriteKey, rudderDataPlaneURL) | ||
} | ||
|
||
func NewRudderClientWithCredentials(writeKey, dataPlaneURL string) (Client, error) { | ||
client, err := rudder.NewWithConfig(writeKey, dataPlaneURL, rudder.Config{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &rudderWrapper{client: client}, nil | ||
} | ||
|
||
type rudderWrapper struct { | ||
client rudder.Client | ||
} | ||
|
||
func (r *rudderWrapper) Enqueue(t Track) error { | ||
err := r.client.Enqueue(rudder.Track{ | ||
UserId: t.UserID, | ||
Event: t.Event, | ||
Properties: t.Properties, | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *rudderWrapper) Close() error { | ||
err := r.client.Close() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package telemetry | ||
|
||
import "github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot" | ||
|
||
type Tracker interface { | ||
Track(event string, properties map[string]interface{}) | ||
TrackUserEvent(event string, userID string, properties map[string]interface{}) | ||
} | ||
|
||
type Client interface { | ||
Enqueue(t Track) error | ||
Close() error | ||
} | ||
|
||
type Track struct { | ||
UserID string | ||
Event string | ||
Properties map[string]interface{} | ||
} | ||
|
||
type tracker struct { | ||
client Client | ||
diagnosticID string | ||
serverVersion string | ||
pluginID string | ||
pluginVersion string | ||
telemetryShortName string | ||
enabled bool | ||
logger bot.Logger | ||
} | ||
|
||
func NewTracker(c Client, diagnosticID, serverVersion, pluginID, pluginVersion, telemetryShortName string, enableDiagnostics bool, logger bot.Logger) Tracker { | ||
return &tracker{ | ||
telemetryShortName: telemetryShortName, | ||
client: c, | ||
diagnosticID: diagnosticID, | ||
serverVersion: serverVersion, | ||
pluginID: pluginID, | ||
pluginVersion: pluginVersion, | ||
enabled: enableDiagnostics, | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (t *tracker) Track(event string, properties map[string]interface{}) { | ||
if !t.enabled || t.client == nil { | ||
return | ||
} | ||
|
||
event = t.telemetryShortName + "_" + event | ||
properties["PluginID"] = t.pluginID | ||
properties["PluginVersion"] = t.pluginVersion | ||
properties["ServerVersion"] = t.serverVersion | ||
|
||
err := t.client.Enqueue(Track{ | ||
UserID: t.diagnosticID, | ||
Event: event, | ||
Properties: properties, | ||
}) | ||
|
||
if err != nil { | ||
t.logger.Warnf("cannot enqueue telemetry event, err=%s", err.Error()) | ||
} | ||
} | ||
|
||
func (t *tracker) TrackUserEvent(event string, userID string, properties map[string]interface{}) { | ||
properties["UserActualID"] = userID | ||
t.Track(event, properties) | ||
} |