Skip to content

Commit

Permalink
Add segment tracking to public api endpoints (#5960)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencecho committed Apr 18, 2023
1 parent 9365c19 commit 32fa531
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.slf4j.LoggerFactory;

/**
* Tracking client that logs to STDOUT. Mainly used for local deveolpment.
* Tracking client that logs to STDOUT. Mainly used for local development.
*/
public class LoggingTrackingClient implements TrackingClient {

Expand Down Expand Up @@ -44,11 +44,13 @@ public void track(@Nullable final UUID workspaceId, final String action) {

@Override
public void track(@Nullable final UUID workspaceId, final String action, final Map<String, Object> metadata) {
TrackingIdentity trackingIdentity = identityFetcher.apply(workspaceId);

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();
if (identityFetcher.apply(workspaceId) != null) {
version = Optional.ofNullable(trackingIdentity.getAirbyteVersion()).map(AirbyteVersion::serialize).orElse(null);
userId = trackingIdentity.getCustomerId();
}
LOGGER.info("track. version: {}, userId: {}, action: {}, metadata: {}",
version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public class SegmentTrackingClient implements TrackingClient {

public SegmentTrackingClient(final Function<UUID, TrackingIdentity> identityFetcher,
final Deployment deployment,

final String airbyteRole) {
this(identityFetcher, deployment, airbyteRole, Analytics.builder(SEGMENT_WRITE_KEY).build());
}
Expand Down Expand Up @@ -127,6 +126,7 @@ public void track(@Nullable final UUID workspaceId, final String action, final M
LOGGER.error("Could not track action {} due to null workspaceId", action);
return;
}

final Map<String, Object> mapCopy = new HashMap<>(metadata);
final TrackingIdentity trackingIdentity = identityFetcher.apply(workspaceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ private static void initialize() {
initialize(new LoggingTrackingClient(workspaceId -> TrackingIdentity.empty()));
}

/**
* Initialize client for Airbyte API usage.
*/
public static void initializeWithoutDatabase(final Configs.TrackingStrategy trackingStrategy,
final Deployment deployment,
final AirbyteVersion airbyteVersion) {
initialize(createTrackingClient(
trackingStrategy,
deployment,
null,
(userId) -> new TrackingIdentity(
airbyteVersion,
userId,
null,
null,
null,
null)));
}

@VisibleForTesting
static TrackingIdentity getTrackingIdentity(final ConfigRepository configRepository, final AirbyteVersion airbyteVersion, final UUID workspaceId) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public static TrackingIdentity empty() {
return new TrackingIdentity(null, null, null, null, null, null);
}

public TrackingIdentity(
final AirbyteVersion airbyteVersion,
public TrackingIdentity(final AirbyteVersion airbyteVersion,
final UUID customerId,
final String email,
final Boolean anonymousDataCollection,
Expand Down

0 comments on commit 32fa531

Please sign in to comment.