Skip to content

Commit c59dfc6

Browse files
committed
add otel metrics to exporter
1 parent 04b42d8 commit c59dfc6

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

Dockerfile.exporter

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ RUN apt-get update \
77
&& apt-get -y autoremove \
88
&& apt-get -y clean
99

10+
RUN pip3 install --break-system-packages opentelemetry-distro
11+
# Above, `--break-system-packages` flag overrides the
12+
# "This environment is externally managed" error that calling pip
13+
# would otherwise incur here.
14+
1015
WORKDIR /app
1116
COPY middleware/* .
1217

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ docker compose run --env AWS_PROFILE=localstack --env S3_BUCKET_NAME=sqs-senzing
265265
- `FOLDER_NAME` -- optional (defaults to `exporter-outputs`); folder inside S3
266266
where the file will be placed.
267267
- `LOG_LEVEL` -- optional; defaults to `INFO`.
268+
- `RUNTIME_ENV` -- the runtime enviroment (e.g., "Dev", "Prod", etc.). Optional;
269+
defaults to "unknown".
268270

269271
_Mounts in docker-compose.yaml:_
270272

middleware/consumer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@ def clean_up(signum, frm):
171171
log.error(fmterr(e))
172172

173173
# OTel setup #
174+
log.info('Starting OTel setup.')
174175
meter = otel.init('consumer')
175176
otel_msgs_counter = meter.create_counter('consumer.messages.count')
176177
otel_durations = meter.create_histogram('consumer.messages.duration')
178+
log.info('Finished OTel setup.')
177179
# end OTel setup #
178180

179181
while 1:

middleware/exporter.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from loglib import *
1111
log = retrieve_logger()
1212

13+
import otel
14+
1315
try:
1416
log.info('Importing senzing_core library . . .')
1517
import senzing_core as sz_core
@@ -28,6 +30,7 @@
2830
sys.exit(1)
2931
S3_BUCKET_NAME = os.environ['S3_BUCKET_NAME']
3032
FOLDER_NAME = os.environ.get('FOLDER_NAME', 'exporter-outputs')
33+
RUNTIME_ENV = os.environ.get('RUNTIME_ENV', 'unknown') # For OTel
3134

3235
EXPORT_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

129155
def main():
@@ -134,4 +160,3 @@ def main():
134160
go()
135161

136162
if __name__ == '__main__': main()
137-

0 commit comments

Comments
 (0)