Skip to content

Commit

Permalink
feat(turbopack): peek captured telemetries
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 10, 2023
1 parent 6293ac0 commit ef8dd42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod next_import_map;
mod next_route_matcher;
pub mod next_server;
pub mod next_shared;
mod next_telemetry;
mod page_loader;
mod page_source;
pub mod pages_structure;
Expand All @@ -38,7 +39,6 @@ mod transform_options;
pub mod url_node;
mod util;
mod web_entry_source;
mod next_telemetry;

pub use app_source::create_app_source;
pub use page_loader::create_page_loader_entry_asset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ lazy_static! {
]
),
("@next", vec!["/font/google", "/font/local"])
])
.into();
]);
}

#[turbo_tasks::value]
Expand Down
32 changes: 30 additions & 2 deletions packages/next-swc/crates/next-core/src/next_telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
use anyhow::Result;
use turbo_tasks::{emit, primitives::StringVc, ValueToString, ValueToStringVc};
use turbopack_binding::features::auto_hash_map;

/// A list of issues captured with
/// [`NextTelemetryVc::peek_telemetries_with_path`] and
#[derive(Debug)]
#[turbo_tasks::value]
pub struct CapturedTelemetry {
pub telemetries: auto_hash_map::AutoSet<NextTelemetryVc>,
}

#[turbo_tasks::value_trait]
pub trait NextTelemetry {
// [TODO]: this is likely to change to match to parity to the existing
// telemetry payload.
fn event_name(&self) -> StringVc;
}

impl NextTelemetryVc {
pub fn emit(self) {
emit(self);
}

pub async fn peek_telemetries_with_path<T: turbo_tasks::CollectiblesSource + Copy>(
source: T,
) -> Result<CapturedTelemetryVc> {
Ok(CapturedTelemetryVc::cell(CapturedTelemetry {
telemetries: source.peek_collectibles().strongly_consistent().await?,
}))
}
}

#[turbo_tasks::value_trait]
pub trait TelemetryReporter {
fn report(
&self,
telemetries: turbo_tasks::TransientInstance<turbo_tasks::ReadRef<CapturedTelemetry>>,
source: turbo_tasks::TransientValue<turbo_tasks::RawVc>,
) -> turbo_tasks::primitives::BoolVc;
}

/// A struct represent telemetry event for feature usage,
/// referred as `importing` a certain module.
/// A struct represent telemetry event for the feature usage,
/// referred as `importing` a certain module. (i.e importing @next/image)
#[turbo_tasks::value(shared)]
pub struct ModuleFeatureTelemetry {
pub event_name: String,
Expand Down

0 comments on commit ef8dd42

Please sign in to comment.