-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [8.3.0] - 2024-04-03 ### Added: - This release introduces a Hooks API. Hooks are collections of user-defined callbacks that are executed by the SDK at various points of interest. You can use them to augment the SDK with metrics or tracing. ### Changed: - Dropped explicit support for .NET Core 3.1.
- Loading branch information
Showing
32 changed files
with
1,369 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,3 +183,6 @@ project.lock.json | |
|
||
*.snk | ||
*.p12 | ||
|
||
# Jetbrains | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using LaunchDarkly.Sdk; | ||
using LaunchDarkly.Sdk.Server.Hooks; | ||
|
||
namespace TestService | ||
{ | ||
using SeriesData = ImmutableDictionary<string, object>; | ||
|
||
public class TestHook: Hook | ||
{ | ||
private readonly CallbackService _service; | ||
private readonly Dictionary<string, LdValue> _before; | ||
private readonly Dictionary<string, LdValue> _after; | ||
|
||
public TestHook(string name, CallbackService service, Dictionary<string, LdValue> before, Dictionary<string, LdValue> after) : base(name) | ||
{ | ||
_service = service; | ||
_before = before; | ||
_after = after; | ||
} | ||
|
||
public override SeriesData BeforeEvaluation(EvaluationSeriesContext context, SeriesData data) | ||
{ | ||
_service.Post("", new EvaluationHookParams() | ||
{ | ||
EvaluationSeriesContext = context, | ||
EvaluationSeriesData = data, | ||
Stage = "beforeEvaluation" | ||
}); | ||
|
||
|
||
if (_before == null) return base.BeforeEvaluation(context, data); | ||
var builder = data.ToBuilder(); | ||
foreach (var entry in _before) | ||
{ | ||
builder[entry.Key] = entry.Value; | ||
} | ||
|
||
return builder.ToImmutable(); | ||
} | ||
|
||
public override SeriesData AfterEvaluation(EvaluationSeriesContext context, SeriesData data, EvaluationDetail<LdValue> detail) | ||
{ | ||
_service.Post("", new EvaluationHookParams() | ||
{ | ||
EvaluationSeriesContext = context, | ||
EvaluationSeriesData = data, | ||
EvaluationDetail = new EvaluateFlagResponse(){Reason = detail.Reason, VariationIndex = detail.VariationIndex, Value = detail.Value}, | ||
Stage = "afterEvaluation" | ||
}); | ||
|
||
|
||
if (_after == null) return base.AfterEvaluation(context, data, detail); | ||
var builder = data.ToBuilder(); | ||
foreach (var entry in _after) | ||
{ | ||
builder[entry.Key] = entry.Value; | ||
} | ||
|
||
return builder.ToImmutable(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/LaunchDarkly.ServerSdk/Hooks/EvaluationSeriesContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace LaunchDarkly.Sdk.Server.Hooks | ||
{ | ||
/// <summary> | ||
/// EvaluationSeriesContext represents parameters associated with a feature flag evaluation. It is | ||
/// made available in <see cref="Hook"/> stage callbacks. | ||
/// </summary> | ||
public sealed class EvaluationSeriesContext { | ||
/// <summary> | ||
/// The key of the feature flag. | ||
/// </summary> | ||
public string FlagKey { get; } | ||
|
||
/// <summary> | ||
/// The Context used for evaluation. | ||
/// </summary> | ||
public Context Context { get; } | ||
|
||
/// <summary> | ||
/// The user-provided default value for the evaluation. | ||
/// </summary> | ||
public LdValue DefaultValue { get; } | ||
|
||
/// <summary> | ||
/// The variation method that triggered the evaluation. | ||
/// </summary> | ||
public string Method { get; } | ||
|
||
/// <summary> | ||
/// Constructs a new EvaluationSeriesContext. | ||
/// </summary> | ||
/// <param name="flagKey">the flag key</param> | ||
/// <param name="context">the context</param> | ||
/// <param name="defaultValue">the default value</param> | ||
/// <param name="method">the variation method</param> | ||
public EvaluationSeriesContext(string flagKey, Context context, LdValue defaultValue, string method) { | ||
FlagKey = flagKey; | ||
Context = context; | ||
DefaultValue = defaultValue; | ||
Method = method; | ||
} | ||
} | ||
} |
Oops, something went wrong.