1111from opentelemetry .sdk .trace .export import BatchSpanProcessor
1212from opentelemetry .exporter .jaeger .thrift import JaegerExporter
1313from opentelemetry .instrumentation .requests import RequestsInstrumentor
14+ from opentelemetry .instrumentation .pymysql import PyMySQLInstrumentor
1415
1516#########
1617# INITS #
5051logging .info ('About to instrument app for OTEL' )
5152# set the service name for our trace provider
5253# this will tag every trace with the service name given
54+ otel_service_name = app .config .get ('OTEL_SERVICE_NAME' , 'COHD' )
5355tp = TracerProvider (
54- resource = Resource .create ({telemetery_service_name_key : 'COHD' })
56+ resource = Resource .create ({telemetery_service_name_key : otel_service_name })
5557 )
5658# create an exporter to jaeger
57- jaeger_host = 'jaeger'
59+ jaeger_host = app .config .get ('JAEGER_HOST' , 'jaeger-otel-agent.sri' )
60+ jaeger_port = app .config .get ('JAEGER_PORT' , 6831 )
5861deployment_env = app .config .get ('DEPLOYMENT_ENV' , 'dev' )
59- if deployment_env [:4 ] == 'ITRB' :
60- jaeger_host = 'jaeger-otel-agent.sri'
6162jaeger_exporter = JaegerExporter (
6263 agent_host_name = jaeger_host ,
63- agent_port = 6831 ,
64+ agent_port = jaeger_port ,
6465 )
6566# here we use the exporter to export each span in a trace
6667tp .add_span_processor (
7475FlaskInstrumentor ().instrument_app (app ,
7576 excluded_urls = otel_excluded_urls )
7677RequestsInstrumentor ().instrument ()
78+ PyMySQLInstrumentor ().instrument ()
7779logging .info ('Finished instrumenting app for OTEL' )
0 commit comments