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

Use []runtime.Frame instead of exporting Stack (#45) #52

Merged
merged 4 commits into from
Mar 5, 2019
Merged

Use []runtime.Frame instead of exporting Stack (#45) #52

merged 4 commits into from
Mar 5, 2019

Conversation

fgblomqvist
Copy link
Contributor

This is my proposed solution to issue #45. I have tried to preserve as much as possible of the existing code structure to make it a less impactful change, but naturally it will be a breaking one no matter what. I concluded that it made the most sense to use []runtime.Frame instead of e.g. runtime.Frames or []uintptr. A runtime.Frame essentially holds the same information as the old Frame, with some additions.

With this change in place, it will be easier to extend the package to be able to get stack traces from other error interfaces, as well as to be able to take a stack trace straight (e.g. similar to what https://github.com/stvp/roll allows for).

While the tests are passing, I have yet to test it during some real usage. I'm planning on doing that over the next few days/week, and will report back once I know how it went (assuming this PR is still of interest).

For now, it depends on #51 simply because that's the kind of environment I've worked in. If that one isn't of interest, it shouldn't be hard to just rebase this onto master (and is something that I'll of course do in that case).

Open to feedback if there is any change/piece of code that isn't up to par/to your liking! :)

@jessewgibbs
Copy link

@fgblomqvist thanks for this too. We'll review shortly.

Stack is now stack and is solely used to convert
[]runtime.Frame into a json serializable struct.
@fgblomqvist
Copy link
Contributor Author

Rebased the PR since #51 got merged.

@rokob
Copy link
Contributor

rokob commented Feb 20, 2019

If we are making BuildStack private then we need to update some of the comments/docs:

rollbar.go
522:// Callers are required to call BuildStack on their own at the time the cause is wrapped.

doc.go
72:One can implement this interface for custom Error types to be able to build up a chain of stack traces. In order to get stack the correct stacks, callers must call BuildStack on their own at the time that the cause is wrapped. This is the least intrusive mechanism for gathering this information due to the decisions made by the Go runtime to not track this information.

transforms.go Outdated
@@ -191,10 +192,10 @@ func filterIp(ip string, captureIp captureIp) string {
// method, the causes will be traversed until nil.
func errorBody(configuration configuration, err error, skip int) (map[string]interface{}, string) {
var parent error
traceChain := []map[string]interface{}{}
var traceChain []map[string]interface{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry it was just a reflex to change that due to my IDE complaining about declaring an empty slice with a literal. I believe it's considered a good convention to use nil declarations (https://stackoverflow.com/a/29164565/998919), but by all means, I can revert it if this project prefers the other (previous) style.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that we always append something to it so this change is okay. The one difference is that for JSON serialization the nil slice becomes null and the empty slice becomes [] and the backend will treat those differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I did pay attention to this in at least one other spot, to make sure we get [] in the JSON. Hmm I do feel now that the benefit of leaving that line as-is (e.g. what it originally was) outweighs the benefit of not allocating it (since we do "always" append to it, assuming no errors occur). I'm thinking if the code changes down the line it might become a frustrating error in case a nil slice slips through to the JSON marshaling. I'm gonna go ahead and revert it if that's fine.

@fgblomqvist
Copy link
Contributor Author

@rokob I'll do the docs changes (to the best of my knowledge) and push up in a moment, thanks for the suggestion

stack.go Outdated
func BuildStack(skip int) Stack {
stack := make(Stack, 0)
// buildStack converts []runtime.Frame into a JSON serializable slice of frames
// optionally skipping the number of frames specified by the input skip argument.
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get rid of the "optionally skipping ..." as we are not taking a skip argument anymore.

Copy link
Contributor

@rokob rokob left a comment

Choose a reason for hiding this comment

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

Small doc change, otherwise this LGTM

@fgblomqvist
Copy link
Contributor Author

@rokob Thanks, done.

@rokob rokob merged commit eb32617 into rollbar:master Mar 5, 2019
@fgblomqvist fgblomqvist deleted the feature/generalize-stack branch June 11, 2019 01:17
@mmlb
Copy link

mmlb commented Jun 11, 2019

Too late now I'd say, but this should have been released as a major version bump as it breaks previously compiling code.

@fgblomqvist
Copy link
Contributor Author

fgblomqvist commented Jun 11, 2019

@mmlb It should. I take part of the blame (I should have suggested that), but yeah, too late now.
(that being said, idk if this projected explicitly stated anywhere that it's using SemVar so theoretically it wasn't wrong releasing it as a minor point release)

@mmlb
Copy link

mmlb commented Jun 11, 2019

🤷‍♂️

@mmlb
Copy link

mmlb commented Jun 11, 2019

Looking forward to updating to this code though :D

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