Python app logs not getting exported to elastic backend #3487
Unanswered
MadhusudanN
asked this question in
Q&A
Replies: 1 comment
-
Perhaps related: #3473 Could you try removing the env var and try using logger.WARNING instead to see if that works? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background ::
I have a python app which uses Flask server and have added GET Api which returns a string as response.
I wanted to check auto-instrumentation of logs feature as described in this link :: https://opentelemetry.io/docs/instrumentation/python/automatic/logs-example/
Problem ::
Logs are not getting exported to elastic backend. Python logging library is used as described in the above link
Excerpt of code below ::
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from flask import Flask
import logging
provider = TracerProvider()
trace.set_tracer_provider(provider)
tracer = trace.get_tracer(name)
app = Flask(name)
@app.route("/server_request")
def server_request():
print(request.args.get("param"))
logging.getLogger().info("Calling methodA()")
methodA()
return "served"
def methodA():
with tracer.start_as_current_span("methodA"):
span = trace.get_current_span()
print("Inside MethodA")
print("Calling MethodB")
logging.getLogger().info("Calling methodB()")
methodB()
def methodB():
with tracer.start_as_current_span("methodB"):
span = trace.get_current_span()
print("Inside MethodB")
print("Calling MethodC")
logging.getLogger().info("Calling methodC()")
methodC()
def methodC():
with tracer.start_as_current_span("methodC"):
span = trace.get_current_span()
print("Inside MethodC")
print("Calling MethodD")
logging.getLogger().info("Calling methodD()")
methodD()
def methodD():
with tracer.start_as_current_span("methodD"):
span = trace.get_current_span()
print("Inside MethodD")
print("Calling MethodE")
logging.getLogger().info("Calling methodE()")
methodE()
def methodE():
print("Inside MethodE")
print("Calling MethodF")
logging.getLogger().info("Calling methodF()")
methodF()
def methodF():
print("Inside MethodF")
print("Returning from MethodF")
logging.getLogger().info("Returning from MethodF")
if name == 'main':
app.run()
The below environment variables are set ::
OTEL_LOGS_EXPORTER = otlp
OTEL_PYTHON_LOG_LEVEL = info
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED = true
OTEL_EXPORTER_OTLP_ENDPOINT is set to APM server and OTEL_EXPORTER_OTLP_HEADERS is set to proper values
I am able to see traces in the elastic backend. Please find the screenshot below.

The app is launched with the below command ::
opentelemetry-instrument --traces_exporter console,otlp --metrics_exporter console,otlp --service_name test-logging python app.py
Host OS and Python details ::
Windows 11
Python :: 3.9.6
opentelemetry-instrument :: 0.40b0
Do not see any errors in the logs. PFA the logs file here.
logs.txt
Can someone please look into this and guide.
Beta Was this translation helpful? Give feedback.
All reactions