<commit_before>package com.shmenkins.infra.aws.lambda;

import java.util.Collections;
import java.util.Map;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import com.shmenkins.core.handler.BasicHandler;
import com.shmenkins.core.handler.http.HttpRequest;
import com.shmenkins.core.handler.http.HttpResponse;

public abstract class ApiGwLambda {

	private final Logger log = LoggerFactory.getLogger(this.getClass());

	private final BasicHandler<HttpRequest, HttpResponse> handler;

	protected ApiGwLambda(BasicHandler<HttpRequest, HttpResponse> handler) {
		// all logs from this instance can be identified using this value
		MDC.put("lambdaInstanceId", UUID.randomUUID().toString());

		this.handler = handler;

		log.info("Instantiated; handler={}", handler);
	}

	public Map<Object, Object> handle(Map<Object, Object> apiGwRequest) {

		log.debug("Handling; request={}", apiGwRequest);

		HttpRequest httpRequest = apiGwToHttpRequest(apiGwRequest);

		try {
			HttpResponse httpResponse = handler.handle(httpRequest);
			Map<Object, Object> apiGwResponse = httpToApiGwResponse(httpResponse);
			return apiGwResponse;
		} catch (Throwable e) {
			log.error("Cannot handle apigw request; request=" + apiGwRequest, e);
			throw new RuntimeException("500", e);
		}
	}

	private HttpRequest apiGwToHttpRequest(Map<Object, Object> apiGwRequest) {
		log.trace("ApiGwRequest={}", apiGwRequest);
		return new HttpRequest();
	}

	private Map<Object, Object> httpToApiGwResponse(HttpResponse httpResponse) {
		return Collections.emptyMap();
	}

}<commit_msg>Initialize MDC in static context<commit_after>package com.shmenkins.infra.aws.lambda;

import java.util.Collections;
import java.util.Map;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import com.shmenkins.core.handler.BasicHandler;
import com.shmenkins.core.handler.http.HttpRequest;
import com.shmenkins.core.handler.http.HttpResponse;

public abstract class ApiGwLambda {

	static {
		// all logs from this instance can be identified using this value
		MDC.put("lambdaInstanceId", UUID.randomUUID().toString());
	}

	private final Logger log = LoggerFactory.getLogger(this.getClass());

	private final BasicHandler<HttpRequest, HttpResponse> handler;

	protected ApiGwLambda(BasicHandler<HttpRequest, HttpResponse> handler) {
		this.handler = handler;
		log.info("Instantiated; handler={}", handler);
	}

	public Map<Object, Object> handle(Map<Object, Object> apiGwRequest) {

		log.debug("Handling; request={}", apiGwRequest);

		HttpRequest httpRequest = apiGwToHttpRequest(apiGwRequest);

		try {
			HttpResponse httpResponse = handler.handle(httpRequest);
			Map<Object, Object> apiGwResponse = httpToApiGwResponse(httpResponse);
			return apiGwResponse;
		} catch (Throwable e) {
			log.error("Cannot handle apigw request; request=" + apiGwRequest, e);
			throw new RuntimeException("500", e);
		}
	}

	private HttpRequest apiGwToHttpRequest(Map<Object, Object> apiGwRequest) {
		log.trace("ApiGwRequest={}", apiGwRequest);
		return new HttpRequest();
	}

	private Map<Object, Object> httpToApiGwResponse(HttpResponse httpResponse) {
		return Collections.emptyMap();
	}
	
}
{'fraction_non_alphanumeric': 0.11398644485520641, 'fraction_numerical': 0.0036968576709796672, 'mean_word_length': 5.681069958847736, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2146732', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1018, 'n_words': 223}