diff --git a/packages/java/examples/OwlTestApp/src/main/java/com/readme/example/CustomUserDataCollectorConfig.java b/packages/java/examples/OwlTestApp/src/main/java/com/readme/example/CustomUserDataCollectorConfig.java new file mode 100644 index 0000000000..f971870b9f --- /dev/null +++ b/packages/java/examples/OwlTestApp/src/main/java/com/readme/example/CustomUserDataCollectorConfig.java @@ -0,0 +1,38 @@ +package com.readme.example; + +import org.springframework.context.annotation.Configuration; + +/** + * Configuration class for customizing the strategy to collect user data. + * + *
This configuration provides a custom implementation of {@link UserDataCollector}, + * which overrides the default behavior provided by the SDK. It allows developers + * to specify their own logic for extracting user-specific information, such as API keys, + * email addresses, or labels, from the incoming HTTP requests.
+ * + *In this example, the API key is extracted from the HTTP headers using the header + * "X-User-Name", while the email and label fields are hardcoded with custom values. + * Developers can modify this logic to suit their application's requirements.
+ * + *By defining this bean, Spring Boot's auto-configuration will automatically use + * this custom implementation instead of the default {@link UserDataCollector}.
+ */ +@Configuration +public class CustomUserDataCollectorConfig { + + //Uncomment the code below to have a custom user data collection configuration. + //It automatically overrides the default one + + +// @Bean +// public UserDataCollector* This class acts as a bridge between YAML/Properties configuration and * the corresponding strategy for extracting user-related data * (e.g., from JSON body, headers, or JWT tokens). - * + *
* Ensures flexibility and proper encapsulation of the strategy selection logic.
*/
-@Component
@AllArgsConstructor
@Slf4j
public class ServletUserDataCollector implements UserDataCollector `collect` method is intended to be implemented to extract, process, and
- * send metrics data from the given input object. The exact implementation
+ * `collect` method is intended to be implemented to extract and process
+ * metrics data from the given input object. The exact implementation
* will vary depending on the framework or API used. The default endpoint for sending metrics is {@code https://metrics.readme.io/v1/request}.
*
*/
+
+@Slf4j
public class HttpDataSender implements DataSender {
public static final String APPLICATION_JSON_TYPE = "application/json";
@@ -30,22 +34,33 @@ public HttpDataSender(OkHttpClient client, CoreConfig coreConfig) {
}
@Override
- public int send(RequestPayload requestPayload) {
- if (requestPayload != null && requestPayload.getBody() != null && !requestPayload.getBody().isEmpty()) {
+ public int send(List