@@ -71,7 +71,6 @@ func NewTelemetryService(config TelemetryServiceConfig) *TelemetryService {
7171// SendMetricsForAllWorkspaces collects and sends telemetry metrics for all workspaces
7272func (t * TelemetryService ) SendMetricsForAllWorkspaces (ctx context.Context ) error {
7373 if ! t .enabled {
74- t .logger .Debug ("Telemetry is disabled, skipping metrics collection" )
7574 return nil
7675 }
7776
@@ -81,15 +80,10 @@ func (t *TelemetryService) SendMetricsForAllWorkspaces(ctx context.Context) erro
8180 return fmt .Errorf ("failed to list workspaces: %w" , err )
8281 }
8382
84- t .logger .WithField ("workspace_count" , len (workspaces )).Info ("Collecting telemetry metrics for workspaces" )
85-
8683 // Collect and send metrics for each workspace
8784 for _ , workspace := range workspaces {
8885 if err := t .sendMetricsForWorkspace (ctx , workspace .ID ); err != nil {
89- // Log error but continue with other workspaces
90- t .logger .WithField ("workspace_id" , workspace .ID ).
91- WithField ("error" , err ).
92- Error ("Failed to send telemetry metrics for workspace" )
86+ // Continue with other workspaces on error
9387 }
9488 }
9589
@@ -112,53 +106,30 @@ func (t *TelemetryService) sendMetricsForWorkspace(ctx context.Context, workspac
112106 // Get workspace database connection
113107 db , err := t .workspaceRepo .GetConnection (ctx , workspaceID )
114108 if err != nil {
115- t .logger .WithField ("workspace_id" , workspaceID ).
116- WithField ("error" , err ).
117- Warn ("Failed to get workspace database connection for telemetry" )
118109 // Continue without database metrics
119110 } else {
120111 // Count contacts
121- if contactsCount , err := t .countContacts (ctx , db ); err != nil {
122- t .logger .WithField ("workspace_id" , workspaceID ).
123- WithField ("error" , err ).
124- Warn ("Failed to count contacts for telemetry" )
125- } else {
112+ if contactsCount , err := t .countContacts (ctx , db ); err == nil {
126113 metrics .ContactsCount = contactsCount
127114 }
128115
129116 // Count broadcasts
130- if broadcastsCount , err := t .countBroadcasts (ctx , db ); err != nil {
131- t .logger .WithField ("workspace_id" , workspaceID ).
132- WithField ("error" , err ).
133- Warn ("Failed to count broadcasts for telemetry" )
134- } else {
117+ if broadcastsCount , err := t .countBroadcasts (ctx , db ); err == nil {
135118 metrics .BroadcastsCount = broadcastsCount
136119 }
137120
138121 // Count transactional notifications
139- if transactionalCount , err := t .countTransactional (ctx , db ); err != nil {
140- t .logger .WithField ("workspace_id" , workspaceID ).
141- WithField ("error" , err ).
142- Warn ("Failed to count transactional notifications for telemetry" )
143- } else {
122+ if transactionalCount , err := t .countTransactional (ctx , db ); err == nil {
144123 metrics .TransactionalCount = transactionalCount
145124 }
146125
147126 // Count messages
148- if messagesCount , err := t .countMessages (ctx , db ); err != nil {
149- t .logger .WithField ("workspace_id" , workspaceID ).
150- WithField ("error" , err ).
151- Warn ("Failed to count messages for telemetry" )
152- } else {
127+ if messagesCount , err := t .countMessages (ctx , db ); err == nil {
153128 metrics .MessagesCount = messagesCount
154129 }
155130
156131 // Count lists
157- if listsCount , err := t .countLists (ctx , db ); err != nil {
158- t .logger .WithField ("workspace_id" , workspaceID ).
159- WithField ("error" , err ).
160- Warn ("Failed to count lists for telemetry" )
161- } else {
132+ if listsCount , err := t .countLists (ctx , db ); err == nil {
162133 metrics .ListsCount = listsCount
163134 }
164135 }
@@ -242,56 +213,34 @@ func (t *TelemetryService) sendMetrics(ctx context.Context, metrics TelemetryMet
242213 // Send request (will fail silently if endpoint is offline due to 5s timeout)
243214 resp , err := t .httpClient .Do (req )
244215 if err != nil {
245- // Log the error but don't return it to fail silently
246- t .logger .WithField ("workspace_id_sha1" , metrics .WorkspaceIDSHA1 ).
247- WithField ("error" , err ).
248- Debug ("Failed to send telemetry metrics (endpoint may be offline)" )
249216 return nil // Fail silently as requested
250217 }
251218 defer resp .Body .Close ()
252219
253220 // Check response status
254221 if resp .StatusCode >= 400 {
255- t .logger .WithField ("workspace_id_sha1" , metrics .WorkspaceIDSHA1 ).
256- WithField ("status_code" , resp .StatusCode ).
257- Debug ("Telemetry endpoint returned error status" )
258222 return nil // Fail silently as requested
259223 }
260224
261- t .logger .WithField ("workspace_id_sha1" , metrics .WorkspaceIDSHA1 ).
262- WithField ("contacts_count" , metrics .ContactsCount ).
263- WithField ("broadcasts_count" , metrics .BroadcastsCount ).
264- WithField ("transactional_count" , metrics .TransactionalCount ).
265- WithField ("messages_count" , metrics .MessagesCount ).
266- WithField ("lists_count" , metrics .ListsCount ).
267- Debug ("Successfully sent telemetry metrics" )
268-
269225 return nil
270226}
271227
272228// StartDailyScheduler starts a goroutine that sends telemetry metrics daily
273229func (t * TelemetryService ) StartDailyScheduler (ctx context.Context ) {
274230 if ! t .enabled {
275- t .logger .Debug ("Telemetry is disabled, not starting daily scheduler" )
276231 return
277232 }
278233
279234 go func () {
280235 ticker := time .NewTicker (24 * time .Hour )
281236 defer ticker .Stop ()
282237
283- t .logger .Info ("Started daily telemetry scheduler" )
284-
285238 for {
286239 select {
287240 case <- ctx .Done ():
288- t .logger .Info ("Stopping daily telemetry scheduler" )
289241 return
290242 case <- ticker .C :
291- t .logger .Debug ("Daily telemetry tick - collecting metrics" )
292- if err := t .SendMetricsForAllWorkspaces (ctx ); err != nil {
293- t .logger .WithField ("error" , err ).Error ("Failed to send daily telemetry metrics" )
294- }
243+ t .SendMetricsForAllWorkspaces (ctx )
295244 }
296245 }
297246 }()
0 commit comments