init
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2020-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"git.wilix.dev/loop/loop-plugin-starter-template/server/telemetry"
|
||||
)
|
||||
|
||||
func (p *Plugin) uninitTelemetry() error {
|
||||
p.mut.Lock()
|
||||
defer p.mut.Unlock()
|
||||
if p.telemetry == nil {
|
||||
return nil
|
||||
}
|
||||
return p.telemetry.Close()
|
||||
}
|
||||
|
||||
func (p *Plugin) initTelemetry(enableDiagnostics *bool) error {
|
||||
p.mut.Lock()
|
||||
defer p.mut.Unlock()
|
||||
if p.telemetry == nil && enableDiagnostics != nil && *enableDiagnostics {
|
||||
p.API.LogDebug("Initializing telemetry")
|
||||
// setup telemetry
|
||||
client, err := telemetry.NewClient(telemetry.ClientConfig{
|
||||
WriteKey: rudderWriteKey,
|
||||
DataplaneURL: rudderDataplaneURL,
|
||||
DiagnosticID: p.API.GetDiagnosticId(),
|
||||
DefaultProps: map[string]any{
|
||||
"ServerVersion": p.API.GetServerVersion(),
|
||||
"PluginBuild": buildHash,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.telemetry = client
|
||||
} else if p.telemetry != nil && (enableDiagnostics == nil || !*enableDiagnostics) {
|
||||
p.API.LogDebug("Deinitializing telemetry")
|
||||
// destroy telemetry
|
||||
if err := p.telemetry.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
p.telemetry = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user