-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLN] Move log module outside of worker crate (#3547)
## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - Move log module outside of worker crate - New functionality - ... ## Test plan *How are these changes tested?* - [ ] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Documentation Changes *Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?*
- Loading branch information
1 parent
e4ec7f3
commit c5f7d2e
Showing
31 changed files
with
304 additions
and
268 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "chroma-log" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
async-trait = { workspace = true } | ||
# Used by tracing | ||
opentelemetry = { workspace = true } | ||
rand = { workspace = true } | ||
serde = { workspace = true } | ||
thiserror = { workspace = true } | ||
tonic = { workspace = true } | ||
tracing = { workspace = true } | ||
# Used by tracing | ||
tracing-opentelemetry = { workspace = true } | ||
uuid = { workspace = true } | ||
|
||
chroma-config = { workspace = true } | ||
chroma-error = { workspace = true } | ||
chroma-segment = { workspace = true } | ||
chroma-types = { workspace = true } | ||
|
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,14 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct GrpcLogConfig { | ||
pub host: String, | ||
pub port: u16, | ||
pub connect_timeout_ms: u64, | ||
pub request_timeout_ms: u64, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub enum LogConfig { | ||
Grpc(GrpcLogConfig), | ||
} |
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,17 @@ | ||
pub mod config; | ||
#[allow(clippy::module_inception)] | ||
pub mod log; | ||
pub mod test; | ||
pub mod tracing; | ||
|
||
use chroma_config::Configurable; | ||
use chroma_error::ChromaError; | ||
use config::LogConfig; | ||
|
||
pub async fn from_config(config: &LogConfig) -> Result<Box<log::Log>, Box<dyn ChromaError>> { | ||
match &config { | ||
config::LogConfig::Grpc(_) => Ok(Box::new(log::Log::Grpc( | ||
log::GrpcLog::try_from_config(config).await?, | ||
))), | ||
} | ||
} |
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
File renamed without changes.
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,47 @@ | ||
// Interceptor copies from worker::tracing::util | ||
// TODO: A seperate tracing crate | ||
|
||
use std::str::FromStr; | ||
|
||
use opentelemetry::trace::TraceContextExt; | ||
use tonic::{metadata::MetadataValue, Request, Status}; | ||
use tracing::Span; | ||
use tracing_opentelemetry::OpenTelemetrySpanExt; | ||
|
||
const TRACE_ID_HEADER_KEY: &str = "chroma-traceid"; | ||
const SPAN_ID_HEADER_KEY: &str = "chroma-spanid"; | ||
|
||
pub(crate) fn client_interceptor(request: Request<()>) -> Result<Request<()>, Status> { | ||
// If span is disabled then nothing to append in the header. | ||
if Span::current().is_disabled() { | ||
return Ok(request); | ||
} | ||
let mut mut_request = request; | ||
let metadata = mut_request.metadata_mut(); | ||
let trace_id = MetadataValue::from_str( | ||
Span::current() | ||
.context() | ||
.span() | ||
.span_context() | ||
.trace_id() | ||
.to_string() | ||
.as_str(), | ||
); | ||
let span_id = MetadataValue::from_str( | ||
Span::current() | ||
.context() | ||
.span() | ||
.span_context() | ||
.span_id() | ||
.to_string() | ||
.as_str(), | ||
); | ||
// Errors are not fatal. | ||
if let Ok(id) = trace_id { | ||
metadata.append(TRACE_ID_HEADER_KEY, id); | ||
} | ||
if let Ok(id) = span_id { | ||
metadata.append(SPAN_ID_HEADER_KEY, id); | ||
} | ||
Ok(mut_request) | ||
} |
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.