Skip to content

Commit

Permalink
Move CString init out of log_callback arg
Browse files Browse the repository at this point in the history
  • Loading branch information
javorszky authored and avahahn committed Aug 13, 2024
1 parent d949513 commit 9888c14
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 3 additions & 1 deletion auto/otel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cd ../../
nxt_feature="otel"
nxt_feature_name=NXT_HAVE_OTEL
nxt_feature_run=no
nxt_feature_libs=
nxt_feature_libs=""
nxt_feature_test="int main(void){return 0;}"

. auto/feature
Expand All @@ -27,3 +27,5 @@ if [ $nxt_found = no ]; then
$echo
exit 1;
fi

NXT_LIB_AUX_LIBS="$NXT_LIB_AUX_LIBS -lssl -lcrypto src/otel/target/debug/libotel.a"
3 changes: 1 addition & 2 deletions src/nxt_h1proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1837,10 +1837,9 @@ nxt_h1p_conn_sent(nxt_task_t *task, void *obj, void *data)
{
nxt_conn_t *c;
nxt_event_engine_t *engine;
#if (NXT_HAVE_OTEL)
nxt_http_request_t *r;
r = ((nxt_h1proto_t *) data)->request;

#if (NXT_HAVE_OTEL)
nxt_otel_test_and_call_state(task, r);
#endif

Expand Down
4 changes: 3 additions & 1 deletion src/nxt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ main(int argc, char **argv)

nxt_main_log.handler = nxt_log_time_handler;

nxt_otel_init(otel_phase1_log_callback);
#if (NXT_HAVE_OTEL)
nxt_otel_init(&otel_phase1_log_callback);
#endif
ret = nxt_runtime_create(&nxt_main_task);

if (ret != NXT_OK) {
Expand Down
16 changes: 6 additions & 10 deletions src/otel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ unsafe fn nxt_otel_init(log_callback: unsafe extern "C" fn(*mut i8)) {

// unwrap
match res {
Err(e) => log_callback(
CString::from_vec_unchecked(e.to_string().as_bytes().to_vec())
.into_raw() as _,
),
Err(e) => {
let msg =CString::from_vec_unchecked(e.to_string().as_bytes().to_vec());
log_callback(msg.into_raw() as _)
},
Ok(t) => {
GLOBAL_TRACER_PROVIDER.get_or_init(move || t);
log_callback(
CString::from_vec_unchecked(
"otel exporter has been initialised".as_bytes().to_vec(),
)
.into_raw() as _,
);
let msg = CString::from_vec_unchecked("otel exporter has been initialised".as_bytes().to_vec());
log_callback(msg.into_raw() as _);
}
}
}
Expand Down

0 comments on commit 9888c14

Please sign in to comment.