Skip to content

Instantly share code, notes, and snippets.

@liamwh
Last active October 3, 2023 09:59
Show Gist options
  • Save liamwh/f5796b4ad852c267389cba661653b1c8 to your computer and use it in GitHub Desktop.
Save liamwh/f5796b4ad852c267389cba661653b1c8 to your computer and use it in GitHub Desktop.
Grafana not working
OTEL_EXPORTER_OTLP_PASS="TOKEN_HERE"
OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-eu-west-3.grafana.net/otlp"
OTEL_EXPORTER_OTLP_USER="632205"
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
frame: GoAway { error_code: FRAME_SIZE_ERROR, last_stream_id: StreamId(0) }
[2023-10-02T19:03:55.127Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] Connection::poll; connection error (error="GoAway(b"", FRAME_SIZE_ERROR, Library)",line=430,peer=Client,target=h2::proto::connection)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/proto/connection.rs
OpenTelemetry trace error occurred. Exporter otlp encountered the following error(s): the grpc server returns error (Unknown error): , detailed error message: h2 protocol error: http2 error: connection error detected: frame with invalid size
[2023-10-02T19:03:55.127Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - END] (elapsed_milliseconds=12,line=140,peer=Client,target=h2::proto::connection)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/proto/connection.rs
[2023-10-02T19:03:55.127Z] DEBUG: veloxide-server-localdev/25086 on PadCore: connection error: connection error detected: frame with invalid size (line=165,target=hyper::proto::h2::client)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/proto/h2/client.rs
[2023-10-02T19:03:55.127Z] DEBUG: veloxide-server-localdev/25086 on PadCore: client response error: connection error detected: frame with invalid size (line=321,target=hyper::proto::h2::client)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/proto/h2/client.rs
[2023-10-02T19:03:55.127Z] DEBUG: veloxide-server-localdev/25086 on PadCore: connection error: hyper::Error(Http2, Error { kind: GoAway(b"", FRAME_SIZE_ERROR, Library) }) (line=78,target=hyper::client::service)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/client/service.rs
[2023-10-02T19:04:00.096Z] DEBUG: veloxide-server-localdev/25086 on PadCore: resolving host="otlp-gateway-prod-eu-west-3.grafana.net" (line=122,target=hyper::client::connect::dns)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/client/connect/dns.rs
[2023-10-02T19:04:00.098Z] DEBUG: veloxide-server-localdev/25086 on PadCore: connecting to 20.31.17.143:443 (line=537,target=hyper::client::connect::http)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/client/connect/http.rs
[2023-10-02T19:04:00.111Z] DEBUG: veloxide-server-localdev/25086 on PadCore: connected to 20.31.17.143:443 (line=540,target=hyper::client::connect::http)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/client/connect/http.rs
[2023-10-02T19:04:00.112Z] DEBUG: veloxide-server-localdev/25086 on PadCore: binding client connection (line=1217,target=h2::client)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/client.rs
[2023-10-02T19:04:00.112Z] DEBUG: veloxide-server-localdev/25086 on PadCore: client connection bound (line=1222,target=h2::client)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/client.rs
[2023-10-02T19:04:00.112Z] DEBUG: veloxide-server-localdev/25086 on PadCore: send (line=232,target=h2::codec::framed_write)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/codec/framed_write.rs
--
frame: Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 }
[2023-10-02T19:04:00.112Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - START] (line=140,peer=Client,target=h2::proto::connection)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/proto/connection.rs
[2023-10-02T19:04:00.112Z] DEBUG: veloxide-server-localdev/25086 on PadCore: processing request (line=197,service.ready=true,target=tower::buffer::worker)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.4.13/src/buffer/worker.rs
[2023-10-02T19:04:00.112Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] send (line=232,peer=Client,target=h2::codec::framed_write)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/codec/framed_write.rs
--
frame: WindowUpdate { stream_id: StreamId(0), size_increment: 5177345 }
[2023-10-02T19:04:00.113Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] send (line=232,peer=Client,target=h2::codec::framed_write)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/codec/framed_write.rs
--
frame: Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) }
[2023-10-02T19:04:00.113Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] send (frame="Data { stream_id: StreamId(1) }",line=232,peer=Client,target=h2::codec::framed_write)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/codec/framed_write.rs
[2023-10-02T19:04:00.113Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] send (line=232,peer=Client,target=h2::codec::framed_write)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/codec/framed_write.rs
--
frame: Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) }
[2023-10-02T19:04:00.133Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] Connection::poll; connection error (error="GoAway(b"", FRAME_SIZE_ERROR, Library)",line=430,peer=Client,target=h2::proto::connection)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/proto/connection.rs
[2023-10-02T19:04:00.133Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] send (line=232,peer=Client,target=h2::codec::framed_write)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/codec/framed_write.rs
--
frame: GoAway { error_code: FRAME_SIZE_ERROR, last_stream_id: StreamId(0) }
[2023-10-02T19:04:00.133Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - EVENT] Connection::poll; connection error (error="GoAway(b"", FRAME_SIZE_ERROR, Library)",line=430,peer=Client,target=h2::proto::connection)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/proto/connection.rs
[2023-10-02T19:04:00.134Z] DEBUG: veloxide-server-localdev/25086 on PadCore: [CONNECTION - END] (elapsed_milliseconds=21,line=140,peer=Client,target=h2::proto::connection)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/h2-0.3.21/src/proto/connection.rs
[2023-10-02T19:04:00.134Z] DEBUG: veloxide-server-localdev/25086 on PadCore: connection error: connection error detected: frame with invalid size (line=165,target=hyper::proto::h2::client)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/proto/h2/client.rs
[2023-10-02T19:04:00.134Z] DEBUG: veloxide-server-localdev/25086 on PadCore: client response error: connection error detected: frame with invalid size (line=321,target=hyper::proto::h2::client)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/proto/h2/client.rs
OpenTelemetry trace error occurred. Exporter otlp encountered the following error(s): the grpc server returns error (Unknown error): , detailed error message: h2 protocol error: http2 error: connection error detected: frame with invalid size
[2023-10-02T19:04:00.134Z] DEBUG: veloxide-server-localdev/25086 on PadCore: connection error: hyper::Error(Http2, Error { kind: GoAway(b"", FRAME_SIZE_ERROR, Library) }) (line=78,target=hyper::client::service)
file: /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.27/src/client/service.rs
use std::collections::HashMap;
use base64::{engine::general_purpose, Engine as _};
use opentelemetry_otlp::WithExportConfig;
use tonic::metadata::MetadataMap;
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
const OTEL_EXPORTER_OTLP_ENDPOINT_ENV_VAR: &str = "OTEL_EXPORTER_OTLP_ENDPOINT";
const OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT: &str = "http://localhost:4317";
const OBSERVABILITY_SERVICE_NAME_ENV_VAR: &str = "OBSERVABILITY_SERVICE_NAME";
const OBSERVABILITY_SERVICE_NAME_DEFAULT: &str = "veloxide-server";
#[tracing::instrument]
pub fn configure_observability() -> std::result::Result<(), crate::error::Error> {
let otel_exporter_endpoint =
dotenvy::var(OTEL_EXPORTER_OTLP_ENDPOINT_ENV_VAR).unwrap_or_else(|_| {
tracing::warn!(
"{} Env var not set, using default",
OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT
);
OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT.to_string()
});
let mut headers: HashMap<String, String> = HashMap::new();
if let (Some(otel_user), Some(otel_pass)) = (
dotenvy::var("OTEL_EXPORTER_OTLP_USER").ok(),
dotenvy::var("OTEL_EXPORTER_OTLP_PASS").ok(),
) {
let credentials = format!("{}:{}", otel_user, otel_pass);
tracing::info!("OTEL_EXPORTER_OTLP_USER and OTEL_EXPORTER_OTLP_PASS are set");
let base64_credentials = general_purpose::STANDARD.encode(credentials);
let auth_value = format!("Basic {}", base64_credentials);
metadata.insert(
"authorization",
auth_value
.clone()
.parse()
.expect("Expected to parse auth_value into metadatamap value"),
);
headers.insert("authorization".to_string(), auth_value);
}
let observability_service_name = dotenvy::var(OBSERVABILITY_SERVICE_NAME_ENV_VAR)
.unwrap_or_else(|_| OBSERVABILITY_SERVICE_NAME_DEFAULT.to_string());
let client = reqwest::Client::new();
let http_exporter = opentelemetry_otlp::new_exporter()
.http()
.with_http_client(client)
.with_headers(headers)
.with_protocol(opentelemetry_otlp::Protocol::HttpBinary)
.with_endpoint(otel_exporter_endpoint);
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(http_exporter)
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
opentelemetry::sdk::Resource::new(vec![opentelemetry::KeyValue::new(
"service.name",
observability_service_name.clone(),
)]),
))
.install_batch(opentelemetry::runtime::Tokio)?;
// Create a tracing layer with the configured tracer
let telemetry_layer = tracing_opentelemetry::layer().with_tracer(tracer);
let filter = tracing_subscriber::EnvFilter::from_default_env();
cfg_if::cfg_if! {
if #[cfg(feature="bunyan")] {
// Create a new formatting layer to print bunyan formatted logs to stdout, pipe into bunyan to view
let formatting_layer = BunyanFormattingLayer::new(observability_service_name, std::io::stdout);
let subscriber = tracing_subscriber::Registry::default()
.with(filter)
.with(telemetry_layer)
.with(JsonStorageLayer)
.with(formatting_layer);
} else {
let subscriber = tracing_subscriber::Registry::default()
.with_filter(filter),
.with_writer(std::io::stdout)
.with(telemetry_layer);
}
}
Ok(tracing::subscriber::set_global_default(subscriber)?)
}
use base64::{engine::general_purpose, Engine as _};
use opentelemetry_otlp::WithExportConfig;
use tonic::metadata::MetadataMap;
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
const OTEL_EXPORTER_OTLP_ENDPOINT_ENV_VAR: &str = "OTEL_EXPORTER_OTLP_ENDPOINT";
const OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT: &str = "http://localhost:4317";
const OBSERVABILITY_SERVICE_NAME_ENV_VAR: &str = "OBSERVABILITY_SERVICE_NAME";
const OBSERVABILITY_SERVICE_NAME_DEFAULT: &str = "veloxide-server";
#[tracing::instrument]
pub fn configure_observability() -> std::result::Result<(), crate::error::Error> {
let otel_exporter_endpoint =
dotenvy::var(OTEL_EXPORTER_OTLP_ENDPOINT_ENV_VAR).unwrap_or_else(|_| {
tracing::warn!(
"{} Env var not set, using default",
OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT
);
OTEL_EXPORTER_OTLP_ENDPOINT_DEFAULT.to_string()
});
let mut metadata = MetadataMap::new();
if let (Some(otel_user), Some(otel_pass)) = (
dotenvy::var("OTEL_EXPORTER_OTLP_USER").ok(),
dotenvy::var("OTEL_EXPORTER_OTLP_PASS").ok(),
) {
tracing::info!("OTEL_EXPORTER_OTLP_USER and OTEL_EXPORTER_OTLP_PASS are set");
let credentials = format!("{}:{}", otel_user, otel_pass);
let base64_credentials = general_purpose::STANDARD.encode(credentials);
let auth_value = format!("Basic {}", base64_credentials);
metadata.insert(
"authorization",
auth_value
.parse()
.expect("Expected to parse auth_value into metadatamap value"),
);
}
let observability_service_name = dotenvy::var(OBSERVABILITY_SERVICE_NAME_ENV_VAR)
.unwrap_or_else(|_| OBSERVABILITY_SERVICE_NAME_DEFAULT.to_string());
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_metadata(metadata)
.with_protocol(opentelemetry_otlp::Protocol::HttpBinary)
.with_endpoint(otel_exporter_endpoint),
)
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
opentelemetry::sdk::Resource::new(vec![opentelemetry::KeyValue::new(
"service.name",
observability_service_name.clone(),
)]),
))
.install_batch(opentelemetry::runtime::Tokio)?;
// Create a tracing layer with the configured tracer
let telemetry_layer = tracing_opentelemetry::layer().with_tracer(tracer);
let filter = tracing_subscriber::EnvFilter::from_default_env();
cfg_if::cfg_if! {
if #[cfg(feature="bunyan")] {
// Create a new formatting layer to print bunyan formatted logs to stdout, pipe into bunyan to view
let formatting_layer = BunyanFormattingLayer::new(observability_service_name, std::io::stdout);
let subscriber = tracing_subscriber::Registry::default()
.with(filter)
.with(telemetry_layer)
.with(JsonStorageLayer)
.with(formatting_layer);
} else {
let subscriber = tracing_subscriber::Registry::default()
.with_filter(filter),
.with_writer(std::io::stdout)
.with(telemetry_layer);
}
}
Ok(tracing::subscriber::set_global_default(subscriber)?)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment