Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use clap::Parser;
use log::{error, info};
use tokio::{select, sync::oneshot};

use crate::utils::{instance, observability::init_observability};
use crate::utils::observability::init_observability;

/// Git hash of the aisix core at build time.
pub const GIT_HASH: &str = env!("VERGEN_GIT_SHA");
Expand All @@ -38,8 +38,6 @@ pub async fn run(config_file: Option<String>) -> Result<()> {
let (ob_shutdown_signal, ob_shutdown_task) =
init_observability().context("failed to initialize observability")?;

instance::init().context("failed to initialize instance")?;

let config = match config::load(config_file).context("failed to load configuration") {
Ok(c) => Arc::new(c),
Err(e) => {
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use aisix::{Args, run};
use anyhow::Result;
use anyhow::{Context, Result};
use clap::Parser;

#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();

aisix::utils::instance::init().context("failed to initialize instance")?;
Comment thread
bzp2010 marked this conversation as resolved.

run(args.config).await
}
13 changes: 13 additions & 0 deletions src/proxy/middlewares/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ use crate::utils::future::WithSpan;

pub const TRACEPARENT_HEADER: &str = "traceparent";

mod attributes {
pub const AISIX_INSTANCE_ID: &str = "aisix.instance_id";
pub const AISIX_INSTANCE_RUN_ID: &str = "aisix.instance_run_id";
}

pub struct TimedBody {
start_time: Instant,
inner: Body,
Expand Down Expand Up @@ -134,6 +139,14 @@ pub async fn trace(mut req: Request, next: Next) -> Response<TimedBody> {

root_span.add_properties(|| {
[
(
attributes::AISIX_INSTANCE_ID,
crate::utils::instance::instance_id(),
),
(
attributes::AISIX_INSTANCE_RUN_ID,
crate::utils::instance::run_id(),
),
(HTTP_REQUEST_METHOD, method.to_string()),
(URL_PATH, path.clone()),
]
Expand Down
13 changes: 8 additions & 5 deletions src/utils/observability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ pub fn init_observability_trace(
.build()
.context("failed to initialize otlp exporter")?,
},
Cow::Owned(
Resource::builder()
.with_service_name(INSTRUMENTATION_NAME)
.build(),
),
Cow::Owned(get_resource()),
InstrumentationScope::builder(INSTRUMENTATION_NAME)
.with_version(env!("CARGO_PKG_VERSION"))
.build(),
Expand Down Expand Up @@ -99,6 +95,7 @@ pub fn init_observability_metric(
.with_interval(std::time::Duration::from_secs(15))
.build(),
)
.with_resource(get_resource())
.build();
let meter = meter_provider.meter(INSTRUMENTATION_NAME);

Expand Down Expand Up @@ -132,3 +129,9 @@ pub fn init_observability() -> Result<(oneshot::Sender<()>, tokio::task::JoinHan
let _ = log_shutdown_handle.await;
}))
}

fn get_resource() -> Resource {
Resource::builder()
.with_service_name(INSTRUMENTATION_NAME)
.build()
}