diff --git a/README.md b/README.md index b0e3439..59bfce2 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ public class LogzioSenderExample { ### Release notes + - 2.0.1 + - Add `User-Agent` header with logz.io information - 2.0.0 - **THIS IS A SNAPSHOT RELEASE - SUPPORTED WITH JDK 11 AND ABOVE** - Replaced `BigQueue` module: - Fixes an issue where DiskQueue was not clearing disk space when using JDK 11 and above. diff --git a/logzio-sender-test/pom.xml b/logzio-sender-test/pom.xml index ef0b60a..a4bfc1c 100644 --- a/logzio-sender-test/pom.xml +++ b/logzio-sender-test/pom.xml @@ -5,7 +5,7 @@ logzio-java-sender io.logz.sender - 2.0.0 + 2.0.1 4.0.0 @@ -27,6 +27,12 @@ + + + src/main/resources + true + + diff --git a/logzio-sender/pom.xml b/logzio-sender/pom.xml index 33e1d50..0f4b1a0 100644 --- a/logzio-sender/pom.xml +++ b/logzio-sender/pom.xml @@ -5,7 +5,7 @@ logzio-java-sender io.logz.sender - 2.0.0 + 2.0.1 4.0.0 @@ -75,6 +75,12 @@ + + + src/main/resources + true + + diff --git a/logzio-sender/src/main/java/io/logz/sender/HttpsSyncSender.java b/logzio-sender/src/main/java/io/logz/sender/HttpsSyncSender.java index e32bf5e..dcadddd 100644 --- a/logzio-sender/src/main/java/io/logz/sender/HttpsSyncSender.java +++ b/logzio-sender/src/main/java/io/logz/sender/HttpsSyncSender.java @@ -11,6 +11,7 @@ import java.net.HttpURLConnection; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.Properties; import java.util.zip.GZIPOutputStream; public class HttpsSyncSender { @@ -106,11 +107,9 @@ private boolean handleResponse(byte[] payload, int responseCode, String response if (errorMessage != null) { reporter.warning(errorMessage); } - } - else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) { + } else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) { reporter.error("Logz.io: Got forbidden! Your token is not right. Unfortunately, dropping logs. Message: " + responseMessage); - } - else if (responseCode == HttpURLConnection.HTTP_OK) { + } else if (responseCode == HttpURLConnection.HTTP_OK) { reporter.info("Successfully sent bulk to logz.io, size: " + payload.length); } else { retry = true; @@ -140,19 +139,28 @@ private String readErrorStream(HttpURLConnection conn) { } private HttpURLConnection sendRequest(byte[] payload) throws IOException { + String logzAgent = "version-not-found"; HttpURLConnection conn = (HttpURLConnection) configuration.getLogzioListenerUrl().openConnection(); - conn.setRequestMethod(configuration.getRequestMethod()); - conn.setRequestProperty("Content-length", String.valueOf(payload.length)); - conn.setRequestProperty("Content-Type", "text/plain"); - if (configuration.isCompressRequests()) { - conn.setRequestProperty("Content-Encoding", "gzip"); - } - conn.setReadTimeout(configuration.getSocketTimeout()); - conn.setConnectTimeout(configuration.getConnectTimeout()); - conn.setDoOutput(true); - conn.setDoInput(true); - conn.getOutputStream().write(payload); + try { + final Properties properties = new Properties(); + properties.load(HttpsSyncSender.class.getClassLoader().getResourceAsStream("project.properties")); + logzAgent = String.format("java/%s/logs", properties.getProperty("logzSenderVersion")); + } finally { + conn.setRequestMethod(configuration.getRequestMethod()); + conn.setRequestProperty("Content-length", String.valueOf(payload.length)); + conn.setRequestProperty("Content-Type", "text/plain"); + conn.setRequestProperty("User-Agent", logzAgent); + if (configuration.isCompressRequests()) { + conn.setRequestProperty("Content-Encoding", "gzip"); + } + conn.setReadTimeout(configuration.getSocketTimeout()); + conn.setConnectTimeout(configuration.getConnectTimeout()); + conn.setDoOutput(true); + conn.setDoInput(true); + + conn.getOutputStream().write(payload); + } return conn; } diff --git a/logzio-sender/src/main/resources/project.properties b/logzio-sender/src/main/resources/project.properties new file mode 100644 index 0000000..39c3e65 --- /dev/null +++ b/logzio-sender/src/main/resources/project.properties @@ -0,0 +1 @@ +logzSenderVersion=${project.version} diff --git a/pom.xml b/pom.xml index 7388c21..c611cdb 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.logz.sender logzio-java-sender pom - 2.0.0 + 2.0.1 Logz.io Logs Sender Send your log messages to your logz.io account in an encrypted, non-blocking manner. @@ -97,6 +97,12 @@ + + + src/main/resources + true + +