我有一个使用 Quart 的 python Web 应用程序。以下是我向其中添加样板 App Insights 请求遥测的方法:
...
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
bp = Blueprint("routes", __name__, static_folder='static')
def create_app():
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(BatchSpanProcessor(AzureMonitorTraceExporter()))
app = Quart(__name__)
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app, tracer_provider = tracer_provider)
app.register_blueprint(bp)
return app
...
我还将
APPLICATIONINSIGHTS_CONNECTION_STRING
环境变量设置为 App Insights 连接字符串。
它有效 - 我在 App Insights 中获得了样板请求遥测。
现在我想用自定义维度来丰富请求遥测。我知道它的理论:
customDimensions
。我们已在 Asp.Net 应用程序中实现了它。但我不知道如何使用 Quart 将其转换为 python Web 应用程序。
探索图书馆提供的示例怎么样
azure-monitor-opentelemetry
?