Skip to content

Commit 0a50517

Browse files
committed
feat: add o11y crate
1 parent a1693b3 commit 0a50517

File tree

12 files changed

+113
-18
lines changed

12 files changed

+113
-18
lines changed

Cargo.lock

+76-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ futures-util = { version = "0.3.30" }
2323
graphql_client = { version = "0.13.0", default-features = false }
2424
http = { version = "0.2" } # request use 0.2
2525
moka = { version = "0.12.4", features = ["future"] }
26+
opentelemetry_sdk = { version = "0.21.2" }
2627
reqwest = { version = "0.11.23", default-features = false, features = ["rustls-tls", "json"] }
2728
serde = { version = "1", features = ["derive"] }
2829
serde_json = { version = "1.0.111" }

crates/synd_api/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ name = "synd_api"
1212
version = "0.1.0"
1313

1414
[dependencies]
15-
anyhow = { workspace = true }
16-
# To use axum 0.7
15+
synd_o11y = { path = "../synd_o11y" }
16+
17+
anyhow = { workspace = true }
1718
async-graphql = { version = "7.0", features = ["tracing"] }
1819
async-graphql-axum = { version = "7.0" }
1920
async-trait = { workspace = true }
20-
# TODO configure features
2121
axum = { workspace = true }
2222
chrono = { workspace = true }
2323
clap = { workspace = true, features = ["derive"] }

crates/synd_api/src/gql/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ pub mod handler {
1616
use async_graphql::http::GraphiQLSource;
1717
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
1818
use axum::{response::IntoResponse, Extension};
19+
use synd_o11y::audit_span;
1920
use tracing::Instrument;
2021

21-
use crate::{audit_span, principal::Principal};
22+
use crate::principal::Principal;
2223

2324
use super::SyndSchema;
2425

crates/synd_api/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use tracing::{error, info};
33
use synd_api::{args, dependency::Dependency, serve::listen_and_serve};
44

55
fn init_tracing() {
6-
use synd_api::serve::layer::audit;
6+
use synd_o11y::tracing_subscriber::audit;
77
use tracing_subscriber::{
88
filter::EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt as _, Layer as _,
99
Registry,
-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
pub mod audit;
21
pub mod authenticate;
32
pub mod trace;

crates/synd_api/src/usecase/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ pub mod authorize;
1818
use std::{future::Future, sync::Arc};
1919

2020
use synd_feed::feed::cache::FetchCachedFeed;
21+
use synd_o11y::{audit, tracing_subscriber::audit::Audit};
2122

2223
use crate::{
23-
audit,
2424
persistence::{Datastore, DatastoreError},
2525
principal::Principal,
26-
serve::layer::audit::Audit,
2726
};
2827

2928
use self::authorize::{Authorized, Authorizer, Unauthorized};

crates/synd_o11y/Cargo.toml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
authors.workspace = true
3+
categories.workspace = true
4+
edition.workspace = true
5+
keywords.workspace = true
6+
license.workspace = true
7+
readme.workspace = true
8+
repository.workspace = true
9+
10+
description = "syndicationd lib for tracing and opentelemetry ecosystem"
11+
name = "synd_o11y"
12+
version = "0.1.0"
13+
14+
[dependencies]
15+
opentelemetry-appender-tracing = "0.2.0"
16+
opentelemetry_sdk = { workspace = true, features = ["logs"] }
17+
tracing = { workspace = true }
18+
tracing-subscriber = { workspace = true }
19+
20+
[lints]
21+
workspace = true

crates/synd_o11y/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod tracing_subscriber;

crates/synd_api/src/serve/layer/audit.rs crates/synd_o11y/src/tracing_subscriber/audit/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ mod macros {
1717
macro_rules! audit_span {
1818
() => {
1919
::tracing::info_span!(
20-
target: $crate::serve::layer::audit::Audit::TARGET,
21-
$crate::serve::layer::audit::Audit::SPAN_ROOT_NAME)
20+
target: $crate::tracing_subscriber::audit::Audit::TARGET,
21+
$crate::tracing_subscriber::audit::Audit::SPAN_ROOT_NAME)
2222
};
2323
}
2424

2525
#[macro_export]
2626
macro_rules! audit {
2727
($($arg:tt)*) => {
2828
::tracing::event!(
29-
name: $crate::serve::layer::audit::Audit::EVENT_NAME,
30-
target: $crate::serve::layer::audit::Audit::TARGET,
29+
name: $crate::tracing_subscriber::audit::Audit::EVENT_NAME,
30+
target: $crate::tracing_subscriber::audit::Audit::TARGET,
3131
::tracing::Level::TRACE, $($arg)*)
3232
};
3333
}
@@ -233,7 +233,7 @@ mod tests {
233233
mod usecase_authorize_scenario {
234234
use tracing::info_span;
235235

236-
use crate::{audit, audit_span, serve::layer::audit::Audit};
236+
use crate::{audit, audit_span, tracing_subscriber::audit::Audit};
237237

238238
pub fn root() {
239239
let span = audit_span!();
@@ -293,9 +293,7 @@ mod tests {
293293
#[test]
294294
fn no_audit_span() {
295295
let on_event = |event: &Event<'_>| {
296-
if event.metadata().name() == Audit::EMIT_EVENT_NAME {
297-
panic!("should not called");
298-
}
296+
assert_eq!(event.metadata().name(), Audit::EMIT_EVENT_NAME);
299297
};
300298
let test_layer = TestLayer { on_event };
301299
let subscriber = tracing_subscriber::registry()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod audit;

crates/synd_test/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ version = "0.1.0"
1313

1414
[dependencies]
1515
synd_authn = { path = "../synd_authn" }
16-
synd_term = { path = "../synd_term" }
1716

1817
anyhow = { workspace = true }
1918
axum = { workspace = true }

0 commit comments

Comments
 (0)