question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.label() Method throws Exceptions

See original GitHub issue

Apparently if labels are missing or a null value is supplied to a label the prometheus client will throw a IllegalArgumentException.

Exceptions being thrown on the “hot” path with null values in labels are a problem as they either require me to add try/catch logic around my monitoring code or decorate the whole prometheus client with try/catch blocks.

IMO there are a ton of instances where you might have a label that is not compile-time supplied (I know in most examples it’s the HTTP method being passed). But for a lot of cases it could be something like a AWS Region-ID or a Cluster-ID or a machine name or endpoint name etc… Not saying that any of these values being null is a good thing, but errors happen sometimes and especially when you are dealing with legacy systems these things are commonplace. Having code break in very unexpected ways because prometheus complains about it’s arguments is really really problematic.

The offending code in the client is here: https://github.com/prometheus/client_java/blob/master/simpleclient/src/main/java/io/prometheus/client/SimpleCollector.java#L64-L68

Is there any policy on metrics? Because in my book metrics/logging should be totally transparent and never require any additional logic. If I can’t call the prometheus client with absolute certainty that it won’t break my code under ANY circumstances I’m hesitant to include it as I am opening myself up to another level of complexity (and all of this suddenly needs testing etc).

Imo it’s preferable to have missing labels be mis-reported as empty string and the client being 100% runtime safe than having a operation fail because some parameter was not correctly checked.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
brian-brazilcommented, Feb 15, 2018

If you want liberal sprinkling, then an extra line of code you have to add kinda goes against that. This is something that’d have to work by default.

0reactions
brian-brazilcommented, Jan 24, 2021

Unfortunately Java doesn’t have the notion of non-nullable types, so there’s not much that can be done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the Throws keyword in Java (and when ... - Rollbar
The throw keyword can be useful for throwing exceptions based on certain conditions within a code block and for throwing custom exceptions.
Read more >
JavaFX How to throws exception message to label?
I write warehouse application and firstly I wrote code which will be displayed in console. Now i want to display it as window...
Read more >
Throwing an exception in Java - Javamex
A method must declare which checked exceptions (if any) it throws, but does not have to declare unchecked exceptions. There are various standard...
Read more >
Best Practice: Catching and re-throwing Java Exceptions - IBM
printStackTrace() and the lack of passing the parameter t as an inner exception to the ServletException. The correct way to catch and re-throw...
Read more >
Exception specifications (throw, noexcept) (C++)
In /std:c++17 mode, throw() is an alias for noexcept(true) . In /std:c++17 mode and later, when an exception is thrown from a function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found