Source:
private static boolean postLogs(String url, Secret apiKey, String payload) throws IOException { if(payload == null){ logger.fine("No payload to post"); return true; } HttpURLConnection conn = null; URL logsEndpointURL = new URL(url); try { logger.fine("Setting up HttpURLConnection..."); conn = getHttpURLConnection(logsEndpointURL); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("DD-API-KEY", Secret.toString(apiKey)); conn.setRequestProperty("User-Agent", String.format("Datadog/%s/jenkins Java/%s Jenkins/%s", DatadogUtilities.getDatadogPluginVersion(), DatadogUtilities.getJavaRuntimeVersion(), DatadogUtilities.getJenkinsVersion())); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream(), "utf-8"); logger.fine("Writing to OutputStreamWriter..."); wr.write(payload); wr.close(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); if ("{}".equals(result.toString())) { logger.fine(String.format("Logs API call was sent successfully!")); logger.fine(String.format("Payload: %s", payload)); } else { logger.severe(String.format("Logs API call failed!")); logger.severe(String.format("Payload: %s", payload)); return false; } } catch (Exception e) { try { if (conn != null && conn.getResponseCode() == BAD_REQUEST) { logger.severe("Hmmm, your API key or your Log Intake URL may be invalid. We received a 400 in response."); } else { DatadogUtilities.severe(logger, e, "Client error"); } } catch (IOException ex) { DatadogUtilities.severe(logger, ex, null); } return false; } finally { if (conn != null) { conn.disconnect(); } } return true; }

Target:
private boolean postLogs(String url, Secret apiKey, String payload) { if(payload == null){ logger.fine("No payload to post"); return true; } HttpURLConnection conn = null; try { URL logsEndpointURL = new URL(url); logger.fine("Setting up HttpURLConnection..."); conn = getHttpURLConnection(logsEndpointURL); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("DD-API-KEY", Secret.toString(apiKey)); conn.setRequestProperty("User-Agent", String.format("Datadog/%s/jenkins Java/%s Jenkins/%s", getDatadogPluginVersion(), getJavaRuntimeVersion(), getJenkinsVersion())); DatadogUtilities.severe(logger, null, String.format("Datadog/%s/jenkins Java/%s Jenkins/%s", getDatadogPluginVersion(), getJavaRuntimeVersion(), getJenkinsVersion())); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream(), "utf-8"); logger.fine("Writing to OutputStreamWriter..."); wr.write(payload); wr.close(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); if ("{}".equals(result.toString())) { logger.fine(String.format("Logs API call was sent successfully!")); logger.fine(String.format("Payload: %s", payload)); } else { logger.severe(String.format("Logs API call failed!")); logger.fine(String.format("Payload: %s", payload)); return false; } } catch (Exception e) { try { if (conn != null && conn.getResponseCode() == BAD_REQUEST) { logger.severe("Hmmm, your API key or your Log Intake URL may be invalid. We received a 400 in response."); } else { DatadogUtilities.severe(logger, e, "Client error"); } } catch (IOException ex) { DatadogUtilities.severe(logger, ex, null); } return false; } finally { if (conn != null) { conn.disconnect(); } } return true; }