-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
LoggingTrackingClient.java
57 lines (46 loc) · 1.8 KB
/
LoggingTrackingClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (c) 2023 Airbyte, Inc., all rights reserved.
*/
package io.airbyte.analytics;
import io.airbyte.commons.version.AirbyteVersion;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggingTrackingClient implements TrackingClient {
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingTrackingClient.class);
private final Function<UUID, TrackingIdentity> identityFetcher;
public LoggingTrackingClient(final Function<UUID, TrackingIdentity> identityFetcher) {
this.identityFetcher = identityFetcher;
}
@Override
public void identify(final UUID workspaceId) {
LOGGER.info("identify. userId: {}", identityFetcher.apply(workspaceId).getCustomerId());
}
@Override
public void alias(final UUID workspaceId, final String previousCustomerId) {
LOGGER.info("merge. userId: {} previousUserId: {}", identityFetcher.apply(workspaceId).getCustomerId(), previousCustomerId);
}
@Override
public void track(@Nullable final UUID workspaceId, final String action) {
track(workspaceId, action, Collections.emptyMap());
}
@Override
public void track(@Nullable final UUID workspaceId, final String action, final Map<String, Object> metadata) {
String version = null;
UUID userId = null;
if (workspaceId != null) {
version = Optional.ofNullable(identityFetcher.apply(workspaceId).getAirbyteVersion()).map(AirbyteVersion::serialize).orElse(null);
userId = identityFetcher.apply(workspaceId).getCustomerId();
}
LOGGER.info("track. version: {}, userId: {}, action: {}, metadata: {}",
version,
userId,
action,
metadata);
}
}