我在 Kubernetes 上部署了几个服务。有些基于 NodeJS,有些则基于 Java。集群中部署了 OTEL Collector,为 Prometheus 提供数据。 Grafana 用于仪表板。对于 Java,我使用
-javaagent:/jars/opentelemetry-javaagent.jar
,对于 NodeJS,我使用简单的跟踪文件,例如:
const sdk = new NodeSDK({
// Service name is configured by OTEL_SERVICE_NAME
traceExporter: new OTLPTraceExporter(),
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
exportIntervalMillis: 5000,
}),
instrumentations: [getNodeAutoInstrumentations()], // will contain https://www.npmjs.com/package/@opentelemetry/instrumentation-http
});
其余 OTEL 配置在 ENV 中定义(为了便于阅读,省略了跟踪配置):
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_METRICS_EXPORTER=otlp
OTEL_SERVICE_NAME=[service name]
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector-listens-here:4317
应用程序部署在 Kubernetes 上,每个应用程序有 2 个或更多 pod。我认为这就是为什么我得到
http_server_duration_milliseconds_count
指标奇怪结果的问题。查看示例:
这些指标的可用标签有:
http_flavor
http_method
http_route
http_scheme
http_status_code
job
net_host_name
net_host_port
net_protocol_name
net_protocol_version
我的假设是否正确,即没有办法区分 Pod,并且这些指标被视为来自同一个来源?我认为 ServiceA#pod1 导出值 1,然后 ServiceA#pod2(收到更多请求)导出 12之后 ServiceA@pod1 导出 3 个(因为它收到了 2 个新请求),依此类推?
如果是这样,解决这个问题的最佳解决方案是什么?
net_host_ip
,我希望将其设置为 pod IP,但在基于 Java 和 NodeJS 的检测中不会自动设置此属性。k8s_pod_name
这样的标签或其他东西
区分豆荚?service.instance.id
似乎是我的问题的“本机”解决方案,但它是实验状态任何建议或澄清将不胜感激:)
这是
service.instance.id
的预期用例。不幸的是,OpenTelemetry 规范中的实验性并没有表明某些东西的实验性或稳定性。
根据文档:
信号一开始是实验性的,涵盖信号的 alpha、beta 和发布候选版本。
service.instance.id
可能是安全的,因为它对于像您共享的用例(例如识别不同的 k8s pod)非常重要。然而,如何最好地生成此 ID 的定义可能会发生变化,但它旨在成为一个用于比较实例行为的不透明值。