Commit 547e518
authored
feat: Allow register plugins dynamically (#266)
**Requirements**
Add possibility to Register plugins dynamically for separation concerns
from LD flagging and Observability.
It is not customer facing API and doesn't require documentation change.
```
var client = await LdClient.InitAsync(ldConfig, context, TimeSpan.FromSeconds(5));
client.RegisterPlugin(observabilityPlugin);
```
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes hook execution and evaluation/identify wrapping for all
clients (unified Executor path) and introduces concurrent hook list
updates; failures are logged but mis-registered plugins could affect
observability behavior.
>
> **Overview**
> Adds **`LdClient.RegisterPlugin`** so plugins (e.g. observability) can
be attached after `Init`/`InitAsync`, without listing them in
`ConfigurationBuilder.Plugins`.
>
> The hook pipeline is refactored for **runtime hook registration**:
`IHookExecutor` gains **`AddHooks`**, and **`Executor`** keeps an
immutable **`Stages`** snapshot (hooks + before/after executors)
published under a lock; each evaluation/identify call snapshots
`_stages` so before/after stages stay consistent if hooks are added
mid-flight. With zero hooks, evaluation/identify skip hook work.
>
> **`NoopExecutor`** is removed—the client always uses **`Executor`**
(including when no hooks are configured at startup).
**`EnvironmentMetadata`** is always created on the client (not only when
config plugins exist), and is reused for dynamic registration.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
6e1d766. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 2133517 commit 547e518
4 files changed
Lines changed: 142 additions & 50 deletions
File tree
- pkgs/sdk/client/src
- Internal/Hooks
- Executor
- Interfaces
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | | - | |
18 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
19 | 34 | | |
20 | | - | |
21 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
22 | 38 | | |
23 | 39 | | |
24 | 40 | | |
25 | 41 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
31 | 58 | | |
32 | 59 | | |
33 | 60 | | |
34 | 61 | | |
35 | 62 | | |
36 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
37 | 69 | | |
38 | 70 | | |
39 | 71 | | |
40 | | - | |
| 72 | + | |
41 | 73 | | |
42 | 74 | | |
43 | 75 | | |
| |||
46 | 78 | | |
47 | 79 | | |
48 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
49 | 84 | | |
50 | | - | |
| 85 | + | |
51 | 86 | | |
52 | 87 | | |
53 | 88 | | |
54 | 89 | | |
55 | 90 | | |
56 | | - | |
| 91 | + | |
57 | 92 | | |
58 | 93 | | |
59 | 94 | | |
60 | 95 | | |
61 | 96 | | |
62 | 97 | | |
63 | 98 | | |
64 | | - | |
| 99 | + | |
65 | 100 | | |
66 | 101 | | |
67 | 102 | | |
| |||
71 | 106 | | |
72 | 107 | | |
73 | 108 | | |
74 | | - | |
| 109 | + | |
| 110 | + | |
75 | 111 | | |
76 | 112 | | |
77 | 113 | | |
| |||
Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| |||
34 | 32 | | |
35 | 33 | | |
36 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
227 | | - | |
| 229 | + | |
228 | 230 | | |
229 | | - | |
| 231 | + | |
230 | 232 | | |
231 | 233 | | |
232 | | - | |
233 | | - | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| |||
902 | 902 | | |
903 | 903 | | |
904 | 904 | | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
905 | 979 | | |
906 | 980 | | |
907 | 981 | | |
| |||
0 commit comments