5
5
package io .airbyte .workers .temporal .sync ;
6
6
7
7
import static io .airbyte .metrics .lib .ApmTraceConstants .ACTIVITY_TRACE_OPERATION_NAME ;
8
+ import static io .airbyte .metrics .lib .ApmTraceConstants .Tags .CONNECTION_ID_KEY ;
9
+ import static io .airbyte .metrics .lib .ApmTraceConstants .Tags .SOURCE_ID_KEY ;
8
10
9
11
import datadog .trace .api .Trace ;
10
12
import io .airbyte .api .client .generated .SourceApi ;
13
15
import io .airbyte .api .client .model .generated .SourceDiscoverSchemaRequestBody ;
14
16
import io .airbyte .api .client .model .generated .SourceIdRequestBody ;
15
17
import io .airbyte .commons .features .EnvVariableFeatureFlags ;
18
+ import io .airbyte .metrics .lib .ApmTraceUtils ;
16
19
import jakarta .inject .Singleton ;
17
20
import java .time .OffsetDateTime ;
21
+ import java .util .Map ;
18
22
import java .util .UUID ;
19
23
import lombok .extern .slf4j .Slf4j ;
20
24
@@ -25,48 +29,54 @@ public class RefreshSchemaActivityImpl implements RefreshSchemaActivity {
25
29
private final SourceApi sourceApi ;
26
30
private final EnvVariableFeatureFlags envVariableFeatureFlags ;
27
31
28
- public RefreshSchemaActivityImpl (SourceApi sourceApi ,
29
- EnvVariableFeatureFlags envVariableFeatureFlags ) {
32
+ public RefreshSchemaActivityImpl (final SourceApi sourceApi ,
33
+ final EnvVariableFeatureFlags envVariableFeatureFlags ) {
30
34
this .sourceApi = sourceApi ;
31
35
this .envVariableFeatureFlags = envVariableFeatureFlags ;
32
36
}
33
37
34
38
@ Override
35
39
@ Trace (operationName = ACTIVITY_TRACE_OPERATION_NAME )
36
- public boolean shouldRefreshSchema (UUID sourceCatalogId ) {
40
+ public boolean shouldRefreshSchema (final UUID sourceCatalogId ) {
37
41
if (!envVariableFeatureFlags .autoDetectSchema ()) {
38
42
return false ;
39
43
}
40
44
45
+ ApmTraceUtils .addTagsToTrace (Map .of (SOURCE_ID_KEY , sourceCatalogId ));
41
46
return !schemaRefreshRanRecently (sourceCatalogId );
42
47
}
43
48
44
49
@ Override
45
- public void refreshSchema (UUID sourceCatalogId , UUID connectionId ) {
50
+ @ Trace (operationName = ACTIVITY_TRACE_OPERATION_NAME )
51
+ public void refreshSchema (final UUID sourceCatalogId , final UUID connectionId ) {
46
52
if (!envVariableFeatureFlags .autoDetectSchema ()) {
47
53
return ;
48
54
}
49
55
50
- SourceDiscoverSchemaRequestBody requestBody =
56
+ ApmTraceUtils .addTagsToTrace (Map .of (CONNECTION_ID_KEY , connectionId , SOURCE_ID_KEY , sourceCatalogId ));
57
+
58
+ final SourceDiscoverSchemaRequestBody requestBody =
51
59
new SourceDiscoverSchemaRequestBody ().sourceId (sourceCatalogId ).disableCache (true ).connectionId (connectionId );
52
60
53
61
try {
54
62
sourceApi .discoverSchemaForSource (requestBody );
55
63
} catch (final Exception e ) {
64
+ ApmTraceUtils .addExceptionToTrace (e );
56
65
// catching this exception because we don't want to block replication due to a failed schema refresh
57
66
log .error ("Attempted schema refresh, but failed with error: " , e );
58
67
}
59
68
}
60
69
61
- private boolean schemaRefreshRanRecently (UUID sourceCatalogId ) {
70
+ private boolean schemaRefreshRanRecently (final UUID sourceCatalogId ) {
62
71
try {
63
- SourceIdRequestBody sourceIdRequestBody = new SourceIdRequestBody ().sourceId (sourceCatalogId );
64
- ActorCatalogWithUpdatedAt mostRecentFetchEvent = sourceApi .getMostRecentSourceActorCatalog (sourceIdRequestBody );
72
+ final SourceIdRequestBody sourceIdRequestBody = new SourceIdRequestBody ().sourceId (sourceCatalogId );
73
+ final ActorCatalogWithUpdatedAt mostRecentFetchEvent = sourceApi .getMostRecentSourceActorCatalog (sourceIdRequestBody );
65
74
if (mostRecentFetchEvent .getUpdatedAt () == null ) {
66
75
return false ;
67
76
}
68
77
return mostRecentFetchEvent .getUpdatedAt () > OffsetDateTime .now ().minusHours (24l ).toEpochSecond ();
69
- } catch (ApiException e ) {
78
+ } catch (final ApiException e ) {
79
+ ApmTraceUtils .addExceptionToTrace (e );
70
80
// catching this exception because we don't want to block replication due to a failed schema refresh
71
81
log .info ("Encountered an error fetching most recent actor catalog fetch event: " , e );
72
82
return true ;
0 commit comments