1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-02-22 18:33:18 +01:00
* Use matrix to test all versions.

* Add support for OTEL 0.16

* Typo.

* Fail on warnings.

* Inject headers when using OTEL 0.16.

* Fix.
This commit is contained in:
Luca Palmieri 2021-08-30 13:36:15 +02:00 committed by GitHub
parent 1f3ecfe182
commit 050bfe058d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 15 deletions

View File

@ -13,9 +13,12 @@ env:
CARGO_TERM_COLOR: always
jobs:
test:
test_without_otel:
name: Test
runs-on: ubuntu-latest
env:
# Fail the build if there are warnings
RUSTFLAGS: "-D warnings"
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
@ -35,18 +38,40 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
test_with_otel:
name: Test
runs-on: ubuntu-latest
env:
# Fail the build if there are warnings
RUSTFLAGS: "-D warnings"
strategy:
matrix:
otel_version:
- opentelemetry_0_13
- opentelemetry_0_14
- opentelemetry_0_15
- opentelemetry_0_16
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --features opentelemetry_0_13
- uses: actions-rs/cargo@v1
with:
command: test
args: --features opentelemetry_0_14
- uses: actions-rs/cargo@v1
with:
command: test
args: --features opentelemetry_0_15
args: --features ${{ matrix.otel_version }}
fmt:
name: Rustfmt

View File

@ -23,6 +23,7 @@ default = ["emit_event_on_error"]
opentelemetry_0_13 = ["opentelemetry_0_13_pkg", "tracing-opentelemetry_0_12_pkg"]
opentelemetry_0_14 = ["opentelemetry_0_14_pkg", "tracing-opentelemetry_0_13_pkg"]
opentelemetry_0_15 = ["opentelemetry_0_15_pkg", "tracing-opentelemetry_0_14_pkg"]
opentelemetry_0_16 = ["opentelemetry_0_16_pkg", "tracing-opentelemetry_0_15_pkg"]
emit_event_on_error = []
[dependencies]
@ -34,9 +35,11 @@ uuid = { version = "0.8.1", features = ["v4"] }
opentelemetry_0_13_pkg = { package = "opentelemetry", version = "0.13", optional = true }
opentelemetry_0_14_pkg = { package = "opentelemetry", version = "0.14", optional = true }
opentelemetry_0_15_pkg = { package = "opentelemetry", version = "0.15", optional = true }
opentelemetry_0_16_pkg = { package = "opentelemetry", version = "0.16", optional = true }
tracing-opentelemetry_0_12_pkg = { package = "tracing-opentelemetry",version = "0.12", optional = true }
tracing-opentelemetry_0_13_pkg = { package = "tracing-opentelemetry", version = "0.13", optional = true }
tracing-opentelemetry_0_14_pkg = { package = "tracing-opentelemetry",version = "0.14", optional = true }
tracing-opentelemetry_0_15_pkg = { package = "tracing-opentelemetry",version = "0.15", optional = true }
[dev-dependencies]
tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter"] }

View File

@ -35,7 +35,7 @@ Add `tracing-actix-web` to your dependencies:
```toml
[dependencies]
# ...
tracing-actix-web = "0.4.0-beta.10"
tracing-actix-web = "0.4.0-beta.11"
tracing = "0.1"
actix-web = "4.0.0-beta.8"
```
@ -45,6 +45,7 @@ actix-web = "4.0.0-beta.8"
- `opentelemetry_0_13`: attach [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-rust)'s context to the root span using `opentelemetry` 0.13;
- `opentelemetry_0_14`: same as above but using `opentelemetry` 0.14;
- `opentelemetry_0_15`: same as above but using `opentelemetry` 0.15;
- `opentelemetry_0_16`: same as above but using `opentelemetry` 0.16;
- `emit_event_on_error`: emit a [`tracing`] event when request processing fails with an error (enabled by default).
`tracing-actix-web` will release `0.4.0`, going out of beta, as soon as `actix-web` releases a stable `4.0.0`.

View File

