text stringlengths 0 2.35k |
|---|
**Mat Ryer:** Yeah, on that question of consuming the logs then, Erik from the Gophers Slack - and by the way, everybody, don't forget, we're on Slack. You can join the chat live, GoTimeFM channel. Erik has done just that. Erik asks "Will the key-value pairs always be in the same order with logfmt?" Because I imagine ... |
**Ed Welch:** It's gonna be subject to whatever library implements that. In most of the applications that I work with, we use GoKit, and they're always consistently in order of the way that they're written. Like I said, the libraries that implement logfmt - JSON is more common, but I think there's support in others as ... |
So having consistency in your log output is a huge value for a human to parse. Machines tend to not care. Maybe there's some efficiency gains if they're consistent, but it would be a good feature to have, that's consistently orienting your -- and I think probably most JSON serializers are gonna be consistent. I think m... |
**Mat Ryer:** I imagine if you're passing in key-value pairs, it probably logs out in the order that you do it, and therefore it's up to you to make sure you're consistent in your code to get it right. And that thing of context is interesting... I have a project where we actually use the context to carry -- like, Go's ... |
**Ed Welch:** \[19:47\] Yeah, definitely. The applications that I work with do this pretty commonly. Trace ID is often propagated through the context; or is always propagated through the context. Something like a tenant ID in a multi-tenant system... And there's helper functions that we have that will pull that out to ... |
I wish Go went one step farther here... One of my griefs with Go is the context deadline exceeded, and context canceled errors, because in a distributed system you get a context deadline exceeded and I don't know who canceled that context, or what deadline rather exceeded or timed out... It could have been four systems... |
**Mat Ryer:** Yeah, that's a nice one. You could write a package that did that, couldn't you? |
**Ed Welch:** I thought about this last night... \[laughs\] I'm not sure what it would look like to -- I mean, you could do definitely something that catches it; where it's tricky is how easy and how organic would it be to use... Because a lot of times you're catching an error on a function, and you have no idea what t... |
As much as I love how well that context cancelation allows you to control over network connections and things, I find that it leaves a lot of times confusion around what piece of the puzzle was the one that actually said \[unintelligible 00:21:57.15\] |
**Mat Ryer:** Yeah, because in an HTTP world if you are getting a request and the browser -- like, someone just closes the browser, that'll cancel it. That'll cancel the request. And in your own code, you might be canceling context and relying on that, and then you can't tell the difference. |
**Ed Welch:** Yeah. My favorite is -- so like NGINX, or anybody that sits in the middle, that times out, will result in a context canceled error. I mean, in my argument here that would be not the most helpful, but somebody should know that it was their context that was canceled, and say "Hey, it's me over here. I don't... |
**Mat Ryer:** I wonder if you could pass a string into the cancel function... Because you get back -- when you do with the timeout, or the other one, with cancel, you get back the little cancel callback function thing. Could you pass in a string there, I wonder...? Actually, that's an interesting problem. It'd be quite... |
**Ed Welch:** I think the idea of how well and how useful the context is, but it does often lead -- I know when I first started writing Go, I found that I was doing a thing that was very Java-esque, because I really missed checked exceptions and I was trying to understand why an error... So I'm looking at the type of a... |
**Mat Ryer:** Yeah, you've gotta save it for the theme tune. They don't count unless it's been played. |
**Break:** \[23:43\] |
**Mat Ryer:** I usually end up having dedicated code for context errors at the top of -- wherever they unwind to, I'll have some code, because I probably want to do something different. And the other thing is - it's very normal to have context that gets canceled. It's a sentinel error, term coined by our friend and fri... |
**Ed Welch:** I would support that. |
**Mat Ryer:** Yeah. I'll do a PR. |
**Ed Welch:** It's something to think about for folks that are writing applications and they're using contexts - and they should be; there's the context -- you can add values to it, so take advantage of that. Like, most things probably don't get carried away, keep the context simple, but you could consider... I don't k... |
**Mat Ryer:** Yeah. Another interesting little thing that's quite nice to do in Go that I did once was when adding final use to the log, using those helpers that you talk about, that these packages have - that would also return a little cancel function, which you defer immediately, remove that value, essentially... Whi... |
**Ed Welch:** Yeah, I'm a little bit biased when it comes to the way we observe applications. I spend all of my time working on a system that's designed around handling logs, so... |
**Mat Ryer:** That's why you're here though, Ed. |
**Ed Welch:** \[27:49\] It's true, yeah. The nice thing about logging is it's kind of always there. It's the one most accessible way that we have to get info out of an application. The other forms that we have of observability tend to lend themselves to better use cases or different options... Distributed tracing can d... |
And there's another one, I think, when it comes to error messages. A lot of times, depending on how you structure your logging and whether your logger is gonna include the line number something comes from - I don't have strong opinions if you need to do that or not. Honestly, I would say just make sure you write error ... |
**Mat Ryer:** Yeah. Like monkey1, monkey2. |
**Ed Welch:** Exactly, yeah. So maybe you were really onto something there... \[laughs\] |
**Mat Ryer:** Well, that's why I use different numbers. |
**Ed Welch:** Yeah. How do you keep track of how many monkeys there are though? |
**Mat Ryer:** Yeah, that is difficult. To be fair, it gets way out of hand very quickly. |
**Ed Welch:** Do you have like a global monkey tracker that you...? |
**Mat Ryer:** You do need to implement that monkey tracking, yeah. And I did once mess up a loop and ended up with infinite monkeys... And they produced no works of any kind of discernable literature whatsoever, so - very disappointed there. |
**Ed Welch:** Yeah. One way with error messages that you can accomplish this uniqueness is the idea that you could consider error messages part of the runbooks for operating your system. So it's one thing to say something timed out, it's another to say that it timed out but that it's gonna retry; it's gonna retry ten t... |
It's funny, when you're writing applications and you get to where you're logging an error message, you likely have the most context of anybody that's gonna see that error message in years to come. So what can you put in there that helps someone make a decision about what they should do when they're operating that softw... |
**Mat Ryer:** I kind of love this about the UX of logs, is what we're really doing... And honestly, anytime I see a sophisticated approach in any field, they reach that sophistication by caring about the audience or the user of that thing. And it works for web UIs and APIs that you write in Go, and packages, programs..... |
**Ed Welch:** One other place that's been useful is propagated all the way back through your API. We have limits in our application that you can hit for various things. So we will log something like "You've exceeded this limit. Contact your administrator, or reach out to whoever administrates that." Or try again, or re... |
**Mat Ryer:** Hm. Would you link to like a runbook, or link to a doc even? |
**Ed Welch:** \[31:51\] I don't know, because my experience with that is that whatever you link to ultimately will break, and no one will ever go back and repair that link. It's very hard to maintain... If you can link it back to the source code in a pretty stable way... And can you have a linter or something that find... |
**Mat Ryer:** Good point. Yeah, keep itself contained; it's probably good advice. I once wrote a package for a co-worker. He was gonna then implement it. So we kind of broke the work up like that. And I customized all the errors, all the error messages just for him. So I was saying "Come on, mate... This is obviously. ... |
**Ed Welch:** \[laughs\] I've logged messages before that are along the lines of like "This shouldn't happen..." I wrote those log lines, which is -- my favorite was in Java, an exception handling of - you would catch an exception and then catch an exception within the exception, and in a lot of those cases I don't eve... |
Another consideration here would be - what would maybe make this easier if you pull your error strings into a central spot. If you're doing internationalization of your application, this can be helpful. There was some tooling that made that a little bit easier to swap filenames and you could just have your error messag... |
**Mat Ryer:** \[laughs\] Yeah. Well, on context then - maybe we could talk about log levels, because this is something else that is quite divisive subject I've seen around. This is where you can -- each line has a level, so it's usually debug, info, warning, error, critical... There's loads of options. I'm sure you've ... |
**Ed Welch:** So I have some opinions here... |
**Mat Ryer:** Are they popular or unpopular? |
**Ed Welch:** These are probably popular, but... |
**Mat Ryer:** Okay, I'll leave the music. |
**Ed Welch:** Not everyone will agree, but errors is the easiest one for me. So I can start at error and warn, and then it gets kind of murky from there. But the error levels - I like to log at an error level if there's something wrong with my application. It's my job, it's my responsibility to fix it. |
**Mat Ryer:** It makes sense. |
**Ed Welch:** I like to use warning level when it's not my responsibility or my job to fix it. So I'm getting bad data... Some other downstream system is misbehaving, something that is useful for me to go find, but it's gonna be more useful probably for somebody else than me. That's my opinion on that. |
Now, when you go beyond that -- so debug is really fascinating, because it ends up just being sort of the dumpster of log levels; everything ends up in there, and it usually ends up being so verbose that people don't run with it. And if you're not running with it - and most applications in my experiences don't have an ... |
So they can see the argument to seeing that you just log everything at sort of info, and that would force you to go back through and remove log lines that aren't as useful... But you do have these cases where -- I don't know, you write these log lines and instrument something in a way that's really interesting for spec... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.