Compare commits

...

38 commits

Author SHA1 Message Date
asonix 22e03df3ff Add opentelemetry 0.21 to CI
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-11-13 12:44:38 -06:00
asonix dd2f7ffd5d Update opentelemetry dependencies 2023-11-13 12:43:07 -06:00
asonix 0663e5f331 Update toolchain 2023-11-13 12:33:06 -06:00
asonix 84482016c4 Stable tracing-actix-web
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-08-05 12:02:47 -05:00
asonix a60a5f69cb Update otlp for examples
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-04 19:00:37 -05:00
asonix 502619d91c Update example imports
Some checks failed
continuous-integration/drone/push Build is failing
2023-08-04 18:58:41 -05:00
asonix e9c3b62578 Add opentelemetry 0.20
Some checks failed
continuous-integration/drone/push Build is failing
2023-08-04 18:53:36 -05:00
asonix 9c3d864239 Update flake 2023-06-01 17:21:36 -05:00
asonix a72de00e2d Use stable tracing-actix-web
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-05-24 09:51:49 -05:00
asonix efa1d019f6 clippy
All checks were successful
continuous-integration/drone/push Build is passing
2023-05-23 16:47:03 -05:00
asonix 0a54e7aefa Update to opentelemetry 0.19
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-23 16:41:16 -05:00
asonix 2147358277 Update to otel 0.18
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-09-20 22:09:27 -05:00
Aode (lion) 9d92b3cd04 Bump version
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2022-04-06 20:42:50 -05:00
Aode (lion) 6f4c9b3bf9 Take spans on stream completion
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-06 18:33:37 -05:00
Aode (lion) dbd7a6f369 Add dummy inner spans with no parent
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-06 18:16:56 -05:00
Aode (lion) 107c091dfc Bump version
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/tag Build is passing
2022-04-06 16:51:41 -05:00
Aode (lion) 859f233ca2 Create body span on first poll
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-04-06 16:51:20 -05:00
Aode (lion) 9d44100e32 Remove follows-from relation for body
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-04-06 16:15:33 -05:00
Aode (Lion) d8f1f2e6f6 Update readme example
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-03-08 12:10:47 -06:00
Aode (Lion) 2e77029b50 Bump readme version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-03-08 11:52:22 -06:00
Aode (Lion) 410ceef25a Stable awc
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-03-08 11:11:02 -06:00
Aode (Lion) caf21d9d4f stable actix-web
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-02-26 11:52:50 -06:00
Aode (lion) e2d438aac7 Fix version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-02-11 10:59:28 -06:00
Aode (lion) bb8b3ef494 Actix-Web rc.3
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-11 10:59:01 -06:00
Aode (lion) 8e42442bb0 Stable tracing-awc
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-02-04 10:59:51 -06:00
Aode (lion) aa8c1500f5 Add support for opentelemetry 0.17
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-03 19:26:45 -06:00
Aode (Lion) 0c66c31d3c awc-beta.20
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-02-01 09:00:50 -06:00
Aode (lion) 0a154dd6f0 Bump actix web
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-23 22:17:46 -06:00
Aode (lion) 4ad8651f84 Bump version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-18 11:08:25 -06:00
Aode (lion) b220477135 Merge branch 'main' of git.asonix.dog:asonix/tracing-awc into main 2022-01-18 11:08:08 -06:00
Aode (lion) d9e79a3557 Update deps 2022-01-18 11:07:32 -06:00
Aode (Lion) 5fd4bb9066 Update awc.b18
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-06 11:24:51 -06:00
Aode (lion) 0b3c25b2e3 Update dependencies
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-12-30 10:10:14 -06:00
Aode (lion) 0cfa95c847 awc beta.15
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-12-28 10:00:26 -06:00
Aode (lion) 80b1620eed Update to latest rust-builder tags
All checks were successful
continuous-integration/drone/push Build is passing
2021-12-22 15:56:34 -06:00
Aode (lion) f72c442cab Update deps
All checks were successful
continuous-integration/drone/push Build is passing
2021-12-18 20:21:30 -06:00
Aode (lion) 640ecb06de published deps
All checks were successful
continuous-integration/drone/push Build is passing
2021-12-13 11:15:34 -06:00
Aode (lion) 4898546aa1 Update to latest beta
All checks were successful
continuous-integration/drone/push Build is passing
2021-12-12 14:36:05 -06:00
9 changed files with 476 additions and 125 deletions

