I have been trying to test OTEL auto instrumentation for Python and been having trouble getting metrics, traces, and logs to all be properly exporting consistently. I have been attempting this will using the opentelemetry-instrument command in my Dockerfile and have a simple Flask Python application.
Dockerfile:
WORKDIR /app
COPY . ./
RUN pip install -r requirements.txt
RUN pip install opentelemetry-distro \
opentelemetry-exporter-otlp
RUN opentelemetry-bootstrap -a install
ENV APP_HOME=/app
RUN chown -R appuser:appuser /app
FROM development as production
WORKDIR /app
USER appuser
EXPOSE 8443
CMD ["opentelemetry-instrument", "python", "src/index.py"]
index.py:
app = flask.Flask(__name__)
@app.route('/debug', methods=['GET'])
def do_GET():
i = 0
for x in range(16):
print("(PRINT) do_GET logs " + str(x))
logger.info("(DEFAULT INFO) do_GET logs " + str(x))
logger.warning("(DEFAULT WARNING) do_GET logs " + str(x))
logger.error("(DEFAULT ERROR) do_GET logs " + str(x))
i = i + 1
return {"status": "Success"}
if __name__ == "__main__":
logger.info('start')
app.run(debug=True, port=8443, host='0.0.0.0')
In this setup, I can see metrics being exported to the OTEL collector consistently and can see specifically the "start" log being exported to the OTEL collector but with "0" as the trace and span id. All other logs within the "debug" endpoint is not being exported at all and I do not see any traces being exported. I am relatively new still to messing with OTEL and instrumentation, but realistic I am trying to explore methods into auto instrumenting Python applications with little code changes. I am curious if I am on the right track and just have problems with my implementation or if there is another method to better accomplish this. The only success I have really had with instrumenting my application is with the OTEL Python SDK to add the logger in my Python file. Any help would be greatly appreciated!