Skip to content

Commit e4c5930

Browse files
feat: add usage tracking to config method
- Add tracking call for :ai:config:function:single event - Include test to verify tracking functionality - Follows SDK spec requirement 1.2.3.5 Co-Authored-By: [email protected] <[email protected]>
1 parent b964886 commit e4c5930

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/server/ai/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def initialize(ld_client)
147147
# @return [AIConfig] An AIConfig instance containing the configuration data
148148
#
149149
def config(config_key, context, default_value = nil, variables = nil)
150+
@ld_client.track('$ld:ai:config:function:single', context, config_key, 1)
151+
150152
variation = @ld_client.variation(
151153
config_key,
152154
context,

spec/server/ai/config_tracker_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,28 @@
377377
)
378378
end
379379
end
380+
381+
describe 'config method tracking' do
382+
it 'calls track with correct parameters when config is called' do
383+
allow(ld_client).to receive(:track)
384+
allow(ld_client).to receive(:variation).and_return({
385+
'_ldMeta' => { 'enabled' => true, 'variationKey' => 'test-variation', 'version' => 1 },
386+
'model' => { 'name' => 'test-model' },
387+
'provider' => { 'name' => 'test-provider' },
388+
'messages' => []
389+
})
390+
391+
client = LaunchDarkly::Server::AI::Client.new(ld_client)
392+
default_value = LaunchDarkly::Server::AI::AIConfig.new(enabled: false)
393+
394+
client.config('test-config-key', context, default_value)
395+
396+
expect(ld_client).to have_received(:track).with(
397+
'$ld:ai:config:function:single',
398+
context,
399+
'test-config-key',
400+
1
401+
)
402+
end
403+
end
380404
end

0 commit comments

Comments
 (0)