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

apptracker: Error tracking interface and it's Sentry implementation #34

Merged
merged 14 commits into from
Sep 13, 2024

Conversation

gouthamp-stellar
Copy link
Contributor

@gouthamp-stellar gouthamp-stellar commented Aug 11, 2024

What

Error tracking interface and it's Sentry implementation

Task: https://app.asana.com/0/1207947010297920/1207245825676510

Why

Adding sentry tracking to the Wallet Backend

Known limitations

N/A

Issue that this PR addresses

https://app.asana.com/0/1207947010297920/1207245825676510

Checklist

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

gsoarescosta

This comment was marked as outdated.

Copy link
Contributor

@CaioTeixeira95 CaioTeixeira95 left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. I've left a few comments.

}
}

func StellarEnvironmentOption(configKey *string) *config.ConfigOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this environment? What's used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sentry needs a variable called Environment when you call sentry.Init(...) and this basically sets the value for that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used to set up the sentry environment which is a variable we need to initialize the sentry tracker

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use the Network Passphrase for that, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like we use the sentry environment variable to initialize the tracker in the Vibrant backend so I did the same here

Copy link
Member

Choose a reason for hiding this comment

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

@gouthamp-stellar this is something we're refactoring on the Vibrant backend. Unfortunately we have this duplicate ENV there.
Wdyt about using the Network Passphrase env that we already use for ingestion (like @CaioTeixeira95 suggested) and mapping it to testnet/development or mainnet/production in the NewSentryTracker function.
That way we don't have this duplicate config which at the end of the day means the same thing.

Copy link
Member

@daniel-burghardt daniel-burghardt Sep 12, 2024

Choose a reason for hiding this comment

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

If not maybe we can at least name the env something like TRACKER_ENVIRONMENT so it's not misused in other places interchangeably with NETWORK_PASSPHRASE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Down to do that in a future pr. I already pushed a pr to kube-vibrant with this env variable. Since it's only a couple lines, I can add this change to an upcoming pr

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a DryRunAppTracker? This would only log on the Stdout, this is useful for local development environments, so we don't need to use a sentry account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense. done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 29 to 31
AppTracker sentry.SentryTracker
SentryDsn string
StellarEnvironment string
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest we only have the app tracker here. Then on the config we only use a local variable:

var sentryDSN string

utils.SentryOptions(&sentryDSN)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -151,6 +154,7 @@ func TestRecoverHandler(t *testing.T) {
req, err := http.NewRequest("GET", "/", nil)
require.NoError(t, err)
rr := httptest.NewRecorder()
appTrackerMock.On("CaptureException", mock.Anything).Return(nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

The same suggestion that I've made on the InternalServerError, can we test the error value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 13 to 19
func (s *SentryTracker) CaptureMessage(message string) {
sentry.CaptureMessage(message)
}

func (s *SentryTracker) CaptureException(exception error) {
sentry.CaptureException(exception)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add tests for these methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@gouthamp-stellar gouthamp-stellar changed the title Error tracking interface and it's Sentry implementation apptracker: Error tracking interface and it's Sentry implementation Aug 27, 2024
Copy link
Contributor

@CaioTeixeira95 CaioTeixeira95 left a comment

Choose a reason for hiding this comment

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

Overall, it looks good to me. Please solve the remaining commentaries before merging it.

cmd/ingest.go Outdated
}
appTracker, err := sentry.NewSentryTracker(sentryDSN, stellarEnvironment, 5)
if err != nil {
log.Fatalf("Error initializing App Tracker: %s", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Fatalf("Error initializing App Tracker: %s", err.Error())
return fmt.Errorf("initializing app tracker: %w", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

cmd/ingest.go Outdated
if err != nil {
log.Fatalf("Error initializing App Tracker: %s", err.Error())
}
cfg.AppTracker = *appTracker
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you should pass the reference because it is an interface!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it
cfg.AppTracker = appTracker

cmd/serve.go Outdated
if err != nil {
return fmt.Errorf("initializing App Tracker: %w", err)
}
cfg.AppTracker = *appTracker
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you should pass the reference because it's an interface!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it
cfg.AppTracker = appTracker

)

type SentryTracker struct {
FlushFreq int64
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this value, it seems it's not being used. Shall we remove it?

Copy link
Contributor

Choose a reason for hiding this comment

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

that's a good point, where are we using it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, removed

@@ -25,6 +26,7 @@ type Configs struct {
StartLedger int
EndLedger int
LogLevel logrus.Level
AppTracker sentry.SentryTracker
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you should use the interface!

Suggested change
AppTracker sentry.SentryTracker
AppTracker apptracker.AppTracker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -57,6 +59,9 @@ type Configs struct {
HorizonClientURL string
DistributionAccountSignatureClient signing.SignatureClient
ChannelAccountSignatureClient signing.SignatureClient

// Error Tracker
AppTracker sentry.SentryTracker
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you should use the apptracker.AppTracker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@gouthamp-stellar gouthamp-stellar merged commit a74bc67 into main Sep 13, 2024
5 checks passed
@gouthamp-stellar gouthamp-stellar deleted the apptracker branch September 13, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants