Skip to content

Commit

Permalink
use grafana otlp collector
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Nov 1, 2023
1 parent 62e3134 commit 50373cb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ module "leader" {

jwt_signature_pk_url = var.jwt_signature_pk_url

otlp_endpoint = var.otlp_endpoint
opentelemetry_level = var.opentelemetry_level

depends_on = [
google_secret_manager_secret_iam_member.account_creator_secret_access,
google_secret_manager_secret_iam_member.fast_auth_partners_secret_access,
Expand Down
9 changes: 8 additions & 1 deletion infra/modules/leader/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ resource "google_cloud_run_v2_service" "leader" {
}
}
}

env {
name = "MPC_RECOVERY_JWT_SIGNATURE_PK_URL"
value = var.jwt_signature_pk_url
}
env {
name = "MPC_RECOVERY_OTLP_ENDPOINT"
value = var.otlp_endpoint
}
env {
name = "MPC_RECOVERY_OPENTELEMETRY_LEVEL"
value = var.opentelemetry_level
}

env {
name = "RUST_LOG"
Expand Down
8 changes: 8 additions & 0 deletions infra/modules/leader/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ variable "fast_auth_partners_secret_id" {
variable "jwt_signature_pk_url" {
type = string
}

variable "otlp_endpoint" {
type = string
}

variable "opentelemetry_level" {
type = string
}
2 changes: 2 additions & 0 deletions infra/terraform-dev.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ signer_configs = [
}
]
jwt_signature_pk_url = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com"
otlp_endpoint = "http://otel.dev.api.pagoda.co:443"
opentelemetry_level = "debug"
10 changes: 10 additions & 0 deletions infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ variable "signer_configs" {
variable "jwt_signature_pk_url" {
type = string
}

variable "otlp_endpoint" {
type = string
default = "http://localhost:4317"
}

variable "opentelemetry_level" {
type = string
default = "off"
}
2 changes: 1 addition & 1 deletion mpc-recovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ hyper-rustls = { version = "=0.23", features = ["http2"] }
jsonwebtoken = "8.3.0"
lazy_static = "1.4.0"
opentelemetry = { version = "0.20.0", features = ["rt-tokio", "trace"] }
opentelemetry-otlp = "0.13.0"
opentelemetry-otlp = { version = "0.13.0", features = ["http-proto"] }
opentelemetry-semantic-conventions = "0.12.0"
prometheus = { version = "0.13.3", features = ["process"] }
rand = "0.7"
Expand Down
23 changes: 16 additions & 7 deletions mpc-recovery/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,20 @@ impl Display for ColorOutput {
#[derive(Debug, Default, clap::Parser)]
pub struct Options {
/// Enables export of span data using opentelemetry exporters.
#[clap(long, value_enum, default_value = "off")]
opentelemetry: OpenTelemetryLevel,
#[clap(
long,
env("MPC_RECOVERY_OPENTELEMETRY_LEVEL"),
value_enum,
default_value = "off"
)]
opentelemetry_level: OpenTelemetryLevel,

/// Opentelemetry gRPC collector endpoint.
#[clap(long, default_value = "http://localhost:4317")]
#[clap(
long,
env("MPC_RECOVERY_OTLP_ENDPOINT"),
default_value = "http://localhost:4317"
)]
otlp_endpoint: String,

/// Whether the log needs to be colored.
Expand All @@ -103,7 +112,7 @@ impl Options {
pub fn into_str_args(self) -> Vec<String> {
let mut buf = vec![
"--opentelemetry".to_string(),
self.opentelemetry.to_string(),
self.opentelemetry_level.to_string(),
"--otlp-endpoint".to_string(),
self.otlp_endpoint,
"--color".to_string(),
Expand Down Expand Up @@ -193,7 +202,7 @@ where
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.http()
.with_endpoint(otlp_endpoint),
)
.with_trace_config(
Expand All @@ -213,7 +222,7 @@ where
fn set_default_otlp_level(options: &Options) {
// Record the initial tracing level specified as a command-line flag. Use this recorded value to
// reset opentelemetry filter when the LogConfig file gets deleted.
DEFAULT_OTLP_LEVEL.set(options.opentelemetry).unwrap();
DEFAULT_OTLP_LEVEL.set(options.opentelemetry_level).unwrap();
}

/// The resource representing a registered subscriber.
Expand Down Expand Up @@ -287,7 +296,7 @@ pub async fn default_subscriber_with_opentelemetry(
.unwrap_or_else(|_| panic!("Failed to set Log Layer Filter"));

let (subscriber, handle) = add_opentelemetry_layer(
options.opentelemetry,
options.opentelemetry_level,
&options.otlp_endpoint,
env,
node_id,
Expand Down

0 comments on commit 50373cb

Please sign in to comment.