Skip to content

feat: Accept synchronous hooks on the async client - #548

Draft
jsonbailey wants to merge 2 commits into
mainfrom
jb/sdk-3077/sync-hooks-async-client
Draft

jsonbailey wants to merge 2 commits into
mainfrom
jb/sdk-3077/sync-hooks-async-client

Conversation

@jsonbailey

Copy link
Copy Markdown
Contributor

feat: Remove the experimental AsyncHook class

Summary

AsyncLDClient now uses the same ldclient.hook.Hook as LDClient, so existing integrations such as the OpenTelemetry tracing hook work with the async client. Before this change, the async client accepted only AsyncHook and ignored sync hooks.

  • The async client runs the hook stages synchronously in the caller's task. A span or context variable set in the before stage stays current until the after stage.
  • AsyncHook is removed. The async API is experimental.
  • AsyncPlugin keeps its async register(). Its get_hooks() now returns Hook instances.
  • AsyncConfig and add_hook() ignore items of the wrong type, the same as the sync client.
  • The async contract-test service uses the sync PostingHook.

AsyncLDClient now takes the same ldclient.hook.Hook as LDClient, so
integrations such as the OpenTelemetry tracing hook work with it. The
hook stages run synchronously in the caller's task, so a span made
current in the before stage stays current until the after stage.

AsyncHook is removed. AsyncPlugin keeps its async register(), and its
get_hooks() returns Hook instances. AsyncConfig now raises TypeError
for a hook that is not a Hook or a plugin that is not an AsyncPlugin,
which matches add_hook().
Match the sync client: AsyncConfig and add_hook() ignore items of the wrong type. The async contract-test service uses the sync PostingHook. Remove redundant docstring notes.
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.

1 participant