簡體   English   中英

將遙測自動檢測與 Python Flask 應用程序一起使用,如何避免手動調用 FlaskInstrumentor().instrument_app(app)?

[英]Using Telemetry auto instrumentation with Python Flask app, how to avoid calling FlaskInstrumentor().instrument_app(app) manually?

我正在使用基於 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”

謝謝

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目前已損壞。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM