Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
add User-Agent header to Sender
  • Loading branch information
8naama authored May 21, 2024
2 parents ad34458 + f30c737 commit 87df9ea
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion logzio-sender-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>logzio-java-sender</artifactId>
<groupId>io.logz.sender</groupId>
<version>2.0.0</version>
<version>2.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -27,6 +27,12 @@
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<dependencies>
Expand Down
8 changes: 7 additions & 1 deletion logzio-sender/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>logzio-java-sender</artifactId>
<groupId>io.logz.sender</groupId>
<version>2.0.0</version>
<version>2.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -75,6 +75,12 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<dependencies>
Expand Down
38 changes: 23 additions & 15 deletions logzio-sender/src/main/java/io/logz/sender/HttpsSyncSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions logzio-sender/src/main/resources/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logzSenderVersion=${project.version}
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.logz.sender</groupId>
<artifactId>logzio-java-sender</artifactId>
<packaging>pom</packaging>
<version>2.0.0</version>
<version>2.0.1</version>

<name>Logz.io Logs Sender</name>
<description>Send your log messages to your logz.io account in an encrypted, non-blocking manner.</description>
Expand Down Expand Up @@ -97,6 +97,12 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<dependencyManagement>
Expand Down

0 comments on commit 87df9ea

Please sign in to comment.