nagisa / rust_tracy_client

Tracy client libraries for Rust
Apache License 2.0
178 stars 37 forks source link

How can I trace a external call and show up in the UI? #74

Closed mamcx closed 1 year ago

mamcx commented 1 year ago

Is possible to mark a section of the code that calls a external function or a inner loop that show up in the UI, like:

#[tracing::instrument(skip_all)]
pub fn compile_sql(db: &RelationalDB, tx: &MutTxId, sql_text: &str) -> Result<Vec<CrudExpr>, DBError> {
    tracing::info!(sql = sql_text);
    let ast = compile_to_ast(db, tx, sql_text)?;

    let mut results = Vec::with_capacity(ast.len());

    let loops = tracing::info_span!("LOOP compiler");
    for sql in ast {
        tracing::info!(sql = sql_text); <--- WANNA THIS be part of "LOOP compiler"
        results.push(compile_statement(sql).map_err(|error| DBError::Plan {
            sql: sql_text.to_string(),
            error,
        })?);
    }
nagisa commented 1 year ago

Sorry for the late response, but no this is unfortunately not possible: Tracy wants the information about the span name to be completed by the time span is entered, so adjusting the span name is not possible (even though tracing itself notionally supports this – you can use field::Empty as the initial field value and then record sql_text to that field after the fact)

Your best bet would be to have a nested child span, one for each SQL query you have, I think.