在Python Flask应用程序中使用遥测自动检测,如何避免手动调用FlaskInstrumentor()?

在Python Flask应用程序中使用遥测自动检测,如何避免手动调用FlaskInstrumentor()?,python,flask,open-telemetry,Python,Flask,Open Telemetry,我正在学习使用基于Python Flask的应用程序进行遥测自动检测。问题是我的应用程序不会生成跟踪,除非我手动调用FlaskInstrumentor().instrument_应用程序(应用程序) 我假设auto_instrumentation/sitecustomize.py会以某种方式实现这一点,但它似乎不是这样工作的 我的代码: from flask import Flask, request from opentelemetry import trace from opentelem

我正在学习使用基于Python Flask的应用程序进行遥测自动检测。问题是我的应用程序不会生成跟踪,除非我手动调用FlaskInstrumentor().instrument_应用程序(应用程序)

我假设auto_instrumentation/sitecustomize.py会以某种方式实现这一点,但它似乎不是这样工作的

我的代码:

from flask import Flask, request

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
    SimpleSpanProcessor,
)
from opentelemetry.exporter.zipkin.json import ZipkinExporter
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
PORT = 8000
MESSAGE = "Hello, world!\n"

app = Flask(__name__)

# create a ZipkinExporter
zipkin_exporter = ZipkinExporter(
)

trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
    SimpleSpanProcessor(zipkin_exporter)
)


FlaskInstrumentor().instrument_app(app)


@app.route("/")
def root():
    result = MESSAGE.encode("utf-8")
    return result


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=PORT)
套餐:

opentelemetry-api==1.2.0
opentelemetry-sdk==1.2.0
opentelemetry-instrumentation-flask==0.21b0
opentelemetry-instrumentation==0.21b0
opentelemetry-distro==0.21b0
opentelemetry-exporter-zipkin==1.2.0 
我使用的命令:“opentelemetry instrument python3./server.py”


谢谢

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py
建议这样做


不幸的是,
https://opentelemetry-python-contrib.readthedocs.io/en/stable/instrumentation/flask/flask.html
从现在起已损坏。

谢谢!顺便说一句,我刚刚用我正在使用的实际代码更新了我的示例代码。你认为我使用自动仪器的方式正确吗?(我不喜欢设置zipkin_exporter和FlaskInstrumentor()的代码。instrument_应用程序(应用程序),但我还没有找到用配置键/环境变量替换它们的方法)。抱歉。我没有一个好的答案。谢谢戴夫。我已经找到了问题的根本原因。这是因为我在调试模式下运行了Flask。本期跟踪。在我按照这里所描述的进行更改之后,它起了作用