feat(relay): remove direct integration with Google Cloud Trace (#2054)

This exporter never worked reliably and we have since switched to
running an OTLP collector as a side-car.
This commit is contained in:
Thomas Eizinger
2023-09-13 14:00:43 +10:00
committed by GitHub
parent 0de7b3e783
commit 178b68d770
3 changed files with 8 additions and 229 deletions

174
rust/Cargo.lock generated
View File

@@ -876,15 +876,6 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484"
[[package]]
name = "crc32fast"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.8"
@@ -1045,9 +1036,6 @@ name = "deranged"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946"
dependencies = [
"serde",
]
[[package]]
name = "derive_more"
@@ -1079,27 +1067,6 @@ dependencies = [
"subtle",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if 1.0.0",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "displaydoc"
version = "0.2.4"
@@ -1338,16 +1305,6 @@ dependencies = [
"wintun",
]
[[package]]
name = "flate2"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]]
name = "fnv"
version = "1.0.7"
@@ -1465,31 +1422,6 @@ dependencies = [
"url",
]
[[package]]
name = "gcp_auth"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ab5724fa45095bf1965ff491e75182818ba13f2a8755b04d484a9ec6408b622"
dependencies = [
"async-trait",
"base64 0.21.4",
"dirs-next",
"hyper",
"hyper-rustls",
"ring",
"rustls 0.20.9",
"rustls-pemfile",
"serde",
"serde_json",
"thiserror",
"time",
"tokio",
"tracing",
"tracing-futures",
"url",
"which",
]
[[package]]
name = "generic-array"
version = "0.14.7"
@@ -1723,20 +1655,6 @@ dependencies = [
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c"
dependencies = [
"http",
"hyper",
"rustls 0.20.9",
"rustls-native-certs",
"tokio",
"tokio-rustls 0.23.4",
]
[[package]]
name = "hyper-timeout"
version = "0.4.1"
@@ -2406,35 +2324,6 @@ dependencies = [
"tonic",
]
[[package]]
name = "opentelemetry-semantic-conventions"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24e33428e6bf08c6f7fcea4ddb8e358fab0fe48ab877a87c70c6ebe20f673ce5"
dependencies = [
"opentelemetry",
]
[[package]]
name = "opentelemetry-stackdriver"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff78d1abfa634182471924e542004d1b46996a31a481da114eda4abaad9d5b61"
dependencies = [
"async-trait",
"futures",
"gcp_auth",
"hex",
"http",
"hyper",
"opentelemetry",
"opentelemetry-semantic-conventions",
"prost",
"prost-types",
"thiserror",
"tonic",
]
[[package]]
name = "opentelemetry_api"
version = "0.19.0"
@@ -2529,7 +2418,7 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall 0.3.5",
"redox_syscall",
"smallvec",
"windows-targets 0.48.5",
]
@@ -2780,15 +2669,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "prost-types"
version = "0.11.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13"
dependencies = [
"prost",
]
[[package]]
name = "quick-error"
version = "1.2.3"
@@ -2875,15 +2755,6 @@ dependencies = [
"url",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
@@ -2893,17 +2764,6 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_users"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom",
"redox_syscall 0.2.16",
"thiserror",
]
[[package]]
name = "regex"
version = "1.9.5"
@@ -2967,7 +2827,6 @@ dependencies = [
"once_cell",
"opentelemetry",
"opentelemetry-otlp",
"opentelemetry-stackdriver",
"phoenix-channel",
"prometheus-client",
"proptest",
@@ -3112,18 +2971,6 @@ dependencies = [
"webpki 0.21.4",
]
[[package]]
name = "rustls"
version = "0.20.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99"
dependencies = [
"log",
"ring",
"sct 0.7.0",
"webpki 0.22.1",
]
[[package]]
name = "rustls"
version = "0.21.7"
@@ -3637,7 +3484,7 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
dependencies = [
"cfg-if 1.0.0",
"fastrand",
"redox_syscall 0.3.5",
"redox_syscall",
"rustix",
"windows-sys 0.48.0",
]
@@ -3776,17 +3623,6 @@ dependencies = [
"syn 2.0.31",
]
[[package]]
name = "tokio-rustls"
version = "0.23.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59"
dependencies = [
"rustls 0.20.9",
"tokio",
"webpki 0.22.1",
]
[[package]]
name = "tokio-rustls"
version = "0.24.1"
@@ -3819,7 +3655,7 @@ dependencies = [
"rustls 0.21.7",
"rustls-native-certs",
"tokio",
"tokio-rustls 0.24.1",
"tokio-rustls",
"tungstenite",
"webpki-roots",
]
@@ -3849,7 +3685,6 @@ dependencies = [
"axum",
"base64 0.13.1",
"bytes",
"flate2",
"futures-core",
"futures-util",
"h2",
@@ -3861,10 +3696,7 @@ dependencies = [
"pin-project",
"prost",
"prost-derive",
"rustls-native-certs",
"rustls-pemfile",
"tokio",
"tokio-rustls 0.23.4",
"tokio-stream",
"tokio-util",
"tower",

View File

@@ -16,7 +16,6 @@ tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread", "net", "t
tracing = { version = "0.1.37", features = ["log"] }
tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "fmt"] }
tracing-stackdriver = { version = "0.7.2", features = ["opentelemetry"] }
opentelemetry-stackdriver = { version = "0.16.0", default-features = false, features = ["gcp_auth", "tls-native-roots"] }
tracing-opentelemetry = "0.19.0"
opentelemetry = { version = "0.19.0", features = ["rt-tokio"] }
opentelemetry-otlp = "0.12.0"

View File

@@ -2,10 +2,7 @@ use anyhow::{anyhow, bail, Context, Result};
use clap::Parser;
use futures::channel::mpsc;
use futures::{future, FutureExt, SinkExt, StreamExt};
use opentelemetry::sdk::trace::TracerProvider;
use opentelemetry::trace::TracerProvider as _;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_stackdriver::Authorizer;
use phoenix_channel::{Error, Event, PhoenixChannel};
use prometheus_client::registry::Registry;
use rand::rngs::StdRng;
@@ -94,8 +91,6 @@ enum LogFormat {
#[derive(clap::ValueEnum, Debug, Clone, Copy)]
enum TraceCollector {
/// Sends traces to Google Cloud Trace.
GoogleCloudTrace,
/// Sends traces to an OTLP collector.
Otlp,
}
@@ -203,17 +198,6 @@ async fn main() -> Result<()> {
///
/// See [`log_layer`] for details on the base log layer.
///
/// ## Integration with Google Cloud Trace
///
/// If the user has specified [`TraceCollector::GoogleCloudTrace`], we will attempt to connect to Google Cloud Trace.
/// This requires authentication.
/// Here is how we will attempt to obtain those, for details see <https://docs.rs/gcp_auth/0.9.0/gcp_auth/struct.AuthenticationManager.html#method.new>.
///
/// 1. Check if the `GOOGLE_APPLICATION_CREDENTIALS` environment variable if set; if so, use a custom service account as the token source.
/// 2. Look for credentials in `.config/gcloud/application_default_credentials.json`; if found, use these credentials to request refresh tokens.
/// 3. Send a HTTP request to the internal metadata server to retrieve a token; if it succeeds, use the default service account as the token source.
/// 4. Check if the `gcloud` tool is available on the PATH; if so, use the `gcloud auth print-access-token` command as the token source.
///
/// ## Integration with OTLP
///
/// If the user has specified [`TraceCollector::Otlp`], we will set up an OTLP-exporter that connects to an OTLP collector specified at `Args.otlp_grpc_endpoint`.
@@ -221,44 +205,11 @@ async fn setup_tracing(args: &Args) -> Result<()> {
// Use `tracing_core` directly for the temp logger because that one does not initialize a `log` logger.
// A `log` Logger cannot be unset once set, so we can't use that for our temp logger during the setup.
let temp_logger_guard = tracing_core::dispatcher::set_default(
&tracing_subscriber::registry()
.with(log_layer(args, args.google_cloud_project_id.clone()))
.into(),
&tracing_subscriber::registry().with(log_layer(args)).into(),
);
let dispatch: Dispatch = match args.trace_collector {
None => tracing_subscriber::registry()
.with(log_layer(args, args.google_cloud_project_id.clone()))
.into(),
Some(TraceCollector::GoogleCloudTrace) => {
tracing::trace!("Setting up Google-Cloud-Trace collector");
let authorizer = opentelemetry_stackdriver::GcpAuthorizer::new()
.await
.context("Failed to find GCP credentials")?;
let project_id = authorizer.project_id().to_owned();
tracing::trace!(%project_id, "Successfully retrieved authentication token for Google services");
let (exporter, driver) = opentelemetry_stackdriver::Builder::default()
.build(authorizer)
.await
.context("Failed to create StackDriverExporter")?;
tokio::spawn(driver);
let tracer = TracerProvider::builder()
.with_batch_exporter(exporter, opentelemetry::runtime::Tokio)
.build()
.tracer("relay");
tracing::trace!("Successfully initialized trace provider on tokio runtime");
tracing_subscriber::registry()
.with(log_layer(args, Some(project_id)))
.with(tracing_opentelemetry::layer().with_tracer(tracer))
.into()
}
None => tracing_subscriber::registry().with(log_layer(args)).into(),
Some(TraceCollector::Otlp) => {
let grpc_endpoint = format!("http://{}", args.otlp_grpc_endpoint);
@@ -279,7 +230,7 @@ async fn setup_tracing(args: &Args) -> Result<()> {
// TODO: This is where we could also configure metrics.
tracing_subscriber::registry()
.with(log_layer(args, args.google_cloud_project_id.clone()))
.with(log_layer(args))
.with(tracing_opentelemetry::layer().with_tracer(tracer))
.into()
}
@@ -301,10 +252,7 @@ async fn setup_tracing(args: &Args) -> Result<()> {
/// - human-centered formatting
/// - JSON-formatting
/// - Google Cloud optimised formatting
fn log_layer<T>(
args: &Args,
google_cloud_trace_project_id: Option<String>,
) -> Box<dyn Layer<T> + Send + Sync>
fn log_layer<T>(args: &Args) -> Box<dyn Layer<T> + Send + Sync>
where
T: Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>,
{
@@ -312,7 +260,7 @@ where
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
let log_layer = match (args.log_format, google_cloud_trace_project_id) {
let log_layer = match (args.log_format, args.google_cloud_project_id.clone()) {
(LogFormat::Human, _) => tracing_subscriber::fmt::layer().boxed(),
(LogFormat::Json, _) => tracing_subscriber::fmt::layer().json().boxed(),
(LogFormat::GoogleCloud, None) => {