1

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

我认为 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”

谢谢

4

1 回答 1

1

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截至目前已损坏。

于 2021-05-22T19:00:32.760 回答