Your example of anesthesia during surgery is a good one. For most people, the trade off between the suffering incurred during surgery versus giving up a few hours of consciousness is an easy one: they take the anesthetic. This is a rational choice that people are making that non-experience is better than a bad experience. So you could naively continue this train of thought inductively on for infinity if you expected the rest of your existence to be at such a level of suffering.
There are a few objections to this simple argument, but I argue that they are all resolvable.
Objection 1: There are diminishing returns on additional suffering.
I don't entirely disagree with this point, I think people tend to adjust to bad conditions and can learn to be happy even in objectively horrible situations. However, there a few considerations. Many people who choose euthanasia are terminally ill. This leaves little time to adjust to the poor conditions under which they are living, so what might be a relatively brief period of suffering for someone with their whole life ahead of them is actually a life consuming amount of time.
Walking into conjecture territory, I suspect that the diminishing returns for some conditions bottom out at somewhere nonzero. That is to say, even though it gets better it doesn't necessarily get good or even bearable.
Objection 2: This only applies to finite timescales, but death is infinite.
As I understand this objection, a terminal value against permanent nonexistence. As such, it is difficult to argue against without discussing more meta-ethical considerations.
Fortunately for my argument, we all die eventually anyway. Dying now instead of later is still only a finite loss of consciousness similar to going under anesthetic (though generally longer). When the transhumanists achieve immortality or if the theists end up being right about the afterlife, it will become more important to discuss whether it is a good terminal value or not.
Objection 3: There is a moral difference between being unconscious and being dead.
I'm going to unpack this one with care, because this is moral rats nest.
In one sense, this is trivially true. A person who is unconscious will eventually wake up. This has some obvious moral implications, like it being okay to bury a dead person underground but not an unconscious person.
There is also the question of whether they are experientially different. This is true in the case of sleeping, since most people dream. Under anesthetic people rarely remember dreaming. In the end, I do not think this is an important distinction because people would choose anesthetic whether or not they experienced anything (as demonstrated by the apparent lack of sensation)
A relevant question is whether it is acceptable to pull the plug on brain dead individuals. I don't know if I have ever heard anyone say that this is unacceptable, but YMMV.
In the end I don't have an irrefutable counterargument against this, but I fund it unconvincing.
Objection 4: Anesthesia is helps the future, not just the present.
There are two ways to go with this.
One way is the argument that even temporary pain has lasting effects, so preventing pain in the short term enables greater happiness in the future. While this is not a contradiction, I do not think it matches reality. Consider the choice between taking an anesthetic so you experience nothing, and undergoing surgery without anesthetic but taking an amnesiac after so that you forget the experience (for the sake of the thought experiment, assume it works perfectly). It is a rare person who would choose the second one, even though by the assumption of the argument it ought to be strictly better.
The other line of argument is that being under anesthetic makes surgery less likely to go wrong. This is actually actively false for many surgeries, and anesthetic increases the risk of complication (this was especially true in the past). This fails to pass a reality check.
Conclusion: If you accept that undergoing anesthesia is a rational decision, it directly follows that euthanasia can also be rational, unless you strongly value existence in a vegetative state.