Skip to content

fix observing namespaced functions#200

Merged
brettmc merged 4 commits intoopen-telemetry:mainfrom
brettmc:namespaced_function
Oct 2, 2025
Merged

fix observing namespaced functions#200
brettmc merged 4 commits intoopen-telemetry:mainfrom
brettmc:namespaced_function

Conversation

@brettmc
Copy link
Contributor

@brettmc brettmc commented Sep 29, 2025

if a user wants to observe a namespaced function, this allows adding the observer with or without a leading slash. Previously, the leading slash caused the lookup to fail, which is not clear to users. Added a test to show that it works with both forms now.

Fixes: open-telemetry/opentelemetry-php#1720

if a user wants to observe a namespaced function, this allows adding the observer
with or without a leading slash. Previously, the leading slash caused the lookup to fail,
which is not clear to users. Added a test to show that it works with both forms now.
@brettmc brettmc requested a review from a team as a code owner September 29, 2025 06:37
static bool find_observers(HashTable *ht, zend_string *n, zend_llist *pre_hooks,
zend_llist *post_hooks) {
otel_observer *observer = zend_hash_find_ptr_lc(ht, n);
zend_string *normalized = normalize_fq_func_name(n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should instead strip the leading \ in add_function_observer to avoid the allocations during lookup.

@@ -0,0 +1,74 @@
--TEST--
Check hooking namespaced function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also want to add a test for hooking a namespaced class method with leading \ in the classname.

@brettmc brettmc merged commit 382ed36 into open-telemetry:main Oct 2, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[opentelemetry-php-instrumentation] Can't seem to hook namespaced functions.

3 participants