<commit_before>package com.swisscom.cloud.sb.broker.util

import groovy.util.logging.Slf4j
import org.slf4j.MDC
import org.springframework.web.servlet.HandlerMapping
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@Slf4j
class LogContextEnrichInterceptor extends HandlerInterceptorAdapter {
    @Override
    boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Map<String,String> pathVariables = (Map)request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE)
        if (pathVariables.containsKey("serviceInstanceGuid")) {
            MDC.put("serviceInstanceGuid", pathVariables.get("serviceInstanceGuid").toString())
        }
        return true
    }
}
<commit_msg>make sure that any exceptions of the LogContextEnrichInterceptor are caught<commit_after>package com.swisscom.cloud.sb.broker.util

import groovy.util.logging.Slf4j
import org.slf4j.MDC
import org.springframework.web.servlet.HandlerMapping
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@Slf4j
class LogContextEnrichInterceptor extends HandlerInterceptorAdapter {
    @Override
    boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        try {
            Map<String, String> pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE)
            if (pathVariables.containsKey("serviceInstanceGuid")) {
                MDC.put("serviceInstanceGuid", pathVariables.get("serviceInstanceGuid").toString())
            }
        } catch (Exception e) {
            log.debug("Error setting log context", e)
        }
        return true
    }
}

{'fraction_non_alphanumeric': 0.08012486992715921, 'fraction_numerical': 0.003121748178980229, 'mean_word_length': 4.525862068965517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2148748', 'n_tokens_mistral': 505, 'n_tokens_neox': 509, 'n_words': 96}