Skip to content

Commit 53ec5f6

Browse files
authored
fix: Add usage tracking to config method (#15)
1 parent b964886 commit 53ec5f6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,26 @@
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+
expect(ld_client).to receive(:track).with(
384+
'$ld:ai:config:function:single',
385+
context,
386+
'test-config-key',
387+
1
388+
)
389+
allow(ld_client).to receive(:variation).and_return({
390+
'_ldMeta' => { 'enabled' => true, 'variationKey' => 'test-variation', 'version' => 1 },
391+
'model' => { 'name' => 'test-model' },
392+
'provider' => { 'name' => 'test-provider' },
393+
'messages' => [],
394+
})
395+
396+
client = LaunchDarkly::Server::AI::Client.new(ld_client)
397+
default_value = LaunchDarkly::Server::AI::AIConfig.new(enabled: false)
398+
399+
client.config('test-config-key', context, default_value)
400+
end
401+
end
380402
end

0 commit comments

Comments
 (0)