Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Another way to try to be on spec! #19

Closed
wants to merge 20 commits into from
Closed

Another way to try to be on spec! #19

wants to merge 20 commits into from

Conversation

taylortrimble
Copy link
Contributor

Remember #14? It was all about trying to pass additional info into the Capture* methods. Unfortunately, the way I chose to do it (variadics pulled apart by type switches) wasn't type safe, which isn't great.

However, there is an obvious way to make type safety work: instead of variadics, just introduce the ability to merge packets.

Current master
func (client *Client) CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string

Only allows tags and interfaces 😦

Bad Variadic Solution
func (client *Client) CaptureMessage(message string, attr ...interface{}) string

Not type safe like at all 😩

This Pull Request
func (client *Client) CaptureMessage(message string, packetToMerge *Packet) string

The actual signature is a little more descriptive, but this does everything both of us want (I think)! ☺️

What's Next

Before I get going on:

  • Fixing the tests
  • Writing new tests
  • Adding the in-code documentation

I want to know what you think of this direction! Like last time, the change isn't as big as it looks. Mainly, Capture* methods now take what used to be a Packet in and merging happens now. Client also dispenses the packets like last time. writer.go nicely demos how this looks:

w.Client.CaptureMessage(string(p), &EventInfo{Level: w.Level, Logger: w.Logger})

I ended up renaming some things to make more sense to me, and factoring things into different files while trying to make sense of the world 😉 but I I did like the changes in the end.

Thanks for looking this over again! Let me know if you have any questions.


Closes #19

Includes ability to merge event info. That’s pretty much it. A refactor
thrown in while I was trying to make sense of life.
@taylortrimble
Copy link
Contributor Author

Oops, fixed a big bug. Wasn't merging interfaces. Okay now.

@taylortrimble
Copy link
Contributor Author

Hey @titanous, let me know what you think of all this! Thanks!

@titanous
Copy link
Contributor

titanous commented Jan 6, 2014

@tylrtrmbl Sorry for not getting to this quickly, it might be a couple more days. My week is really busy.

@taylortrimble
Copy link
Contributor Author

@titanous np, just checking in. Good luck with your things! 🍀

// when client is nil. A channel is provided if it is important to check for a
// send's success.
func (client *Client) Capture(packet *Packet, captureTags map[string]string) (eventID string, ch chan error) {
func (client *Client) Capture(message string, eventInfo *EventInfo) (eventID string, ch chan error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between Capture and CaptureMessage, their signatures are the same. I don't think Capture should take a message.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to call this Send? Should it be capturing anything? Isn't it what all of the Capture* methods use to actually send the packet after building 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.

I added Capture for parity with the Python client. I messed up the signature badly though. Will change it and let you know.

It might also make sense to see if it just becomes Send.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. This might be ready to take a look at.

@titanous
Copy link
Contributor

Overall I think this is a reasonable approach, let me know when you want me to do a complete review.

if res.StatusCode != 200 {
return fmt.Errorf("raven: got http status %d", res.StatusCode)

// Merge interfaces together
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, shouldn't all of this merging code be in event.go with the rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was different because it was "defaults", but this is done differently now and is more obvious. thank you for catching that!

@mattrobenolt
Copy link
Contributor

Regarding the signature, is there somethign wrong with doing:

func (client *Client) CaptureMessage(message string, contexts ...*Context) string

That way you can utilize context/types/merging, and still keep the signature variadic. This will allow both the common case of:

client.CaptureMessage("lol broken")

and

client.CaptureMessage("lol broken", &Context{Level: "error"})

@taylortrimble
Copy link
Contributor Author

I like that. It's sort of a marriage of #14 and this one, and is sort of like how we do "optional interfaces" right now.

@mattrobenolt
Copy link
Contributor

That's generally how the other clients work, and imo, it'd be awkward to need to define an "empty" object if you're not passing anything. The "extra" is just that. They're meant to be optional.

So the normal case is typically: client.CaptureMessage("lol broken")

And it'd be awkward to have to switch to a different method entirely to do something like: client.CaptureMessageWithContext("lol broken", &Context{...})

And just as awkward would be: client.CaptureMessage("lol broken", &Context{})

Just to satisfy the signature.

This approach could also technically allow passing a bunch of contexts (for whatever reason) and merge them all together.

So client.CaptureMessage("lol broken", &Context{...}, &Context{...}) would be a thing you could do.

@taylortrimble
Copy link
Contributor Author

Right on. ✌️ Fully with ya.

@titanous
Copy link
Contributor

titanous commented Feb 5, 2014

+1, I like this approach.

@mattrobenolt
Copy link
Contributor

Anything I can do to help with this?

@taylortrimble
Copy link
Contributor Author

I'm coming back. I have a clear vision for how I'd like to finish this pull request, so the best thing you all can do to help is be available to give me feedback!

I am committed to finishing this for the new year. Keep me honest!

Also initialize events in *Event method

Also rename EventInfo to Event throughout.
Need some tests for merging. I keep getting them backwards and that
needs to break shit.
@taylortrimble
Copy link
Contributor Author

Made some progress on this today, addressed some feedback. Not ready for a second round of review though; will let you know!

Conflicts:
  client.go
  client_test.go

Had to manually move some code that got copied into new files.
Hopefully I got everything!

Here’s what changed in master since I started:
https://github.com/getsentry/raven-go/compare/30337dc77126a66b25ac836918
f31b63f10f969a...master
Remove CheckError example: need to replace with better example that
makes better use of CaptureError and uses a persistent client.
@taylortrimble
Copy link
Contributor Author

Holy passing tests batman! Still not ready for a good set of eyes, should be in a few days. Just wanted to celebrate this finally turning into a check mark. 😄

@taylortrimble
Copy link
Contributor Author

@mattrobenolt's awesome API is now implemented! 💃

If you're feeling adventurous, you can dig in and try to look at the code as it is right now. I think I've done what I wanted to do with actual implementation.

I still need to:

  • Clean up
  • Write tests
  • Improve the README, especially to document the Capture* methods
  • Improve the examples

Expect these to come over the next couple days, followed by a request for a thorough review. Since this touches most of the existing code, I'm expecting to have to make changes!

@MrSaints
Copy link

MrSaints commented May 2, 2016

What's the ETA on this PR? Is it going to be merged / continued any time soon? Anything we can do to help?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants