MCPcopy
hub / github.com/cortexlabs/cortex / Init

Function Init

pkg/lib/telemetry/telemetry.go:81–131  ·  view source on GitHub ↗
(telemetryConfig Config)

Source from the content-addressed store, hash-verified

79}
80
81func Init(telemetryConfig Config) error {
82 if !telemetryConfig.Enabled {
83 _config = nil
84 return nil
85 }
86
87 if telemetryConfig.UserID == "" {
88 return ErrorUserIDNotSpecified()
89 }
90
91 err := sentry.Init(sentry.ClientOptions{
92 Dsn: getSentryDSN(),
93 Release: consts.CortexVersion,
94 Environment: telemetryConfig.Environment,
95 })
96 if err != nil {
97 _config = nil
98 return err
99 }
100
101 var segmentLogger analytics.Logger
102 if !telemetryConfig.LogErrors {
103 sentry.Logger.SetOutput(silentSentryLogger{})
104 segmentLogger = silentSegmentLogger{}
105 }
106
107 writeKey := _segmentWriteKey
108 if envVar := os.Getenv("CORTEX_TELEMETRY_SEGMENT_WRITE_KEY"); envVar != "" {
109 writeKey = envVar
110 }
111
112 _segment, err = analytics.NewWithConfig(writeKey, analytics.Config{
113 BatchSize: 1,
114 Logger: segmentLogger,
115 DefaultContext: &analytics.Context{
116 App: analytics.AppInfo{
117 Version: consts.CortexVersion,
118 },
119 Device: analytics.DeviceInfo{
120 Type: telemetryConfig.Environment,
121 },
122 },
123 })
124 if err != nil {
125 _config = nil
126 return err
127 }
128
129 _config = &telemetryConfig
130 return nil
131}
132
133func Event(name string, properties ...map[string]interface{}) {
134 integrations := map[string]interface{}{

Callers 7

InitFunction · 0.92
initTelemetryFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92

Calls 2

ErrorUserIDNotSpecifiedFunction · 0.85
getSentryDSNFunction · 0.85

Tested by

no test coverage detected