-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ziy1-Tan <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,044 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2024 The Kuasar Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use std::str::FromStr; | ||
|
||
use opentelemetry::sdk::trace::Tracer; | ||
use opentelemetry::sdk::{trace, Resource}; | ||
use opentelemetry_otlp::WithExportConfig; | ||
use tracing::level_filters::LevelFilter; | ||
use tracing_subscriber::EnvFilter; | ||
|
||
const DEFAULT_JAEGER_ENDPOINT: &str = "http://localhost:14268/api/traces"; | ||
|
||
pub fn create_otlp_tracer( | ||
otlp_service_name: &str, | ||
otlp_endpoint: Option<String>, | ||
) -> anyhow::Result<Tracer> { | ||
let tracer = opentelemetry_otlp::new_pipeline() | ||
.tracing() | ||
.with_exporter( | ||
opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint(otlp_endpoint.unwrap_or(DEFAULT_JAEGER_ENDPOINT.to_string())), | ||
) | ||
.with_trace_config(trace::config().with_resource(Resource::new(vec![ | ||
opentelemetry::KeyValue::new("service.name", otlp_service_name.to_string()), | ||
]))) | ||
.install_batch(opentelemetry::runtime::Tokio)?; | ||
|
||
Ok(tracer) | ||
} | ||
|
||
pub fn create_logger_filter(level: &str) -> anyhow::Result<EnvFilter> { | ||
let log_level = LevelFilter::from_str(&level)?; | ||
let filter = EnvFilter::from_default_env() | ||
.add_directive(format!("containerd_sandbox={:?}", log_level).parse()?) | ||
.add_directive(format!("vmm_sandboxer={:?}", log_level).parse()?); | ||
Ok(filter) | ||
} |
Oops, something went wrong.