Skip to content

Conversation

kinyoklion
Copy link
Member

@kinyoklion kinyoklion commented Sep 3, 2025

Add support for hooks to the SDK.

Example of a hook with all methods that logs things.

final class TestHook extends Hook {
  final HookMetadata _metadata = const HookMetadata(name: "test-hook");

  @override
  HookMetadata get metadata => _metadata;

  @override
  UnmodifiableMapView<String, LDValue> beforeEvaluation(
      EvaluationSeriesContext hookContext,
      UnmodifiableMapView<String, LDValue> data) {
    print(
        'TestHook.beforeEvaluation called with: hookContext=$hookContext, data=$data');
    return super.beforeEvaluation(hookContext, data);
  }

  @override
  UnmodifiableMapView<String, LDValue> afterEvaluation(
      EvaluationSeriesContext hookContext,
      UnmodifiableMapView<String, LDValue> data,
      LDEvaluationDetail<LDValue> detail) {
    print(
        'TestHook.afterEvaluation called with: hookContext=$hookContext, data=$data, detail=$detail');
    return super.afterEvaluation(hookContext, data, detail);
  }

  @override
  UnmodifiableMapView<String, LDValue> beforeIdentify(
      IdentifySeriesContext hookContext,
      UnmodifiableMapView<String, LDValue> data) {
    print(
        'TestHook.beforeIdentify called with: hookContext=$hookContext, data=$data');
    return super.beforeIdentify(hookContext, data);
  }

  @override
  UnmodifiableMapView<String, LDValue> afterIdentify(
      IdentifySeriesContext hookContext,
      UnmodifiableMapView<String, LDValue> data,
      IdentifyResult result) {
    print(
        'TestHook.afterIdentify called with: hookContext=$hookContext, data=$data, result=$result');
    return super.afterIdentify(hookContext, data, result);
  }

  @override
  void afterTrack(TrackSeriesContext hookContext) {
    print('TestHook.afterTrack called with: hookContext=$hookContext');
    super.afterTrack(hookContext);
  }
}

Minimal hook:

Example of a hook with all methods that logs things.
```dart
final class TestHook extends Hook {
  final HookMetadata _metadata = const HookMetadata(name: "test-hook");

  @override
  HookMetadata get metadata => _metadata;

@kinyoklion
Copy link
Member Author

bugbot review

cursor[bot]

This comment was marked as outdated.

@kinyoklion
Copy link
Member Author

bugbot review

cursor[bot]

This comment was marked as outdated.

@kinyoklion kinyoklion marked this pull request as ready for review September 5, 2025 17:00
@kinyoklion kinyoklion requested a review from a team as a code owner September 5, 2025 17:00
cursor[bot]

This comment was marked as outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updating these tests for environment ID now that it has been added.

}

Future<IdentifyResult> _mapIdentifyResult(TaskResult<void> res) async {
IdentifyResult _mapIdentifyResult(TaskResult<void> res) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This method didn't need to be async as it runs only on already resolved promises.

@kinyoklion kinyoklion merged commit 6e7a26d into main Sep 8, 2025
5 checks passed
@kinyoklion kinyoklion deleted the rlamb/o11y-450/add-hooks-support branch September 8, 2025 15:51
kinyoklion pushed a commit that referenced this pull request Sep 12, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.7.0](launchdarkly_common_client-v1.6.2...launchdarkly_common_client-v1.7.0)
(2025-09-12)


### Features

* Add experimental plugin support.
([#225](#225))
([5bd9ce7](5bd9ce7))
* Add support for hooks.
([#220](#220))
([6e7a26d](6e7a26d))
* Internal environment ID support.
([#217](#217))
([71b522b](71b522b))


### Bug Fixes

* Change hook data values to `dynamic` from `LDValue`.
([d7720f3](d7720f3))
* Export required plugin meta-data types.
([d7720f3](d7720f3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
kinyoklion added a commit that referenced this pull request Sep 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[4.12.0](4.11.2...4.12.0)
(2025-09-15)


### Features

* Add experimental plugin support.
([#225](#225))
([5bd9ce7](5bd9ce7))
* Add hook support and experimental plugin support.
([#228](#228))
([b698905](b698905))
* Add support for hooks.
([#220](#220))
([6e7a26d](6e7a26d))
* Update version constraints for device_info_plus to allow using 12.x.
([9b5f530](9b5f530))
* Update version constraints for package_info_plus to allow using 9.x.
([9b5f530](9b5f530))


### Bug Fixes

* Change hook data values to `dynamic` from `LDValue`.
([d7720f3](d7720f3))
* Export required plugin meta-data types.
([d7720f3](d7720f3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Ryan Lamb <[email protected]>
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.

2 participants