|
| 1 | +# Traceo SDK for Java |
| 2 | + |
| 3 | +Library for integration with the [Traceo Platform](https://github.com/traceo-dev/traceo). |
| 4 | + |
| 5 | +### Installation |
| 6 | +To install this SDK add this package to your `pom.xml` like below: |
| 7 | + |
| 8 | +```java |
| 9 | +<dependency> |
| 10 | + <groupId>com.traceo.sdk</groupId> |
| 11 | + <artifactId>traceo-sdk</artifactId> |
| 12 | + <version>1.0.0</version> |
| 13 | +</dependency> |
| 14 | +``` |
| 15 | + |
| 16 | +or to `build.gradle` |
| 17 | + |
| 18 | +```java |
| 19 | +dependencies { |
| 20 | + implementation 'com.traceo.sdk:traceo-sdk:1.0.0' |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +### Usage |
| 25 | +To init SDK in your project use internal `TraceoClientBuilder` to create client configuration and pass configurations to static `init()` method from `TraceoClient` class. |
| 26 | +```java |
| 27 | +TraceoClientConfiguration clientConfiguration = TraceoClientBuilder |
| 28 | + .standard() |
| 29 | + .withApiKey("tr_408917b2-42fb-43d9-8602-861879c1a273") |
| 30 | + .withHost("http://localhost:3000") |
| 31 | + .build(); |
| 32 | + |
| 33 | +TraceoClient.init(clientConfiguration); |
| 34 | +``` |
| 35 | + |
| 36 | +Table of available options in `TraceoClientBuilder`: |
| 37 | + |
| 38 | +| Method | Description | Default | Required | |
| 39 | +|:----------:|:-----------------------------------------------------------------------------------------------------------------------------------------------:|:-------:|:--------:| |
| 40 | +| withApiKey | Project api key generated in Traceo Platform | | ✔ | |
| 41 | +| withHost | Host on which Traceo Platform is running provided in format `[protocol]://[domain]:[port]` | | ✔ | |
| 42 | +| withDebug | Set to true if you want to check internal logs for SDK. | false | ❌ | |
| 43 | +| withEnabled | If false then client is not initialized. None of the captured exceptions, spans or metrics are send to Traceo Platform. | true | ❌ | |
| 44 | +| withCatchUncaughtException | Set to true if you want to catch every uncaught exception. | false | ❌ | |
| 45 | +| withPackages | List of packages where SDK is used. Based on this values, SDK can check wheter incoming exception is inside client code or in external library. | | ❌ | |
| 46 | +| withExportIntervalMs | Set custom value for export default metrics interval. | 5000 | ❌ | |
| 47 | + |
| 48 | +### Incidents handling |
| 49 | + |
| 50 | +Incidents are all the exceptions and other problems that occur in your application. After each exception occurs, the Traceo SDK catches the exception and sends it to the Traceo Platform. To catch an exception and send it to the Traceo platform, use the static `catchException()` method from the `TraceoClient` class. |
| 51 | + |
| 52 | +``` |
| 53 | +try { |
| 54 | + // your code |
| 55 | +} catch (ArrayIndexOutOfBoundsException exception) { |
| 56 | + TraceoClient.catchException(exception); |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +### Logger |
| 61 | + |
| 62 | +The Traceo SDK can be used also as a logger. Each log is saved on the Traceo Platform, thanks to which it is possible to later easily access the recorded information. Logs are sent to Traceo in every 180 seconds. |
| 63 | +Example of using logger: |
| 64 | +```java |
| 65 | +public class HttpClient { |
| 66 | + public static final TraceoLogger LOGGER = TraceoClient.getLogger(HttpClient.class); |
| 67 | + |
| 68 | + // your code |
| 69 | + |
| 70 | + public void makeRequest() { |
| 71 | + // your code |
| 72 | + |
| 73 | + LOGGER.log("OK."); |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +Available logger methods: |
| 79 | + |
| 80 | +| Method | Description | |
| 81 | +|:-------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| |
| 82 | +| log | [The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.](https://www.slf4j.org/api/org/apache/log4j/Level.html#:~:text=INFO-,The%20INFO%20level%20designates%20informational%20messages%20that%20highlight%20the%20progress%20of%20the%20application%20at%20coarse%2Dgrained%20level.,-static%20Level) | |
| 83 | +| debug | [The DEBUG Level designates fine-grained informational events that are most useful to debug an application.](https://www.slf4j.org/api/org/apache/log4j/Level.html#:~:text=DEBUG-,The%20DEBUG%20Level%20designates%20fine%2Dgrained%20informational%20events%20that%20are%20most%20useful%20to%20debug%20an%20application.,-static%20Level) | |
| 84 | +| error | [The ERROR level designates error events that might still allow the application to continue running.](https://www.slf4j.org/api/org/apache/log4j/Level.html#:~:text=ERROR-,The%20ERROR%20level%20designates%20error%20events%20that%20might%20still%20allow%20the%20application%20to%20continue%20running.,-static%20Level) | |
| 85 | +| warning | [The WARN level designates potentially harmful situations.](https://www.slf4j.org/api/org/apache/log4j/Level.html#:~:text=WARN-,The%20WARN%20level%20designates%20potentially%20harmful%20situations.,-static%20int) | |
| 86 | + |
| 87 | +**TIP:** Remember to init `TraceoClient` before using `TraceoLogger`. |
| 88 | +### More |
| 89 | +This package is also required to integration with `OpenTelemetry for Java`. Full implementation guide can be found [here](). |
| 90 | + |
| 91 | +## Support |
| 92 | +Feel free to create Issues, Pull Request and Discussion. If you want to contact with the developer working on this package click [here](mailto:piotr.szewczyk.software@gmail.com). |
0 commit comments