@ -8,7 +8,7 @@
//! ```toml
//! [dependencies]
//! # ...
//! tracing-actix-web = "0.4.0-beta.10"
//! tracing-actix-web = "0.4.0-beta.11"
//! tracing = "0.1"
//! actix-web = "4.0.0-beta.8"
//! ```
@ -18,6 +18,7 @@
//! - `opentelemetry_0_13`: attach [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-rust)'s context to the root span using `opentelemetry` 0.13;
//! - `opentelemetry_0_14`: same as above but using `opentelemetry` 0.14;
//! - `opentelemetry_0_15`: same as above but using `opentelemetry` 0.15;
//! - `opentelemetry_0_16`: same as above but using `opentelemetry` 0.16;
//! - `emit_event_on_error`: emit a [`tracing`] event when request processing fails with an error (enabled by default).
//!
//! `tracing-actix-web` will release `0.4.0`, going out of beta, as soon as `actix-web` releases a stable `4.0.0`.
@ -243,7 +244,8 @@ pub mod root_span_macro;
#[cfg(any(
feature = "opentelemetry_0_13",
feature = "opentelemetry_0_14",
feature = "opentelemetry_0_15"
feature = "opentelemetry_0_15",
feature = "opentelemetry_0_16"
))]
mod otel;
@ -253,5 +255,14 @@ compile_error!("feature \"opentelemetry_0_13\" and feature \"opentelemetry_0_14\
#[cfg(all(feature = "opentelemetry_0_13", feature = "opentelemetry_0_15"))]
compile_error!("feature \"opentelemetry_0_13\" and feature \"opentelemetry_0_15\" cannot be enabled at the same time");
#[cfg(all(feature = "opentelemetry_0_13", feature = "opentelemetry_0_16"))]
compile_error!("feature \"opentelemetry_0_13\" and feature \"opentelemetry_0_16\" cannot be enabled at the same time");
#[cfg(all(feature = "opentelemetry_0_14", feature = "opentelemetry_0_15"))]
compile_error!("feature \"opentelemetry_0_14\" and feature \"opentelemetry_0_15\" cannot be enabled at the same time");
#[cfg(all(feature = "opentelemetry_0_14", feature = "opentelemetry_0_16"))]
compile_error!("feature \"opentelemetry_0_14\" and feature \"opentelemetry_0_16\" cannot be enabled at the same time");
#[cfg(all(feature = "opentelemetry_0_15", feature = "opentelemetry_0_16"))]
compile_error!("feature \"opentelemetry_0_15\" and feature \"opentelemetry_0_16\" cannot be enabled at the same time");

View File

@ -6,6 +6,8 @@ use opentelemetry_0_13_pkg as opentelemetry;
use opentelemetry_0_14_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_15")]
use opentelemetry_0_15_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_16")]
use opentelemetry_0_16_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_13")]
use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry;
@ -13,6 +15,8 @@ use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry;
use tracing_opentelemetry_0_13_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_15")]
use tracing_opentelemetry_0_14_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_16")]
use tracing_opentelemetry_0_15_pkg as tracing_opentelemetry;
use opentelemetry::propagation::Extractor;

View File

@ -97,7 +97,12 @@ macro_rules! root_span {
);
std::mem::drop(connection_info);
#[cfg(any(feature = "opentelemetry_0_13", feature = "opentelemetry_0_14", feature = "opentelemetry_0_15"))]
#[cfg(any(
feature = "opentelemetry_0_13",
feature = "opentelemetry_0_14",
feature = "opentelemetry_0_15",
feature = "opentelemetry_0_16"
))]
$crate::root_span_macro::private::set_otel_parent(&$request, &span);
span
@ -121,7 +126,8 @@ pub mod private {
#[cfg(any(
feature = "opentelemetry_0_13",
feature = "opentelemetry_0_14",
feature = "opentelemetry_0_15"
feature = "opentelemetry_0_15",
feature = "opentelemetry_0_16"
))]
#[doc(hidden)]
pub fn set_otel_parent(req: &ServiceRequest, span: &tracing::Span) {