Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] add panics to tracing #2382

Merged
merged 4 commits into from
Jun 20, 2024
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: 2 additions & 2 deletions rust/worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ RUN if [ "$RELEASE_MODE" = "1" ]; then mv target/release/query_service .; else m

FROM debian:bookworm-slim as query_service

RUN apt-get update && apt-get install -y libssl-dev ca-certificates
COPY --from=query_service_builder /chroma/query_service .
COPY --from=query_service_builder /chroma/rust/worker/chroma_config.yaml .
RUN apt-get update && apt-get install -y libssl-dev ca-certificates

ENTRYPOINT [ "./query_service" ]

Expand All @@ -54,8 +54,8 @@ RUN if [ "$RELEASE_MODE" = "1" ]; then mv target/release/compaction_service .; e

FROM debian:bookworm-slim as compaction_service

RUN apt-get update && apt-get install -y libssl-dev ca-certificates
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes incremental builds slightly faster

COPY --from=compaction_service_builder /chroma/compaction_service .
COPY --from=compaction_service_builder /chroma/rust/worker/chroma_config.yaml .
RUN apt-get update && apt-get install -y libssl-dev ca-certificates

ENTRYPOINT [ "./compaction_service" ]
30 changes: 21 additions & 9 deletions rust/worker/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,18 +532,30 @@ impl chroma_proto::metadata_reader_server::MetadataReader for WorkerServer {
impl chroma_proto::debug_server::Debug for WorkerServer {
async fn get_info(
&self,
_: Request<()>,
request: Request<()>,
) -> Result<Response<chroma_proto::GetInfoResponse>, Status> {
let response = chroma_proto::GetInfoResponse {
version: option_env!("CARGO_PKG_VERSION")
.unwrap_or("unknown")
.to_string(),
};
Ok(Response::new(response))
// Note: We cannot write a middleware that instruments every service rpc
// with a span because of https://github.com/hyperium/tonic/pull/1202.
let request_span = trace_span!("Get info");

wrap_span_with_parent_context(request_span, request.metadata()).in_scope(|| {
let response = chroma_proto::GetInfoResponse {
version: option_env!("CARGO_PKG_VERSION")
.unwrap_or("unknown")
.to_string(),
};
Ok(Response::new(response))
})
}

async fn trigger_panic(&self, _: Request<()>) -> Result<Response<()>, Status> {
panic!("Intentional panic triggered");
async fn trigger_panic(&self, request: Request<()>) -> Result<Response<()>, Status> {
// Note: We cannot write a middleware that instruments every service rpc
// with a span because of https://github.com/hyperium/tonic/pull/1202.
let request_span = trace_span!("Trigger panic");

wrap_span_with_parent_context(request_span, request.metadata()).in_scope(|| {
panic!("Intentional panic triggered");
})
}
}

Expand Down
24 changes: 24 additions & 0 deletions rust/worker/src/tracing/opentelemetry_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,28 @@ pub(crate) fn init_otel_tracing(service_name: &String, otel_endpoint: &String) {
tracing::subscriber::set_global_default(subscriber)
.expect("Set global default subscriber failed");
println!("Set global subscriber for {}", service_name);

// Add panics to tracing
let prev_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my learning: does this panic hook get set system wide after this call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's a global hook for all threads (https://doc.rust-lang.org/std/panic/fn.set_hook.html)

let payload = panic_info.payload();

#[allow(clippy::manual_map)]
let payload = if let Some(s) = payload.downcast_ref::<&str>() {
Some(&**s)
} else if let Some(s) = payload.downcast_ref::<String>() {
Some(s.as_str())
} else {
None
};

tracing::error!(
panic.payload = payload,
panic.location = panic_info.location().map(|l| l.to_string()),
panic.backtrace = tracing::field::display(std::backtrace::Backtrace::capture()),
"A panic occurred"
);

prev_hook(panic_info);
}));
}
Loading