1010from loglib import *
1111log = retrieve_logger ()
1212
13+ import otel
14+
1315try :
1416 log .info ('Importing senzing_core library . . .' )
1517 import senzing_core as sz_core
2830 sys .exit (1 )
2931S3_BUCKET_NAME = os .environ ['S3_BUCKET_NAME' ]
3032FOLDER_NAME = os .environ .get ('FOLDER_NAME' , 'exporter-outputs' )
33+ RUNTIME_ENV = os .environ .get ('RUNTIME_ENV' , 'unknown' ) # For OTel
3134
3235EXPORT_FLAGS = sz .SzEngineFlags .SZ_EXPORT_DEFAULT_FLAGS
3336
@@ -82,13 +85,25 @@ def go():
8285 except Exception as e :
8386 log .error (fmterr (e ))
8487
88+ # OTel setup #
89+ log .info ('Starting OTel setup.' )
90+ meter = otel .init ('exporter' )
91+ otel_exp_counter = meter .create_counter ('exporter.export.count' )
92+ otel_duration = meter .create_histogram ('exporter.export.duration' )
93+ log .info ('Finished OTel setup.' )
94+ # end OTel setup #
95+
8596 # init buffer
8697 buff = io .BytesIO ()
8798
8899 # Retrieve output from sz into buff
89100 # sz will export JSONL lines; we add the chars necessary to make
90101 # the output as a whole be a single JSON blob.
91102 log .info (SZ_TAG + 'Starting export from Senzing.' )
103+
104+ start = time .perf_counter ()
105+ success_status = otel .FAILURE # initial default state
106+
92107 try :
93108 export_handle = sz_eng .export_json_entity_report (EXPORT_FLAGS )
94109 log .info (SZ_TAG + 'Obtained export_json_entity_report handle.' )
@@ -121,9 +136,20 @@ def go():
121136 try :
122137 s3 .upload_fileobj (buff , S3_BUCKET_NAME , full_path )
123138 log .info (AWS_TAG + 'Successfully uploaded file.' )
139+ success_status = otel .SUCCESS
124140 except Exception as e :
125141 log .error (AWS_TAG + fmterr (e ))
126142
143+ finish = time .perf_counter ()
144+ otel_exp_counter .add (1 ,
145+ {'status' : success_status ,
146+ 'service' : 'exporter' ,
147+ 'environment' : RUNTIME_ENV })
148+ otel_duration .record (finish - start ,
149+ {'status' : success_status ,
150+ 'service' : 'exporter' ,
151+ 'environment' : RUNTIME_ENV })
152+
127153#-------------------------------------------------------------------------------
128154
129155def main ():
@@ -134,4 +160,3 @@ def main():
134160 go ()
135161
136162if __name__ == '__main__' : main ()
137-
0 commit comments