Skip to content

Commit

Permalink
fix: Upgrade sentry-actix based on latest changes (#87)
Browse files Browse the repository at this point in the history
* ci: Test and lint all workspace packages and examples

* fix: Upgrade sentry-actix based on latest changes

* ci: Remove a default job from build matrix
  • Loading branch information
jan-auer authored Sep 19, 2018
1 parent 6d06bce commit 34e8e0e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ branches:

script: make $SUITE

env: # Needed for allow_failures

matrix:
include:
- env: SUITE=format-check
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ doc:

check-all-features:
@echo 'ALL FEATURES'
@RUSTFLAGS=-Dwarnings cargo check --all-features
@RUSTFLAGS=-Dwarnings cargo check --all-features --all --examples
.PHONY: check-all-features

check-no-default-features:
Expand Down Expand Up @@ -53,10 +53,15 @@ check-all-impls:
@RUSTFLAGS=-Dwarnings cargo check --no-default-features --features 'with_failure,with_log,with_panic,with_error_chain'
.PHONY: check-all-impls

check-actix:
@echo 'ACTIX INTEGRATION'
@RUSTFLAGS=-Dwarnings cargo check --manifest-path integrations/sentry-actix/Cargo.toml
.PHONY: check-actix

check: check-no-default-features check-default-features
.PHONY: check-all-features

checkall: check-all-features check-no-default-features check-default-features check-failure check-log check-panic check-error-chain check-all-impls
checkall: check-all-features check-no-default-features check-default-features check-failure check-log check-panic check-error-chain check-all-impls check-actix
.PHONY: checkall

cargotest:
Expand All @@ -66,7 +71,7 @@ cargotest:

cargotestall:
@echo 'TESTSUITE'
@cargo test --all-features
@cargo test --all-features --all --examples
.PHONY: cargotest

test: checkall cargotestall
Expand All @@ -79,7 +84,7 @@ format-check:

lint:
@rustup component add clippy-preview 2> /dev/null
@cargo clippy --all-features --tests -- -D clippy
@cargo clippy --all-features --tests --all --examples -- -D clippy
.PHONY: lint

travis-push-docs:
Expand Down
36 changes: 20 additions & 16 deletions integrations/sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use actix_web::middleware::{Middleware, Response, Started};
use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse};
use failure::Fail;
use sentry::integrations::failure::exception_from_single_fail;
use sentry::protocol::{ClientSdkPackageInfo, Event, Level};
use sentry::protocol::{ClientSdkPackage, Event, Level};
use sentry::{Hub, Uuid};
use std::borrow::Cow;
use std::sync::{Arc, Mutex};
Expand All @@ -93,13 +93,6 @@ pub struct SentryMiddlewareBuilder {
middleware: SentryMiddleware,
}

/// Reports certain failures to sentry.
pub struct SentryMiddleware {
hub: Option<Arc<Hub>>,
emit_header: bool,
capture_server_errors: bool,
}

impl SentryMiddlewareBuilder {
/// Finishes the building and returns a middleware
pub fn finish(self) -> SentryMiddleware {
Expand Down Expand Up @@ -133,6 +126,13 @@ impl SentryMiddlewareBuilder {
}
}

/// Reports certain failures to sentry.
pub struct SentryMiddleware {
hub: Option<Arc<Hub>>,
emit_header: bool,
capture_server_errors: bool,
}

impl SentryMiddleware {
/// Creates a new sentry middleware.
pub fn new() -> SentryMiddleware {
Expand All @@ -158,19 +158,23 @@ impl SentryMiddleware {
}
}

impl Default for SentryMiddleware {
fn default() -> Self {
SentryMiddleware::new()
}
}

fn extract_request<S: 'static>(
req: &HttpRequest<S>,
with_pii: bool,
) -> (Option<String>, sentry::protocol::Request) {
let resource = req.resource();
let transaction = if let Some(rdef) = resource.rdef() {
Some(rdef.pattern().to_string())
} else if resource.name() != "" {
Some(resource.name().to_string())
} else {
if resource.name() != "" {
Some(resource.name().to_string())
} else {
None
}
None
};
let mut sentry_req = sentry::protocol::Request {
url: format!(
Expand Down Expand Up @@ -229,8 +233,8 @@ impl<S: 'static> Middleware<S> for SentryMiddleware {

if let Some(sdk) = event.sdk.take() {
let mut sdk = sdk.into_owned();
sdk.packages.push(ClientSdkPackageInfo {
package_name: "sentry-actix".into(),
sdk.packages.push(ClientSdkPackage {
name: "sentry-actix".into(),
version: env!("CARGO_PKG_VERSION").into(),
});
event.sdk = Some(Cow::Owned(sdk));
Expand All @@ -255,7 +259,7 @@ impl<S: 'static> Middleware<S> for SentryMiddleware {
Some(event_id) if self.emit_header => {
resp.headers_mut().insert(
"x-sentry-event",
event_id.simple().to_string().parse().unwrap(),
event_id.to_simple_ref().to_string().parse().unwrap(),
);
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/backtrace_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ lazy_static!{
#[cfg(feature = "with_error_chain")] {
rv.push(("error_chain::make_backtrace", "<T as core::convert::Into<U>>::into"));
}
rv
{rv}
};

pub static ref COMMON_RUST_SYMBOL_ESCAPES_RE: Regex = Regex::new(r#"(?x)
Expand Down

0 comments on commit 34e8e0e

Please sign in to comment.