我尝试使用opentelemetry
和open telemetry-otlp
通过OTLP向Honeycomb提供可观测性数据。
我使用类似的东西作为概念证明(如果你想运行它,请提取到这个repo中:(第10页)
fn init_tracer(metadata: &MetadataMap) -> Result<sdktrace::Tracer, TraceError> {
let opentelemetry_endpoint =
env::var("OTEL_ENDPOINT").unwrap_or_else(|_| "https://api.honeycomb.io".to_owned());
let opentelemetry_endpoint =
Url::parse(&opentelemetry_endpoint).expect("OTEL_ENDPOINT is not a valid url");
opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(opentelemetry_endpoint.as_str())
.with_metadata(metadata.clone())
.with_tls_config(
ClientTlsConfig::new().domain_name(
opentelemetry_endpoint
.host_str()
.expect("OTEL_ENDPOINTshould have a valid host"),
),
),
)
.install_batch(opentelemetry::runtime::Tokio)
}
# [tokio::main]
async fn main() -> anyhow::Result<()> {
let mut metadata = MetadataMap::with_capacity(2);
metadata.insert(
"x-honeycomb-team",
"...honeycomb api key...".parse().unwrap(),
);
metadata.insert("x-honeycomb-dataset", "my-api".parse().unwrap());
let tracer = init_tracer(&metadata).expect("failed to instantiate opentelemetry tracing");
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::from_default_env())
.with(tracing_opentelemetry::layer().with_tracer(tracer))
.with(tracing_subscriber::fmt::layer())
.try_init()
.expect("failed to register tracer with registry");
let tracer = global::tracer("ex.com/basic");
但我得到的是:
2022-11-02T17:01:01.088429Z DEBUG hyper::client::connect::http: connecting to 52.5.162.226:443
2022-11-02T17:01:01.170767Z DEBUG hyper::client::connect::http: connected to 52.5.162.226:443
2022-11-02T17:01:01.171870Z DEBUG rustls::client::hs: No cached session for DnsName(DnsName(DnsName("api.honeycomb.io")))
2022-11-02T17:01:01.172555Z DEBUG rustls::client::hs: Not resuming any session
2022-11-02T17:01:01.269218Z DEBUG rustls::client::hs: ALPN protocol is Some(b"h2")
2022-11-02T17:01:01.269398Z DEBUG rustls::client::hs: Using ciphersuite TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
2022-11-02T17:01:01.269504Z DEBUG rustls::client::tls12::server_hello: Server supports tickets
2022-11-02T17:01:01.269766Z DEBUG rustls::client::tls12: ECDHE curve is ECParameters { curve_type: NamedCurve, named_group: secp256r1 }
2022-11-02T17:01:01.269843Z DEBUG rustls::client::tls12: Server DNS name is DnsName(DnsName(DnsName("api.honeycomb.io")))
2022-11-02T17:01:01.271123Z WARN rustls::conn: Sending fatal alert BadCertificate
2022-11-02T17:01:01.271861Z DEBUG tonic::transport::service::reconnect: reconnect::poll_ready: hyper::Error(Connect, Custom { kind: InvalidData, error: InvalidCertificateData("invalid peer certificate: UnknownIssuer") })
2022-11-02T17:01:01.271967Z DEBUG tower::buffer::worker: service.ready=true processing request
2022-11-02T17:01:01.272169Z DEBUG tonic::transport::service::reconnect: error: error trying to connect: invalid peer certificate contents: invalid peer certificate: UnknownIssuer
OpenTelemetry trace error occurred. Exporter otlp encountered the following error(s): the grpc server returns error (The service is currently unavailable): , detailed error message: error trying to connect: invalid peer certificate contents: invalid peer certificate: UnknownIssuer
这似乎表明我的TLS设置有些地方不正确...有没有人有Rust中的opentelemetry
代码片段可以与Honeycomb一起工作?
2条答案
按热度按时间ddrv8njm1#
问题是:您需要为ClientTlsConfig提供一个根证书,目标站点(api.honeycomb.io)将链接回该证书。
我发现一个合适的根证书安装在我的容器中,然后让程序加载它。
下面是代码:
前两行是新的;它们从文件系统加载一个根证书,然后用它来配置ClientTlsConfig。
我根据证书详细信息输出选择了根证书文件:
openssl s_client -connect api.honeycomb.io:443 -servername localhost
证书链中的最后一个条目类似于文件名。它包括:
/CN=Starfield Services Root Certificate Authority - G2
个332nm8kg2#
除了@jessitron的答案,我还可以使用一个单独的OpenTelemetry收集器服务让Honeycomb与Rust服务一起工作。
这样,您就可以使用更简单的配置向收集器Ala报告跟踪:
作为最后一个帮助,如果您使用Helm图表部署收集器,您将需要使用类似于以下内容的配置:
再次感谢@jessitron的离合器帮助。:)