Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/datadog/ai_guard/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def perform(messages, allow_raise: false)
raise ArgumentError, "Messages must not be empty" if messages&.empty?

Tracing.trace(Ext::SPAN_NAME) do |span, trace|
trace.keep!
trace.set_tag(
Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER,
Tracing::Sampling::Ext::Decision::AI_GUARD
)

Comment thread
y9v marked this conversation as resolved.
if (last_message = messages.last)
if last_message.tool_call
span.set_tag(Ext::TARGET_TAG, "tool")
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/tracing/sampling/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module Decision
MANUAL = '-4'
# Formerly AppSec.
ASM = '-5'
# AI Guard.
AI_GUARD = '-13'
# Dynamically configured rule, explicitly created by the user.
REMOTE_USER_RULE = '-11'
# Dynamically configured rule, automatically generated by Datadog.
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/tracing/sampling/ext.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Datadog
TRACE_SAMPLING_RULE: ::String
MANUAL: ::String
ASM: ::String
AI_GUARD: ::String
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/datadog/ai_guard/evaluation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
expect(ai_guard_span).not_to be_nil
end

it "sets manual.keep on the trace with AI Guard decision maker" do
described_class.perform([
Datadog::AIGuard.message(role: :user, content: "Some content")
])

trace = traces.first
expect(trace.sampling_priority).to eq(Datadog::Tracing::Sampling::Ext::Priority::USER_KEEP)
expect(trace.send(:sampling_decision_maker)).to eq('-13')
end

it "sets target tag to 'prompt' when last message is a prompt" do
described_class.perform([
Datadog::AIGuard.message(role: :system, content: "Some content"),
Expand Down
Loading