before method
Before flag evaluation.
Returned context updates are merged into the evaluation context before the provider is called and before later before hooks execute.
Implementation
@override
Future<Map<String, dynamic>?> before(HookContext context) async {
final startTime = DateTime.now();
// Start span with OTel naming convention
final attributes = <String, Object?>{
'feature_flag.key': context.flagKey,
'feature_flag.provider_name':
context.providerMetadata?.name ?? 'IntelliToggle',
};
// Extract targetingKey from evaluation context map (required by OTel)
final evalContext = context.evaluationContext;
if (evalContext.containsKey('targetingKey')) {
attributes['feature_flag.context.targetingKey'] =
evalContext['targetingKey'];
}
final span = Telemetry.startSpan('feature_flag', attributes: attributes);
context.hookData.set(_spanKey, span);
context.hookData.set(_startTimeKey, startTime);
// Increment total evaluation counter
Telemetry.metrics.increment('feature_flag.evaluation_count');
return null;
}