- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个从 Apache2 提供的 Django Web 应用程序,在 Docker 容器中使用 mod_wsgi,该容器运行在 Google Cloud Platform 的 Kubernetes 集群上,受 Identity-Aware Proxy 保护。一切都很好,但我想为所有请求发送 GCP Stackdriver 跟踪,而不是为我的项目中的每个 View 编写一个。我使用 Opencensus 找到了处理这个问题的中间件。我经历了this documentation ,并且能够通过指定 StackdriverExporter
在我的项目中手动生成导出到 Stackdriver Trace 的跟踪。并通过 project_id
参数为 Google Cloud Platform Project Number
对于我的项目。
现在为了让所有请求都自动完成,我按照说明设置了中间件。在 settings.py 中,我将模块添加到 INSTALLED_APPS
, MIDDLEWARE
, 并设置 OPENCENSUS_TRACE
选项字典。我还添加了 OPENCENSUS_TRACE_PARAMS
.这适用于默认导出器“opencensus.trace.exporters.print_exporter.PrintExporter”,因为我可以在我的 Apache2 Web 服务器日志中看到 Trace 和 Span 信息,包括 Trace ID 和所有详细信息。但是,我想将这些发送到我的 Stackdriver Trace 处理器进行分析。
我尝试设置 EXPORTER
opencensus.trace.exporters.stackdriver_exporter.StackdriverExporter
的参数,只要您提供项目编号,它就可以在从 shell 手动运行时工作。
当它设置为使用 StackdriverExporter
,网页不会响应加载,健康检查开始失败,最终网页返回 502 错误,说明我应该在 30 秒后重试(我相信 Identity-Aware Proxy 正在生成此错误,一次它检测到失败的健康检查),但服务器没有生成错误,并且没有访问日志或 Apache2 错误。
settings.py 中有另一个字典,名为 OPENCENSUS_TRACE_PARAMS
,我认为需要确定导出商应该使用哪个项目编号。该示例有 GCP_EXPORTER_PROJECT
设为None
, 和 SERVICE_NAME
设为'my_service'
.
我需要设置哪些选项才能让导出器发送回 Stackdriver 而不是打印到日志?你知道我该如何设置吗?
设置.py
MIDDLEWARE = (
...
'opencensus.trace.ext.django.middleware.OpencensusMiddleware',
)
INSTALLED_APPS = (
...
'opencensus.trace.ext.django',
)
OPENCENSUS_TRACE = {
'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',
'EXPORTER': 'opencensus.trace.exporters.stackdriver_exporter.StackdriverExporter', # This one just makes the server hang with no response or error and kills the health check.
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.GoogleCloudFormatPropagator',
# 'EXPORTER': 'opencensus.trace.exporters.print_exporter.PrintExporter', # This one works to print the Trace and Span with IDs and details in the logs.
}
OPENCENSUS_TRACE_PARAMS = {
'BLACKLIST_PATHS': ['/health'],
'GCP_EXPORTER_PROJECT': 'my_project_number', # Should this be None like the example, or Project ID, or Project Number?
'SAMPLING_RATE': 0.5,
'SERVICE_NAME': 'my_service', # Not sure if this is my app name or some other service name.
'ZIPKIN_EXPORTER_HOST_NAME': 'localhost', # Are the following even necessary, or are they causing a failure that is not detected by Apache2?
'ZIPKIN_EXPORTER_PORT': 9411,
'ZIPKIN_EXPORTER_PROTOCOL': 'http',
'JAEGER_EXPORTER_HOST_NAME': None,
'JAEGER_EXPORTER_PORT': None,
'JAEGER_EXPORTER_AGENT_HOST_NAME': 'localhost',
'JAEGER_EXPORTER_AGENT_PORT': 6831
}
PrintExporter
时的示例(我美化了格式以提高可读性)。 :
[Fri Feb 08 09:00:32.427575 2019]
[wsgi:error]
[pid 1097:tid 139801302882048]
[client 10.48.0.1:43988]
[SpanData(
name='services.views.my_view',
context=SpanContext(
trace_id=e882f23e49e34fc09df621867d753532,
span_id=None,
trace_options=TraceOptions(enabled=True),
tracestate=None
),
span_id='bcbe7b96906a482a',
parent_span_id=None,
attributes={
'http.status_code': '200',
'http.method': 'GET',
'http.url': '/',
'django.user.name': ''
},
start_time='2019-02-08T17:00:29.845733Z',
end_time='2019-02-08T17:00:32.427455Z',
child_span_count=0,
stack_trace=None,
time_events=[],
links=[],
status=None,
same_process_as_parent_span=None,
span_kind=1
)]
# Initialize the exporter
transport = convert_to_import(settings.params.get(TRANSPORT))
if self._exporter.__name__ == 'GoogleCloudExporter':
_project_id = settings.params.get(GCP_EXPORTER_PROJECT, None)
self.exporter = self._exporter(
project_id=_project_id,
transport=transport)
elif self._exporter.__name__ == 'ZipkinExporter':
_service_name = self._get_service_name(settings.params)
_zipkin_host_name = settings.params.get(
ZIPKIN_EXPORTER_HOST_NAME, 'localhost')
_zipkin_port = settings.params.get(
ZIPKIN_EXPORTER_PORT, 9411)
_zipkin_protocol = settings.params.get(
ZIPKIN_EXPORTER_PROTOCOL, 'http')
self.exporter = self._exporter(
service_name=_service_name,
host_name=_zipkin_host_name,
port=_zipkin_port,
protocol=_zipkin_protocol,
transport=transport)
elif self._exporter.__name__ == 'TraceExporter':
_service_name = self._get_service_name(settings.params)
_endpoint = settings.params.get(
OCAGENT_TRACE_EXPORTER_ENDPOINT, None)
self.exporter = self._exporter(
service_name=_service_name,
endpoint=_endpoint,
transport=transport)
elif self._exporter.__name__ == 'JaegerExporter':
_service_name = self._get_service_name(settings.params)
self.exporter = self._exporter(
service_name=_service_name,
transport=transport)
else:
self.exporter = self._exporter(transport=transport)
StackdriverExporter
, 而不是
GoogleCloudExporter
.我在我的应用程序中设置了一个名为
GoogleCloudExporter
的类(class)继承
StackdriverExporter
,并更新了我的 settings.py 以使用
GoogleCloudExporter
,但它似乎没有工作,我想知道是否有其他代码引用这些旧命名方案,可能用于传输。我正在寻找源代码中的线索...这至少告诉我我可以摆脱 ZIPKIN 和 JAEGER 参数选项,因为这是在
EXPORTER
上确定的。参数。
CMD ["python", "/path/to/manage.py", "runserver", "0.0.0.0:80"]
它有效!当我访问该站点时,它会为每个请求将跟踪写入 Stackdriver Trace,Span 名称是正在执行的模块和方法。
最佳答案
我在使用带有 gevent 作为 worker 类(Class)的 gunicorn 时遇到了这个问题。要解决并使云跟踪工作,解决方案是像这样猴子补丁 grpc
from gevent import monkey
monkey.patch_all()
import grpc.experimental.gevent as grpc_gevent
grpc_gevent.init_gevent()
关于Google Kubernetes Engine 上的 Django、Apache2 将 Opencensus Traces 写入 Stackdriver Trace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54597464/
我正在尝试使用 OpenCensus 和 Azure Application Insights 在 Python 中发送指标。 理想情况下,我想发送一些具有任意结构的 Python 字典,但是 Ope
我正在使用 Opencensus 在有 10 个工作人员的 grpc 服务器上做一些监控。我的问题是,在制作示踪剂时,示踪剂的导出商应该是本地的还是全局的。浏览器 这是服务器: server = gr
本文整理了Java中io.opencensus.contrib.zpages.ZPageHandlers类的一些代码示例,展示了ZPageHandlers类的具体用法。这些代码示例主要来源于Githu
我正在尝试使用 OpenCensus 将 django 项目日志连接到 Azure Application Insights。 middleware对于 montirong 请求效果很好,但我也想发送
我正在尝试使用 OpenCensus 从我的 Go 应用程序向 Stackdriver 发送自定义指标。 我关注了 guide ,因此设置了 View 和导出器: import ( "cont
本文整理了Java中io.opencensus.exporter.trace.zipkin.ZipkinTraceExporter类的一些代码示例,展示了ZipkinTraceExporter类的具体
使用 opencensus Azure 启动日志后,我无法导入 mlflow。MLFlow 导入将永远运行。 我的环境如下: Python 3.7 opencensus-ext-azure 1.0.7
本文整理了Java中io.opencensus.contrib.zpages.ZPageHandlers.startHttpServerAndRegisterAll()方法的一些代码示例,展示了ZPa
先决条件:Node.js应用Opencensus图书馆Zipkin Exporter和本地的 Zipkin 服务 app.js : const tracing = require('@open
本文整理了Java中io.opencensus.exporter.trace.zipkin.ZipkinTraceExporter.unregister()方法的一些代码示例,展示了ZipkinTra
本文整理了Java中io.opencensus.exporter.trace.zipkin.ZipkinTraceExporter.register()方法的一些代码示例,展示了ZipkinTrace
我是 Google PubSub 的新手。我在客户端库中使用 GoLang。 如何查看 google-cloud-go 库记录的 opencensus 指标? 我已经成功向 Google PubSub
我在 apache karaf 4.2.6 和 java 11 中有一个模块,可以验证 Google Play 中的购买收据。我正在使用 androidpublisher。 当它第一次发送请求时,我在
我在销售我的 go-project 时遇到问题。尝试使用 glide 和 go-dep - 遇到同样的问题。 $ go get -u go.opencensus.io 给出以下错误: package
我正在使用以下函数将一些日志记录标准输出从 Databricks 发送到 Azure 应用程序洞察日志。 我的功能 import logging from opencensus.ext.azure.l
在 the documentation关于如何使用 opencensus-python 将跟踪提交到 Azure Application Insights,详细说明了如何向 customDimensi
在 the documentation关于如何使用 opencensus-python 将跟踪提交到 Azure Application Insights,详细说明了如何向 customDimensi
我正在将包含 Python 应用程序的容器部署到 GKE,但在尝试使用 OpenCensus 发送跟踪消息时遇到错误: Traceback (most recent call last): Fil
我正在使用 OpenCensus 比较不同的跟踪后端。我已经有了使用 Zipkin 和 Azure Monitor 运行良好的简单 OpenCensus.io python 示例。 现在我正在尝试使用
In the docs它说要安装云客户端库(pip install google-cloud-monitoring)。但是,云客户端库在应用程序引擎上的 python2 标准环境中不可用,descri
我是一名优秀的程序员,十分优秀!