View file

@ -18,7 +18,7 @@ steps:
- chown -R 991:991 .
- name: clippy
image: asonix/rust-builder:amd64-latest
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- rustup component add clippy
@ -27,11 +27,17 @@ steps:
- cargo clippy --features opentelemetry_0_14 -- -D warnings
- cargo clippy --features opentelemetry_0_15 -- -D warnings
- cargo clippy --features opentelemetry_0_16 -- -D warnings
- cargo clippy --example client --features opentelemetry_0_16 -- -D warnings
- cargo clippy --example server --features opentelemetry_0_16 -- -D warnings
- cargo clippy --features opentelemetry_0_17 -- -D warnings
- cargo clippy --features opentelemetry_0_18 -- -D warnings
- cargo clippy --features opentelemetry_0_19 -- -D warnings
- cargo clippy --features opentelemetry_0_20 -- -D warnings
- cargo clippy --features opentelemetry_0_21 -- -D warnings
- cargo clippy --example client --features opentelemetry_0_21 -- -D warnings
- cargo clippy --example server --features opentelemetry_0_21 -- -D warnings
trigger:
event:
- tag
- push
- pull_request
@ -57,13 +63,14 @@ steps:
- chown -R 991:991 .
- name: tests
image: asonix/rust-builder:amd64-latest
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- cargo test
trigger:
event:
- tag
- push
- pull_request
@ -89,12 +96,12 @@ steps:
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:amd64-latest
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- cargo check --target=x86_64-unknown-linux-musl
- cargo check --target=x86_64-unknown-linux-musl --example client --features opentelemetry_0_16
- cargo check --target=x86_64-unknown-linux-musl --example server --features opentelemetry_0_16
- cargo check --target=$TARGET
- cargo check --target=$TARGET --example client --features opentelemetry_0_21
- cargo check --target=$TARGET --example server --features opentelemetry_0_21
trigger:
event:
@ -123,12 +130,12 @@ steps:
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:arm64v8-latest
image: asonix/rust-builder:latest-linux-arm64v8
pull: always
commands:
- cargo check --target=aarch64-unknown-linux-musl
- cargo check --target=aarch64-unknown-linux-musl --example client --features opentelemetry_0_16
- cargo check --target=aarch64-unknown-linux-musl --example server --features opentelemetry_0_16
- cargo check --target=$TARGET
- cargo check --target=$TARGET --example client --features opentelemetry_0_21
- cargo check --target=$TARGET --example server --features opentelemetry_0_21
trigger:
event:
@ -157,14 +164,153 @@ steps:
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:arm32v7-latest
image: asonix/rust-builder:latest-linux-arm32v7
pull: always
commands:
- cargo check --target=armv7-unknown-linux-musleabihf
- cargo check --target=armv7-unknown-linux-musleabihf --example client --features opentelemetry_0_16
- cargo check --target=armv7-unknown-linux-musleabihf --example server --features opentelemetry_0_16
- cargo check --target=$TARGET
- cargo check --target=$TARGET --example client --features opentelemetry_0_21
- cargo check --target=$TARGET --example server --features opentelemetry_0_21
trigger:
event:
- push
- pull_request
---
kind: pipeline
type: docker
name: build-amd64
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- cargo build --target=$TARGET
- cargo build --target=$TARGET --example client --features opentelemetry_0_21
- cargo build --target=$TARGET --example server --features opentelemetry_0_21
trigger:
event:
- tag
---
kind: pipeline
type: docker
name: build-arm64v8
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:latest-linux-arm64v8
pull: always
commands:
- cargo build --target=$TARGET
- cargo build --target=$TARGET --example client --features opentelemetry_0_21
- cargo build --target=$TARGET --example server --features opentelemetry_0_21
trigger:
event:
- tag
---
kind: pipeline
type: docker
name: build-arm32v7
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:latest-linux-arm32v7
pull: always
commands:
- cargo build --target=$TARGET
- cargo build --target=$TARGET --example client --features opentelemetry_0_21
- cargo build --target=$TARGET --example server --features opentelemetry_0_21
trigger:
event:
- tag
---
kind: pipeline
type: docker
name: publish-crate
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: publish
image: asonix/rust-builder:latest-linux-amd64
pull: always
environment:
CRATES_IO_TOKEN:
from_secret: crates_io_token
commands:
- cargo publish --token $CRATES_IO_TOKEN
depends_on:
- clippy
- tests
- build-amd64
- build-arm64v8
- build-arm32v7
trigger:
event:
- tag

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
/target
Cargo.lock
/.envrc
/.direnv

