Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report panics to Sentry #744

Merged
merged 3 commits into from
Apr 25, 2023
Merged

feat: report panics to Sentry #744

merged 3 commits into from
Apr 25, 2023

Conversation

eneskaya
Copy link
Contributor

@eneskaya eneskaya commented Apr 24, 2023

Unfortunately there is some boilerplate required for this to work when it comes to go routines.

@eneskaya eneskaya requested a review from mlabouardy April 24, 2023 12:07
@@ -261,104 +262,247 @@ func doMigrations(ctx context.Context) error {
func fetchResources(ctx context.Context, clients []providers.ProviderClient, regions []string, telemetry bool) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be refactored to avoid duplicated code. Proposal:

func fetchResources(ctx context.Context, clients []providers.ProviderClient, regions []string, telemetry bool) error {
	for _, client := range clients {
		if client.AWSClient != nil {
			go triggerFetchingWorfklow(ctx, client, "AWS", telemetry, regions, sentry.CurrentHub().Clone())
		} else if client.ScalewayClient != nil {
			go triggerFetchingWorfklow(ctx, client, "Scaleway", telemetry, regions, sentry.CurrentHub().Clone())
		} else if client.MongoDBAtlasClient != nil {
		...
}

func triggerFetchingWorfklow(ctx context.Context, client providers.ProviderClient, provider string, telemetry bool, regions []string, localHub *sentry.Hub) {
	defer func() {
		err := recover()
		log.WithField("err", err).Error(fmt.Sprintf("error fetching %s resources", provider))
		if err != nil {
			localHub.CaptureException(err.(error))
			localHub.Flush(2 * time.Second)
		}
	}()

	localHub.ConfigureScope(func(scope *sentry.Scope) {
		scope.SetTag("provider", provider)
	})

	if telemetry {
		analytics.TrackEvent("fetching_resources", map[string]interface{}{
			"provider": provider,
		})
	}

	switch provider {
	case "AWS":
		aws.FetchResources(ctx, client, regions, db, telemetry, analytics)
	case "Scaleway":
		scaleway.FetchResources(ctx, client, db, telemetry, analytics)
	}
}

@mlabouardy mlabouardy added this to the v3.0.14 milestone Apr 25, 2023
@eneskaya eneskaya requested a review from mlabouardy April 25, 2023 12:02
Copy link
Collaborator

@mlabouardy mlabouardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good 🚀

@mlabouardy mlabouardy merged commit bd0747b into develop Apr 25, 2023
@mlabouardy mlabouardy deleted the feature/tech-1082 branch April 25, 2023 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants