48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright (c) 2020-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"git.wilix.dev/loop/loop-plugin-sentry/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
|
|
}
|