微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Django 中的 OpenTelemetry Python Auto Instrumentation 出现错误

如何解决Django 中的 OpenTelemetry Python Auto Instrumentation 出现错误

以下是我完成的设置:

export OTEL_TRACES_EXPORTER=otlp
export OTEL_RESOURCE_ATTRIBUTES=service.name=Communication
export OTEL_EXPORTER_OTLP_HEADERS=x-scope-orgid=XXXXX
export OTEL_PYTHON_LOG_CORRELATION=true
export OTEL_LOG_LEVEL=debug
export OTEL_PYTHON_LOG_LEVEL=debug
export DJANGO_SETTINGS_MODULE=nsl_vcs.settings.docker
export OTEL_PYTHON_DJANGO_TRACED_REQUEST_ATTRS='path_info,content_type'
export OTEL_PYTHON_TRACER_PROVIDER=sdk_tracer_provider
export OTEL_PYTHON_METER_PROVIDER=sdk_meter_provider

pip3 install opentelemetry-sdk
pip3 install opentelemetry-instrumentation-django
pip install opentelemetry-exporter-otlp

opentelemetry-bootstrap --action=install

opentelemetry-instrument python3 manage.py runserver --settings=nsl_vcs.settings.docker 0.0.0.0:7013 --noreload

所有命令都成功了,我没有看到任何错误。但是当我触发 REST 调用时,它给了我下面的错误。请注意,如果没有跟踪,我不会收到错误

opentelemetry-instrument python3 manage.py runserver --settings=nsl_vcs.settings.docker 0.0.0.0:7013 --noreload
2021-07-13 10:38:55,169 DEBUG [/home/nsluser/.local/lib/python3.8/site-packages/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py] [sitecustomize.py:82] [trace_id=0 span_id=0 resource.service.name=Communication] - Instrumented logging
2021-07-13 10:38:55,197 DEBUG [/home/nsluser/.local/lib/python3.8/site-packages/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py] [sitecustomize.py:82] [trace_id=0 span_id=0 resource.service.name=Communication] - Instrumented grpc_client
2021-07-13 10:38:55,199 DEBUG [/home/nsluser/.local/lib/python3.8/site-packages/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py] [sitecustomize.py:82] [trace_id=0 span_id=0 resource.service.name=Communication] - Instrumented grpc_server
path2 /home/nsluser/base/code/communications/nsl_vcs/payment_gateways/templates
ENV docker
2021-07-13 16:08:55,303 DEBUG [/home/nsluser/.local/lib/python3.8/site-packages/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py] [sitecustomize.py:82] [trace_id=0 span_id=0 resource.service.name=Communication] - Instrumented django
Performing system checks...

ENV From base import docker
System check identified no issues (0 silenced).
July 13,2021 - 16:08:55
Django version 2.1,using settings 'nsl_vcs.settings.docker'
Starting development server at http://0.0.0.0:7013/
Quit the server with CONTROL-C.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py",line 34,in inner
    response = get_response(request)
  File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py",line 117,in _get_response
    response = middleware_method(request,callback,callback_args,callback_kwargs)
  File "/home/nsluser/.local/lib/python3.8/site-packages/opentelemetry/instrumentation/django/middleware.py",line 174,in process_view
    route = getattr(match,"route")
AttributeError: 'ResolverMatch' object has no attribute 'route'

解决方法

这是一个开放遥测的问题,错过了 Django 2.1 的一个案例: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/581

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。