Skip to content

Commit

Permalink
Sentry (#44)
Browse files Browse the repository at this point in the history
* refactor: set sentry as optional

* refactor: set sentry as optional
  • Loading branch information
vicanso authored Oct 12, 2024
1 parent ec74050 commit 370e5fc
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
run: |
make release
ldd target/release/pingap
make release-sentry
ldd target/release/pingap
docker:
runs-on: ubuntu-latest
timeout-minutes: 3600
Expand Down
37 changes: 20 additions & 17 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ opentelemetry_sdk = { version = "0.24.1", features = [
"rt-tokio",
], default-features = false }
path-absolutize = "3.1.1"
pingora = { git = "https://github.com/cloudflare/pingora", rev = "0df7b0de1652e5a2639a6e0fd330516bf28d5999", default-features = false, features = [
pingora = { git = "https://github.com/cloudflare/pingora", rev = "9921fe422274ced5ef14eb582d63529859fed441", default-features = false, features = [
# pingora = { version = "0.3.0", default-features = false, features = [
"lb",
"openssl",
Expand All @@ -97,7 +97,7 @@ rust-embed = { version = "8.5.0", features = [
], default-features = false }
rustc_version_runtime = "0.3.0"
scopeguard = "1.2.0"
sentry = { version = "0.26", default-features = false }
sentry = { version = "0.26", default-features = false, optional = true }
serde = "1.0.210"
serde_json = "1.0.128"
sha2 = { version = "0.10.8", default-features = false }
Expand All @@ -122,13 +122,15 @@ url = "2.5.2"
urlencoding = "2.1.3"
uuid = { version = "1.10.0", features = [
"v7",
"std",
"fast-rng",
], default-features = false }
x509-parser = "0.16.0"

[features]
pyro = ["pyroscope", "pyroscope_pprofrs"]
perf = ["pyro", "dhat"]
tracking = ["sentry", "pingora/sentry"]


[dev-dependencies]
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ release:
cargo build --release
ls -lh target/release

release-sentry:
cargo build --release --features=tracking
ls -lh target/release

perf:
cargo build --profile=release-perf --features=perf
ls -lh target/release-perf
Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use state::{get_admin_addr, get_start_time, set_admin_addr};
use std::collections::HashMap;
use std::error::Error;
use std::path::Path;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use tracing::{error, info};
Expand All @@ -44,6 +43,8 @@ mod plugin;
mod proxy;
#[cfg(feature = "pyro")]
mod pyro;
#[cfg(feature = "tracking")]
mod sentry;
mod service;
mod state;
mod util;
Expand Down Expand Up @@ -380,13 +381,12 @@ fn run() -> Result<(), Box<dyn Error>> {
};
let mut my_server = server::Server::new(Some(opt))?;
my_server.configuration = Arc::new(new_server_conf(&args, &conf));
#[cfg(feature = "tracking")]
if let Some(dsn) = &basic_conf.sentry {
match sentry::types::Dsn::from_str(dsn) {
Ok(dsn) => {
my_server.sentry = Some(sentry::ClientOptions {
dsn: Some(dsn),
..Default::default()
});
match sentry::new_sentry_options(dsn) {
Ok(_opts) => {
// TODO enable pingora sentry
// my_server.sentry = Some(opts);
},
Err(e) => {
error!(error = e.to_string(), "sentry init fail");
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod response_headers;
mod stats;

pub static ADMIN_SERVER_PLUGIN: Lazy<String> =
Lazy::new(|| uuid::Uuid::new_v4().to_string());
Lazy::new(|| uuid::Uuid::now_v7().to_string());

pub fn parse_admin_plugin(addr: &str) -> (ServerConf, String, PluginConf) {
let arr: Vec<&str> = addr.split('@').collect();
Expand Down
25 changes: 25 additions & 0 deletions src/sentry/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 Tree xie.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use sentry::types::{Dsn, ParseDsnError};
use sentry::ClientOptions;
use std::str::FromStr;

pub fn new_sentry_options(dsn: &str) -> Result<ClientOptions, ParseDsnError> {
let dsn = Dsn::from_str(dsn)?;
Ok(ClientOptions {
dsn: Some(dsn),
..Default::default()
})
}

0 comments on commit 370e5fc

Please sign in to comment.