我正在尝试使用DBapi来捕获数据库命令,但是我没有看到任何要向Jaeger报告的东西。我正在使用pyodbc和熊猫访问数据库,在调试过程中,我发现没有出现异常,数据库中的数据也没有返回。我已经在我的本地码头配置了Jaeger,如果我使用简单的入门示例,我可以发送数据:
with tracer.start_as_current_span("foo"):
with tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
print("Hello world from OpenTelemetry Python!")我假设DBapi是通向数据库的pyodbc连接的正确库(我使用的是Azure )。有更好的图书馆吗?
我正在运行Python3.7.8。64位Requirements.txt是附加的(在底部)。请记住,这些是主程序的库。我只保留了其中的一小部分--附在下面,可以很容易地复制这个问题。
复制的步骤尝试运行上面的代码。您需要调整数据库访问和sql命令。
预期的行为是什么?根据我最近在.NET中使用.NET的经验,我希望看到捕获数据库命令并将信息发送给Jaeger
实际的行为是什么?忽略数据库命令。
我是做错了什么,还是一个真正的问题?
提前谢谢你!
Requirements.txt
aniso8601==9.0.1
api==0.0.7
asgiref==3.4.1
attrs==20.3.0
cachetools==4.2.1
certifi==2020.11.8
chardet==3.0.4
click==7.1.2
Deprecated==1.2.12
Flask==1.1.2
Flask-RESTful==0.3.8
flask-restplus==0.13.0
Flask-Testing==0.8.1
grpcio==1.39.0
idna==2.10
importlib-metadata==4.0.0
influxdb==5.3.1
install==1.3.4
itsdangerous==1.1.0
Jinja2==2.11.3
jsonschema==3.2.0
Logentries==0.17
MarkupSafe==1.1.1
msgpack==1.0.2
nose==1.3.7
numpy==1.19.3
opentelemetry-api==1.4.1
opentelemetry-exporter-jaeger==1.4.1
opentelemetry-exporter-jaeger-proto-grpc==1.4.1
opentelemetry-exporter-jaeger-thrift==1.4.1
opentelemetry-exporter-zipkin==1.4.1
opentelemetry-exporter-zipkin-json==1.4.1
opentelemetry-exporter-zipkin-proto-http==1.4.1
opentelemetry-instrumentation==0.23b2
opentelemetry-instrumentation-dbapi==0.23b2
opentelemetry-instrumentation-flask==0.23b2
opentelemetry-instrumentation-requests==0.23b2
opentelemetry-instrumentation-wsgi==0.23b2
opentelemetry-sdk==1.4.1
opentelemetry-semantic-conventions==0.23b2
opentelemetry-util-http==0.23b2
pandas==1.1.4
protobuf==3.17.3
pyodbc==4.0.30
pyrsistent==0.17.3
python-dateutil==2.8.1
pytz==2020.4
PyYAML==5.3.1
requests==2.25.0
six==1.15.0
smart-open==5.0.0
thrift==0.13.0
timeloop==1.0.2
typing==3.7.4.3
typing-extensions==3.7.4.3
urllib3==1.26.2
Werkzeug==0.15.5
wrapt==1.12.1
zipp==3.4.1
Python代码
import os
from smart_open import open
from flask import Flask, request, jsonify, abort
from flask_restplus import reqparse, Api, Resource, fields
from datetime import datetime
from timeloop import Timeloop
from datetime import timedelta
import pandas as pd
import time
import pyodbc
from opentelemetry import trace
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.exporter.zipkin.json import ZipkinExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (BatchSpanProcessor)
from opentelemetry.instrumentation.dbapi import trace_integration
pools_connection_string = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=SERVER;Database=DATABASE_NAME;Uid=USER_NAME;pwd=PASSWORD;"
app = Flask(__name__)
trace.set_tracer_provider(TracerProvider())
jaeger_exporter = JaegerExporter(
agent_host_name="localhost",
agent_port=6831,
)
zipkin_exporter = ZipkinExporter(
endpoint="http://localhost:9411/api/v2/spans"
)
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(jaeger_exporter))
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(zipkin_exporter))
FlaskInstrumentor().instrument_app(app)
RequestsInstrumentor().instrument()
trace_integration(pyodbc, "Connection", "odbc")
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("foo"):
with tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
print("Hello world from OpenTelemetry Python!")
connection = pyodbc.connect(pools_connection_string, ansi=True, autocommit=True)
sql = """
with t as
(select GeoAssetID,
Grade,
PriceAtLastUpdate as BunkerPrice,
LastUpdated as PriceDate,
row_number() over (partition by Grade, GeoAssetID order by LastUpdated desc) as row
from [Rates] bp with (nolock)
where GeoAssetID in (3763)
)
select * from t where row = 1 order by GeoAssetID
"""
df = pd.read_sql(sql, con=connection)
tl = Timeloop()
tl.job(interval=timedelta(seconds=14400))
tl.start()
if __name__ == '__main__':
app.run(host='localhost', port=2180, threaded=True)发布于 2021-10-07 09:03:48
最后,我不得不将“连接”改为“连接”。
将trace_integration(pyodbc、"Connection“、"odbc")替换为trace_integration(pyodbc、”Connection“、"odbc")
在文档中似乎有一个错误,这个错误将被修复。
我要结束这个问题。
https://stackoverflow.com/questions/68801304
复制相似问题