@@ -24,6 +24,15 @@ type TelemetryMetrics struct {
2424 MessagesCount int `json:"messages_count"`
2525 ListsCount int `json:"lists_count"`
2626 APIEndpoint string `json:"api_endpoint"`
27+
28+ // Integration flags - boolean for each email provider
29+ Mailgun bool `json:"mailgun"`
30+ AmazonSES bool `json:"amazonses"`
31+ Mailjet bool `json:"mailjet"`
32+ SendGrid bool `json:"sendgrid"`
33+ Postmark bool `json:"postmark"`
34+ SMTP bool `json:"smtp"`
35+ S3 bool `json:"s3"`
2736}
2837
2938const (
@@ -82,7 +91,7 @@ func (t *TelemetryService) SendMetricsForAllWorkspaces(ctx context.Context) erro
8291
8392 // Collect and send metrics for each workspace
8493 for _ , workspace := range workspaces {
85- if err := t .sendMetricsForWorkspace (ctx , workspace . ID ); err != nil {
94+ if err := t .sendMetricsForWorkspace (ctx , workspace ); err != nil {
8695 // Continue with other workspaces on error
8796 }
8897 }
@@ -91,10 +100,10 @@ func (t *TelemetryService) SendMetricsForAllWorkspaces(ctx context.Context) erro
91100}
92101
93102// sendMetricsForWorkspace collects and sends telemetry metrics for a specific workspace
94- func (t * TelemetryService ) sendMetricsForWorkspace (ctx context.Context , workspaceID string ) error {
103+ func (t * TelemetryService ) sendMetricsForWorkspace (ctx context.Context , workspace * domain. Workspace ) error {
95104 // Create SHA1 hash of workspace ID
96105 hasher := sha1 .New ()
97- hasher .Write ([]byte (workspaceID ))
106+ hasher .Write ([]byte (workspace . ID ))
98107 workspaceIDSHA1 := hex .EncodeToString (hasher .Sum (nil ))
99108
100109 // Collect metrics
@@ -103,8 +112,11 @@ func (t *TelemetryService) sendMetricsForWorkspace(ctx context.Context, workspac
103112 APIEndpoint : t .apiEndpoint ,
104113 }
105114
106- // Get workspace database connection
107- db , err := t .workspaceRepo .GetConnection (ctx , workspaceID )
115+ // Set integration flags from workspace integrations
116+ t .setIntegrationFlagsFromWorkspace (workspace , & metrics )
117+
118+ // Get workspace database connection for counting metrics
119+ db , err := t .workspaceRepo .GetConnection (ctx , workspace .ID )
108120 if err != nil {
109121 // Continue without database metrics
110122 } else {
@@ -140,7 +152,7 @@ func (t *TelemetryService) sendMetricsForWorkspace(ctx context.Context, workspac
140152
141153// countContacts counts the total number of contacts in a workspace
142154func (t * TelemetryService ) countContacts (ctx context.Context , db * sql.DB ) (int , error ) {
143- query := `SELECT COUNT(DISTINCT email ) FROM contacts`
155+ query := `SELECT COUNT(* ) FROM contacts`
144156 var count int
145157 err := db .QueryRowContext (ctx , query ).Scan (& count )
146158 if err != nil {
@@ -184,7 +196,7 @@ func (t *TelemetryService) countMessages(ctx context.Context, db *sql.DB) (int,
184196
185197// countLists counts the total number of lists in a workspace
186198func (t * TelemetryService ) countLists (ctx context.Context , db * sql.DB ) (int , error ) {
187- query := `SELECT COUNT(*) FROM lists WHERE deleted_at IS NULL `
199+ query := `SELECT COUNT(*) FROM lists`
188200 var count int
189201 err := db .QueryRowContext (ctx , query ).Scan (& count )
190202 if err != nil {
@@ -193,6 +205,39 @@ func (t *TelemetryService) countLists(ctx context.Context, db *sql.DB) (int, err
193205 return count , nil
194206}
195207
208+ // setIntegrationFlagsFromWorkspace sets boolean flags for each integration type from workspace integrations
209+ func (t * TelemetryService ) setIntegrationFlagsFromWorkspace (workspace * domain.Workspace , metrics * TelemetryMetrics ) {
210+ // Iterate through workspace integrations and set flags based on email provider kind
211+ for _ , integration := range workspace .Integrations {
212+ if integration .Type == domain .IntegrationTypeEmail {
213+ switch integration .EmailProvider .Kind {
214+ case domain .EmailProviderKindMailgun :
215+ metrics .Mailgun = true
216+ case domain .EmailProviderKindSES :
217+ metrics .AmazonSES = true
218+ case domain .EmailProviderKindMailjet :
219+ metrics .Mailjet = true
220+ case domain .EmailProviderKindPostmark :
221+ metrics .Postmark = true
222+ case domain .EmailProviderKindSMTP :
223+ metrics .SMTP = true
224+ case domain .EmailProviderKindSparkPost :
225+ metrics .SendGrid = true // SparkPost maps to SendGrid for telemetry
226+ }
227+ }
228+ }
229+
230+ // Check if S3-compatible file storage is configured
231+ if t .isS3FileStorageConfigured (& workspace .Settings .FileManager ) {
232+ metrics .S3 = true
233+ }
234+ }
235+
236+ // isS3FileStorageConfigured checks if S3-compatible file storage is configured in workspace settings
237+ func (t * TelemetryService ) isS3FileStorageConfigured (fileManager * domain.FileManagerSettings ) bool {
238+ return fileManager .Endpoint != "" && fileManager .Bucket != "" && fileManager .AccessKey != ""
239+ }
240+
196241// sendMetrics sends the collected metrics to the telemetry endpoint
197242func (t * TelemetryService ) sendMetrics (ctx context.Context , metrics TelemetryMetrics ) error {
198243 // Marshal metrics to JSON
0 commit comments