Skip to content

Commit

Permalink
Allow to change transaction name
Browse files Browse the repository at this point in the history
  • Loading branch information
olerapx committed Oct 3, 2023
1 parent 3f44db4 commit 2088f1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod tag;
mod util;
mod worker;

use phper::{ini::Policy, modules::Module, php_get_module};
use phper::{functions::Argument, ini::Policy, modules::Module, php_get_module};

use crate::request::HACK_SWOOLE_ON_REQUEST_FUNCTION_NAME;
pub use errors::{Error, Result};
Expand Down Expand Up @@ -194,5 +194,12 @@ pub fn get_module() -> Module {
request::skywalking_hack_swoole_on_request,
);

module
.add_function(
"skywalking_set_operation_name",
request::skywalking_set_operation_name,
)
.argument(Argument::by_val("name"));

module
}
11 changes: 11 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,14 @@ fn finish_request_context(request_id: Option<i64>, status_code: i32) -> crate::R

Ok(())
}

pub fn skywalking_set_operation_name(args: &mut [ZVal]) -> phper::Result<()> {
let name = args[0].expect_z_str()?.to_str()?;

let _ = RequestContext::try_with_global(None, |ctx| {
ctx.entry_span.span_object_mut().operation_name = name.to_string();
Ok(())
});

Ok(())
}

0 comments on commit 2088f1d

Please sign in to comment.