forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[common/tracing] feature: report tracing stat to jaeger
Start a local jaeger server and report tracing data and view it: ``` docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 jaegertracing/all-in-one:latest FUSE_JAEGER=on RUST_LOG=trace cargo test open http://localhost:16686/ ``` - Add: report tracing data to opentelemetry server(jaeger) with env `FUSE_JAEGER=on` - Add tracing::instrument to store flight server and meta server. - Inject tracing span to tonic request on the client side and extract them on the server side to form a complete tracing. - Add tracing to SledTree
- Loading branch information
1 parent
424d396
commit 0424aa1
Showing
14 changed files
with
425 additions
and
207 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,79 @@ | ||
// Copyright 2020-2021 The Datafuse Authors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0. | ||
|
||
use opentelemetry::global; | ||
use opentelemetry::propagation::Extractor; | ||
use opentelemetry::propagation::Injector; | ||
use tracing_opentelemetry::OpenTelemetrySpanExt; | ||
|
||
/// Inject tracing info into tonic request meta. | ||
struct MetadataMapInjector<'a>(&'a mut tonic::metadata::MetadataMap); | ||
|
||
impl<'a> Injector for MetadataMapInjector<'a> { | ||
/// Set a key and value in the MetadataMap. Does nothing if the key or value are not valid inputs | ||
fn set(&mut self, key: &str, value: String) { | ||
if let Ok(key) = tonic::metadata::MetadataKey::from_bytes(key.as_bytes()) { | ||
if let Ok(val) = tonic::metadata::MetadataValue::from_str(&value) { | ||
self.0.insert(key, val); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Extract tracing info from tonic request meta. | ||
struct MetadataMapExtractor<'a>(&'a tonic::metadata::MetadataMap); | ||
|
||
impl<'a> Extractor for MetadataMapExtractor<'a> { | ||
/// Get a value for a key from the MetadataMap. If the value can't be converted to &str, returns None | ||
fn get(&self, key: &str) -> Option<&str> { | ||
self.0.get(key).and_then(|metadata| metadata.to_str().ok()) | ||
} | ||
|
||
/// Collect all the keys from the MetadataMap. | ||
fn keys(&self) -> Vec<&str> { | ||
self.0 | ||
.keys() | ||
.map(|key| match key { | ||
tonic::metadata::KeyRef::Ascii(v) => v.as_str(), | ||
tonic::metadata::KeyRef::Binary(v) => v.as_str(), | ||
}) | ||
.collect::<Vec<_>>() | ||
} | ||
} | ||
|
||
/// Inject current tracing::Span info into tonic request meta | ||
/// before sending request to a tonic server. | ||
/// Then the tonic server will be able to chain a distributed tracing. | ||
/// | ||
/// A tonic client should call this function just before sending out the request. | ||
/// | ||
/// The global propagater must be installed, e.g. by calling: TODO | ||
pub fn inject_span_to_tonic_request<T>(mes: impl tonic::IntoRequest<T>) -> tonic::Request<T> { | ||
let curr = tracing::Span::current(); | ||
let cx = curr.context(); | ||
|
||
let mut request = mes.into_request(); | ||
|
||
global::get_text_map_propagator(|propagator| { | ||
propagator.inject_context(&cx, &mut MetadataMapInjector(request.metadata_mut())) | ||
}); | ||
|
||
request | ||
} | ||
|
||
/// Extract tracing context from tonic request meta | ||
/// and set current tracing::Span parent to the context from remote, | ||
/// to chain the client side span with current server side span. | ||
/// | ||
/// A tonic request handler should call this before doing anything else. | ||
/// | ||
/// The global propagater must be installed, e.g. by calling: TODO | ||
pub fn extract_remote_span_as_parent<T>(request: &tonic::Request<T>) { | ||
let parent_cx = global::get_text_map_propagator(|prop| { | ||
prop.extract(&MetadataMapExtractor(request.metadata())) | ||
}); | ||
|
||
let span = tracing::Span::current(); | ||
span.set_parent(parent_cx); | ||
} |
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
Oops, something went wrong.