import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
public class Handler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
String httpMethod = event.getHttpMethod();
String path = event.getPath();
// Set the http request method and route on the parent span.
Span span = Span.current();
span.setAttribute("http.request.method", httpMethod);
span.setAttribute("http.route", path);
APIGatewayProxyResponseEvent result = processRequest(event)
// Set the HTTP response code and mark the span as failed for 4xx/5xx responses.
span.setAttribute("http.response.status_code", result.getStatusCode());
span.setStatus(result.getStatusCode() < 400 ? StatusCode.OK : StatusCode.ERROR);
return result;
}
}