Skip to content

Commit

Permalink
Added error handling for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
akats7 committed Nov 17, 2023
1 parent c9e0486 commit cdc8aa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,18 @@ class InstrumentHelper {
private static Map<String, String> getLabels(GroovyMBean mbean, Map<String, Closure> labelFuncs, Map<String, Closure> additionalLabels) {
def labels = [:]
labelFuncs.each { label, labelFunc ->
try{
labels[label] = labelFunc(mbean) as String
}catch(AttributeNotFoundException e){
logger.warning("Attribute missing for label:${label}, label was not applied")
}
}
additionalLabels.each { label, labelFunc ->
try{
labels[label] = labelFunc(mbean) as String
}catch(AttributeNotFoundException e){
logger.warning("Attribute missing for label:${label}, label was not applied")
}
}
return labels
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ class MBeanHelper {
def transformationClosure = attributeTransformation.get(attribute);
if (transformationClosure != null){
try{
transformationClosure(bean)
return transformationClosure(bean)
}
catch(AttributeNotFoundException e){
logger.warning("Transformed attribute not found in ${bean.name()}")
null
return null
}
}
return getBeanAttribute(bean, attribute)
Expand Down

0 comments on commit cdc8aa8

Please sign in to comment.