26
26
27
27
import com .google .common .annotations .VisibleForTesting ;
28
28
import com .google .common .base .Strings ;
29
- import com .google .common .collect .ImmutableMap ;
30
29
import com .segment .analytics .Analytics ;
31
30
import com .segment .analytics .messages .AliasMessage ;
32
31
import com .segment .analytics .messages .IdentifyMessage ;
33
32
import com .segment .analytics .messages .TrackMessage ;
33
+ import io .airbyte .config .Configs ;
34
+ import io .airbyte .config .Configs .WorkerEnvironment ;
34
35
import java .util .Collections ;
35
36
import java .util .HashMap ;
36
37
import java .util .Map ;
@@ -46,38 +47,49 @@ public class SegmentTrackingClient implements TrackingClient {
46
47
private final Analytics analytics ;
47
48
private final Supplier <TrackingIdentity > identitySupplier ;
48
49
private final String airbyteRole ;
50
+ private final WorkerEnvironment deploymentEnvironment ;
49
51
50
52
@ VisibleForTesting
51
53
SegmentTrackingClient (final Supplier <TrackingIdentity > identitySupplier ,
54
+ final Configs .WorkerEnvironment deploymentEnvironment ,
52
55
final String airbyteRole ,
53
56
final Analytics analytics ) {
54
57
this .identitySupplier = identitySupplier ;
58
+ this .deploymentEnvironment = deploymentEnvironment ;
55
59
this .analytics = analytics ;
56
60
this .airbyteRole = airbyteRole ;
57
61
}
58
62
59
- public SegmentTrackingClient (final Supplier <TrackingIdentity > identitySupplier , final String airbyteRole ) {
60
- this (identitySupplier , airbyteRole , Analytics .builder (SEGMENT_WRITE_KEY ).build ());
63
+ public SegmentTrackingClient (final Supplier <TrackingIdentity > identitySupplier ,
64
+ final Configs .WorkerEnvironment deploymentEnvironment ,
65
+ final String airbyteRole ) {
66
+ this (identitySupplier , deploymentEnvironment , airbyteRole , Analytics .builder (SEGMENT_WRITE_KEY ).build ());
61
67
}
62
68
63
69
@ Override
64
70
public void identify () {
65
71
final TrackingIdentity trackingIdentity = identitySupplier .get ();
66
- final ImmutableMap .Builder <String , Object > identityMetadataBuilder = ImmutableMap .<String , Object >builder ()
67
- .put (AIRBYTE_VERSION_KEY , trackingIdentity .getAirbyteVersion ())
68
- .put ("anonymized" , trackingIdentity .isAnonymousDataCollection ())
69
- .put ("subscribed_newsletter" , trackingIdentity .isNews ())
70
- .put ("subscribed_security" , trackingIdentity .isSecurityUpdates ());
72
+ final Map <String , Object > identityMetadata = new HashMap <>();
71
73
74
+ // deployment
75
+ identityMetadata .put (AIRBYTE_VERSION_KEY , trackingIdentity .getAirbyteVersion ());
76
+ identityMetadata .put ("deployment_env" , deploymentEnvironment );
77
+
78
+ // workspace (includes info that in the future we would store in an organization)
79
+ identityMetadata .put ("anonymized" , trackingIdentity .isAnonymousDataCollection ());
80
+ identityMetadata .put ("subscribed_newsletter" , trackingIdentity .isNews ());
81
+ identityMetadata .put ("subscribed_security" , trackingIdentity .isSecurityUpdates ());
82
+ trackingIdentity .getEmail ().ifPresent (email -> identityMetadata .put ("email" , email ));
83
+
84
+ // other
72
85
if (!Strings .isNullOrEmpty (airbyteRole )) {
73
- identityMetadataBuilder .put (AIRBYTE_ROLE , airbyteRole );
86
+ identityMetadata .put (AIRBYTE_ROLE , airbyteRole );
74
87
}
75
88
76
- trackingIdentity .getEmail ().ifPresent (email -> identityMetadataBuilder .put ("email" , email ));
77
-
78
89
analytics .enqueue (IdentifyMessage .builder ()
90
+ // user id is scoped by workspace. there is no cross-workspace tracking.
79
91
.userId (trackingIdentity .getCustomerId ().toString ())
80
- .traits (identityMetadataBuilder . build () ));
92
+ .traits (identityMetadata ));
81
93
}
82
94
83
95
@ Override
0 commit comments