Skip to content

Commit 07f7a05

Browse files
committed
fix build performance tracing
1 parent 6552c4b commit 07f7a05

4 files changed

Lines changed: 50 additions & 8 deletions

File tree

crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use docs_rs_database::{
1212
},
1313
service_config::{ConfigName, get_config, set_config},
1414
};
15+
use docs_rs_logging::BUILD_PACKAGE_TRANSACTION_NAME;
1516
use docs_rs_registry_api::RegistryApi;
1617
use docs_rs_repository_stats::RepositoryStatsUpdater;
1718
use docs_rs_rustdoc_json::{
@@ -26,7 +27,9 @@ use docs_rs_types::{
2627
BuildId, BuildStatus, CrateId, KrateName, ReleaseId, Version,
2728
doc_coverage::{self, DocCoverage},
2829
};
29-
use docs_rs_utils::{RUSTDOC_STATIC_STORAGE_PREFIX, retry, rustc_version::parse_rustc_version};
30+
use docs_rs_utils::{
31+
Handle, RUSTDOC_STATIC_STORAGE_PREFIX, retry, rustc_version::parse_rustc_version,
32+
};
3033
use docsrs_metadata::{BuildTargets, DEFAULT_TARGETS, HOST_TARGET, Metadata};
3134
use regex::Regex;
3235
use rustwide::{
@@ -43,7 +46,6 @@ use std::{
4346
sync::Arc,
4447
time::Instant,
4548
};
46-
use tokio::runtime;
4749
use tracing::{debug, error, info, info_span, instrument, warn};
4850

4951
const USER_AGENT: &str = "docs.rs builder (https://github.com/rust-lang/docs.rs)";
@@ -114,7 +116,7 @@ pub enum PackageKind<'a> {
114116
pub struct RustwideBuilder {
115117
workspace: Workspace,
116118
toolchain: Toolchain,
117-
runtime: runtime::Handle,
119+
runtime: Handle,
118120
config: Arc<Config>,
119121
db: Pool,
120122
blocking_storage: Arc<Storage>,
@@ -127,7 +129,8 @@ pub struct RustwideBuilder {
127129

128130
impl RustwideBuilder {
129131
pub fn init(config: Arc<Config>, context: &Context) -> Result<Self> {
130-
let toolchain = context.runtime().block_on(async {
132+
let runtime: Handle = context.runtime().clone().into();
133+
let toolchain = runtime.block_on(async {
131134
let mut conn = context.pool()?.get_async().await?;
132135
get_configured_toolchain(&mut conn).await
133136
})?;
@@ -137,7 +140,7 @@ impl RustwideBuilder {
137140
toolchain,
138141
config: config.clone(),
139142
db: context.pool()?.clone(),
140-
runtime: context.runtime().clone(),
143+
runtime,
141144
blocking_storage: context.blocking_storage()?.clone(),
142145
storage: context.storage()?.clone(),
143146
registry_api: context.registry_api()?.clone(),
@@ -487,7 +490,7 @@ impl RustwideBuilder {
487490
)
488491
}
489492

490-
#[instrument(name = "docbuilder.build_package", parent = None, skip(self, name), fields(krate=name))]
493+
#[instrument(name = BUILD_PACKAGE_TRANSACTION_NAME, parent = None, skip(self, name), fields(krate=name))]
491494
pub fn build_package(
492495
&mut self,
493496
name: &str,
@@ -533,6 +536,7 @@ impl RustwideBuilder {
533536
}
534537
}
535538

539+
#[instrument(skip(self))]
536540
#[allow(clippy::too_many_arguments)]
537541
fn build_package_inner(
538542
&mut self,

crates/lib/docs_rs_logging/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ use sentry::{
88
use std::{env, str::FromStr as _, sync::Arc};
99
use tracing_subscriber::{EnvFilter, filter::Directive, prelude::*};
1010

11+
/// defines the transaction name to be used for our rustwide builder.
12+
///
13+
/// We want to trace _all_ builds, while we want to apply a
14+
/// sampling ratio to web requests.
15+
///
16+
/// From what I see right now, the transaction name or op is the only way
17+
/// to distinguish build transactions from web requests.
18+
pub const BUILD_PACKAGE_TRANSACTION_NAME: &str = "docbuilder.build_package";
19+
1120
pub struct Guard {
1221
#[allow(dead_code)]
1322
sentry_guard: Option<sentry::ClientInitGuard>,
@@ -54,8 +63,7 @@ pub fn init() -> anyhow::Result<Guard> {
5463
return if sampled { 1.0 } else { 0.0 };
5564
}
5665

57-
let op = ctx.operation();
58-
if op == "docbuilder.build_package" {
66+
if ctx.name() == BUILD_PACKAGE_TRANSACTION_NAME {
5967
// record all transactions for builds
6068
1.
6169
} else {

crates/lib/docs_rs_utils/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
mod runtime_ext;
12
pub mod rustc_version;
23
#[cfg(feature = "testing")]
34
pub mod testing;
45

6+
pub use runtime_ext::Handle;
7+
58
use anyhow::{Context as _, Result};
69
use std::fmt;
710
use std::{panic, thread, time::Duration};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::ops::Deref;
2+
use tokio::runtime;
3+
use tracing::Instrument as _;
4+
5+
/// Newtype around `tokio::runtime::Handle` that adds
6+
/// missing integration with tracing spans.
7+
pub struct Handle(runtime::Handle);
8+
9+
impl Handle {
10+
pub fn block_on<F: Future>(&self, future: F) -> F::Output {
11+
runtime::Handle::block_on(self, future.in_current_span())
12+
}
13+
}
14+
15+
impl From<runtime::Handle> for Handle {
16+
fn from(handle: runtime::Handle) -> Self {
17+
Handle(handle)
18+
}
19+
}
20+
21+
impl Deref for Handle {
22+
type Target = runtime::Handle;
23+
24+
fn deref(&self) -> &Self::Target {
25+
&self.0
26+
}
27+
}

0 commit comments

Comments
 (0)