View file

@ -1,7 +1,7 @@
[package]
name = "tracing-awc"
description = "Tracing instrumentation for the awc http client"
version = "0.1.0-beta.13"
version = "0.1.9"
authors = ["asonix <asonix@asonix.dog"]
edition = "2018"
license = "AGPL-3.0"
@ -10,42 +10,89 @@ readme = "README.md"
[[example]]
name = "client"
required-features = ["opentelemetry_0_16"]
required-features = ["opentelemetry_0_21"]
[[example]]
name = "server"
required-features = ["opentelemetry_0_16"]
required-features = ["opentelemetry_0_21"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["emit_event_on_error"]
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_16_pkg"]
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_16_pkg",
]
opentelemetry_0_17 = [
"opentelemetry_0_17_pkg",
"tracing-opentelemetry_0_17_pkg",
]
opentelemetry_0_18 = [
"opentelemetry_0_18_pkg",
"tracing-opentelemetry_0_18_pkg",
]
opentelemetry_0_19 = [
"opentelemetry_0_19_pkg",
"tracing-opentelemetry_0_19_pkg",
]
opentelemetry_0_20 = [
"opentelemetry_0_20_pkg",
"tracing-opentelemetry_0_21_pkg",
]
opentelemetry_0_21 = [
"opentelemetry_0_21_pkg",
"tracing-opentelemetry_0_22_pkg",
]
[dependencies]
actix-http = { version = "=3.0.0-beta.14", default-features = false }
actix-service = "2.0.1"
awc = { version = "=3.0.0-beta.12", default-features = false }
actix-http = { version = "3.0.2", default-features = false }
actix-service = "2.0.2"
awc = { version = "3.0.0", default-features = false }
bytes = "1"
futures-core = "0.3"
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 }
opentelemetry_0_17_pkg = { package = "opentelemetry", version = "0.17", optional = true }
opentelemetry_0_18_pkg = { package = "opentelemetry", version = "0.18", optional = true }
opentelemetry_0_19_pkg = { package = "opentelemetry", version = "0.19", optional = true }
opentelemetry_0_20_pkg = { package = "opentelemetry", version = "0.20", optional = true }
opentelemetry_0_21_pkg = { package = "opentelemetry", version = "0.21", optional = true }
pin-project-lite = "0.2.7"
tracing = "0.1"
tracing-opentelemetry_0_12_pkg = { package = "tracing-opentelemetry",version = "0.12", 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_16_pkg = { package = "tracing-opentelemetry",version = "0.16", optional = true }
tracing-opentelemetry_0_14_pkg = { package = "tracing-opentelemetry", version = "0.14", optional = true }
tracing-opentelemetry_0_16_pkg = { package = "tracing-opentelemetry", version = "0.16", optional = true }
tracing-opentelemetry_0_17_pkg = { package = "tracing-opentelemetry", version = "0.17", optional = true }
tracing-opentelemetry_0_18_pkg = { package = "tracing-opentelemetry", version = "0.18", optional = true }
tracing-opentelemetry_0_19_pkg = { package = "tracing-opentelemetry", version = "0.19", optional = true }
tracing-opentelemetry_0_21_pkg = { package = "tracing-opentelemetry", version = "0.21", optional = true }
tracing-opentelemetry_0_22_pkg = { package = "tracing-opentelemetry", version = "0.22", optional = true }
[dev-dependencies]
actix-rt = "2.2"
actix-web = { version = "4.0.0-beta.9", default-features = false }
opentelemetry-otlp = "0.9"
opentelemetry_0_16_pkg = { package = "opentelemetry", version = "0.16", features = ["rt-tokio"] }
tracing-actix-web = { version = "0.5.0-beta.3", features = ["opentelemetry_0_16"] }
tracing-subscriber = { version = "0.3", features = ["ansi", "env-filter", "fmt"] }
actix-rt = "2.6"
actix-web = { version = "4.0.0", default-features = false }
opentelemetry-otlp = "0.14"
opentelemetry_0_21_pkg = { package = "opentelemetry", version = "0.21" }
opentelemetry_sdk = { version = "0.21", features = ["rt-tokio"] }
tracing-actix-web = { version = "0.7.8", features = ["opentelemetry_0_21"] }
tracing-subscriber = { version = "0.3", features = [
"ansi",
"env-filter",
"fmt",
] }

View file

@ -4,21 +4,26 @@ Instrument the AWC client with tracing, and optionally opentelemetry for propaga
## Usage
```toml
actix-rt = "2.2"
awc = "3.0.0-beta.8"
actix-rt = "2.6"
awc = "3.0.0"
tracing = "0.1"
tracing-futures = "0.2"
tracing-subscriber = { version = "0.2", features = ["fmt"] }
tracing-awc = { version = "0.1.0-beta.2", features = ["opentelemetry_0_16"]
tracing-awc = { version = "0.1.0", features = ["opentelemetry_0_17"]
```
```rust
use awc::Client;
use std::error::Error;
use tracing_awc::{root_span, Propagate};
use tracing_awc::{root_span, Tracing};
use tracing_futures::Instrument;
async fn request(url: &str) -> Result<(), Box<dyn Error>> {
Client::new().get(url).propagate().send().await?;
Client::builder()
.wrap(Tracing)
.finish()
.get(url)
.send()
.await?;
Ok(())
}

View file

@ -5,13 +5,11 @@ use tracing::instrument::Instrument;
use tracing_awc::{root_span, Tracing};
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, EnvFilter, Registry};
use opentelemetry_0_16_pkg as opentelemetry;
use tracing_opentelemetry_0_16_pkg as tracing_opentelemetry;
use opentelemetry_0_21_pkg as opentelemetry;
use tracing_opentelemetry_0_22_pkg as tracing_opentelemetry;
use opentelemetry::{
sdk::{propagation::TraceContextPropagator, Resource},
KeyValue,
};
use opentelemetry::KeyValue;
use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource};
async fn request(url: &str) -> Result<(), Box<dyn Error>> {
Client::builder()
@ -47,7 +45,7 @@ fn init_opentelemetry(url: &str) -> Result<(), Box<dyn Error>> {
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
opentelemetry::sdk::trace::config().with_resource(Resource::new(vec![KeyValue::new(
opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"client-demo",
)])),
@ -57,7 +55,7 @@ fn init_opentelemetry(url: &str) -> Result<(), Box<dyn Error>> {
.tonic()
.with_endpoint(url),
)
.install_batch(opentelemetry::runtime::Tokio)?;
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer);

View file

@ -7,13 +7,11 @@ use std::error::Error;
use tracing_actix_web::TracingLogger;
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, EnvFilter, Registry};
use opentelemetry_0_16_pkg as opentelemetry;
use tracing_opentelemetry_0_16_pkg as tracing_opentelemetry;
use opentelemetry_0_21_pkg as opentelemetry;
use tracing_opentelemetry_0_22_pkg as tracing_opentelemetry;
use opentelemetry::{
sdk::{propagation::TraceContextPropagator, Resource},
KeyValue,
};
use opentelemetry::KeyValue;
use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource};
#[tracing::instrument(name = "Index")]
async fn index() -> impl Responder {
@ -51,7 +49,7 @@ fn init_opentelemetry(url: &str) -> Result<(), Box<dyn Error>> {
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
opentelemetry::sdk::trace::config().with_resource(Resource::new(vec![KeyValue::new(
opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"server-demo",
)])),
@ -61,7 +59,7 @@ fn init_opentelemetry(url: &str) -> Result<(), Box<dyn Error>> {
.tonic()
.with_endpoint(url),
)
.install_batch(opentelemetry::runtime::Tokio)?;
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer);

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1699099776,
"narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

25
flake.nix Normal file
View file

@ -0,0 +1,25 @@
{
description = "background-jobs";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
packages.default = pkgs.hello;
devShell = with pkgs; mkShell {
nativeBuildInputs = [ cargo cargo-outdated cargo-zigbuild clippy gcc protobuf rust-analyzer rustc rustfmt ];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});
}

View file

@ -1,9 +1,6 @@
use actix_http::{error::PayloadError, Payload, RequestHeadType};
use actix_http::{error::PayloadError, header::map::HeaderMap, Payload, RequestHeadType};
use actix_service::Service;
use awc::{
error::SendRequestError, http::HeaderMap, middleware::Transform, ConnectRequest,
ConnectResponse,
};
use awc::{error::SendRequestError, middleware::Transform, ConnectRequest, ConnectResponse};
use bytes::Bytes;
use futures_core::stream::Stream;
use std::{
@ -21,6 +18,16 @@ use opentelemetry_0_14_pkg as opentelemetry;
use opentelemetry_0_15_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_16")]
use opentelemetry_0_16_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_17")]
use opentelemetry_0_17_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_18")]
use opentelemetry_0_18_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_19")]
use opentelemetry_0_19_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_20")]
use opentelemetry_0_20_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_21")]
use opentelemetry_0_21_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_13")]
use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry;
@ -30,19 +37,54 @@ use tracing_opentelemetry_0_13_pkg as tracing_opentelemetry;
use tracing_opentelemetry_0_14_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_16")]
use tracing_opentelemetry_0_16_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_17")]
use tracing_opentelemetry_0_17_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_18")]
use tracing_opentelemetry_0_18_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_19")]
use tracing_opentelemetry_0_19_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_20")]
use tracing_opentelemetry_0_21_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_21")]
use tracing_opentelemetry_0_22_pkg as tracing_opentelemetry;
#[cfg(any(
feature = "opentelemetry_0_13",
feature = "opentelemetry_0_14",
feature = "opentelemetry_0_15",
feature = "opentelemetry_0_16"
feature = "opentelemetry_0_16",
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
))]
pub fn root_span() -> Span {
let span = tracing::info_span!("Root span", trace_id = tracing::field::Empty,);
{
use opentelemetry::trace::TraceContextExt;
use tracing_opentelemetry::OpenTelemetrySpanExt;
#[cfg(not(any(
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
)))]
let trace_id = span.context().span().span_context().trace_id().to_hex();
#[cfg(any(
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
))]
let trace_id = {
let id = span.context().span().span_context().trace_id();
format!("{:032x}", id)
};
span.record("trace_id", &tracing::field::display(trace_id));
}
@ -69,7 +111,7 @@ where
{
type Response = ConnectResponse;
type Error = SendRequestError;
type Future = TracingFuture<S::Future>;
type Future = Instrumented<TracingFuture<S::Future>>;
fn poll_ready(&self, ctx: &mut core::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(ctx)
@ -96,19 +138,19 @@ where
match request_head.version {
actix_http::Version::HTTP_09 => {
span.record("http.flavor", &"0.9");
span.record("http.flavor", "0.9");
}
actix_http::Version::HTTP_10 => {
span.record("http.flavor", &"1.0");
span.record("http.flavor", "1.0");
}
actix_http::Version::HTTP_11 => {
span.record("http.flavor", &"1.1");
span.record("http.flavor", "1.1");
}
actix_http::Version::HTTP_2 => {
span.record("http.flavor", &"2.0");
span.record("http.flavor", "2.0");
}
actix_http::Version::HTTP_3 => {
span.record("http.flavor", &"3.0");
span.record("http.flavor", "3.0");
}
_ => (),
}
@ -132,16 +174,16 @@ where
}
TracingFuture {
future: self.0.call(req).instrument(span.clone()),
span,
future: span
.in_scope(|| self.0.call(req))
.instrument(tracing::trace_span!(parent: None, "Http Request Inner")),
}
.instrument(span)
}
}
pin_project_lite::pin_project! {
pub struct TracingFuture<F> {
span: Span,
#[pin]
future: Instrumented<F>,
}
@ -156,63 +198,60 @@ where
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.as_mut().project();
let span = Span::current();
let future = this.future;
let span = this.span;
span.in_scope(|| {
future
.poll(cx)
.map_ok(|succ| match succ {
ConnectResponse::Client(client_response) => {
let status: i32 = client_response.status().as_u16().into();
span.record("http.status_code", &status);
if client_response.status().is_client_error() {
span.record("otel.status_code", &"ERROR");
}
ConnectResponse::Client(client_response.map_body(|_, payload| {
let body_span =
tracing::info_span!(parent: None, "HTTP Client Response Body");
body_span.follows_from(span.id());
let instrumented = InstrumentedBody::new(body_span, payload);
let pinned: Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>>>> =
Box::pin(instrumented);
Payload::Stream(pinned)
}))
future
.poll(cx)
.map_ok(|succ| match succ {
ConnectResponse::Client(client_response) => {
let status: i32 = client_response.status().as_u16().into();
span.record("http.status_code", status);
if client_response.status().is_client_error() {
span.record("otel.status_code", "ERROR");
}
ConnectResponse::Tunnel(response_head, etc) => {
let status: i32 = response_head.status.as_u16().into();
span.record("http.status_code", &status);
if response_head.status.is_client_error() {
span.record("otel.status_code", &"ERROR");
}
ConnectResponse::Tunnel(response_head, etc)
ConnectResponse::Client(client_response.map_body(|_, payload| {
let payload = InstrumentedBody::new(payload);
let payload: Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>>>> =
Box::pin(payload);
Payload::Stream { payload }
}))
}
ConnectResponse::Tunnel(response_head, etc) => {
let status: i32 = response_head.status.as_u16().into();
span.record("http.status_code", status);
if response_head.status.is_client_error() {
span.record("otel.status_code", "ERROR");
}
})
.map_err(|err| {
span.record("otel.status_code", &"ERROR");
span.record(
"exception.message",
&tracing::field::display(&format!("{}", err)),
);
span.record(
"exception.details",
&tracing::field::display(&format!("{:?}", err)),
);
ConnectResponse::Tunnel(response_head, etc)
}
})
.map_err(|err| {
span.record("otel.status_code", "ERROR");
span.record(
"exception.message",
&tracing::field::display(&format!("{}", err)),
);
span.record(
"exception.details",
&tracing::field::display(&format!("{:?}", err)),
);
#[cfg(feature = "emit_event_on_error")]
tracing::warn!("Error in request: {}", err);
#[cfg(feature = "emit_event_on_error")]
tracing::warn!("Error in request: {}", err);
err
})
})
err
})
}
}
pin_project_lite::pin_project! {
struct InstrumentedBody<S> {
span: Span,
span: Option<Span>,
dummy_span: Option<Span>,
#[pin]
body: S,
@ -223,8 +262,12 @@ impl<S> InstrumentedBody<S>
where
S: Stream<Item = Result<Bytes, PayloadError>>,
{
fn new(span: Span, body: S) -> InstrumentedBody<S> {
InstrumentedBody { span, body }
fn new(body: S) -> InstrumentedBody<S> {
InstrumentedBody {
span: None,
dummy_span: None,
body,
}
}
}
@ -237,10 +280,26 @@ where
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.as_mut().project();
let span = this.span;
let span = this
.span
.get_or_insert_with(|| tracing::info_span!("HTTP Client Response Body"));
let dummy_span = this.dummy_span.get_or_insert_with(
|| tracing::trace_span!(parent: None, "HTTP Client Response Body Inner"),
);
let body = this.body;
span.in_scope(|| body.poll_next(cx))
let res = span.in_scope(|| dummy_span.in_scope(|| body.poll_next(cx)));
match res {
Poll::Ready(None) => {
this.span.take();
this.dummy_span.take();
Poll::Ready(None)
}
otherwise => otherwise,
}
}
}
@ -254,12 +313,17 @@ struct RequestHeaderCarrier<'a> {
feature = "opentelemetry_0_13",
feature = "opentelemetry_0_14",
feature = "opentelemetry_0_15",
feature = "opentelemetry_0_16"
feature = "opentelemetry_0_16",
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
))]
impl<'a> opentelemetry::propagation::Injector for RequestHeaderCarrier<'a> {
fn set(&mut self, key: &str, value: String) {
let f = || {
use actix_http::http::{HeaderName, HeaderValue};
use actix_http::header::{HeaderName, HeaderValue};
use std::convert::TryFrom;
let key = HeaderName::from_bytes(key.as_bytes())
@ -286,7 +350,12 @@ fn record_otel(_headers: &mut HeaderMap, _span: &Span) {
feature = "opentelemetry_0_13",
feature = "opentelemetry_0_14",
feature = "opentelemetry_0_15",
feature = "opentelemetry_0_16"
feature = "opentelemetry_0_16",
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
))]
{
let span = _span;