ApplyGuardrailScope class
为安全防护措施评估操作提供 OpenTelemetry 跟踪范围。
描述安全保护者评估。 如果多个监护人被链接,则多个监护人跨度可能存在于单个操作范围下。
监护人范围应该是他们保护的操作范围的孩子(例如推理或execute_tool跨度)。
方法
| record |
记录护栏评估的输出内容值(选择加入)。 |
| record |
记录有关护栏范围的更新决定。 在创建跨度后确定护栏决策时,请使用此功能。 |
| record |
记录当前范围的安全查找事件。 每个护栏评估可能会记录多个发现。 |
| start(Guardrail |
创建并启动一个新的护栏评估跟踪范围。 |
继承的方法
| dispose() | 用于兼容性的旧释放方法 |
| get |
获取此范围的范围上下文。 这可用于为跨异步边界的显式父子链接创建 ParentSpanRef。 |
| record |
记录多个用于遥测跟踪的属性键/值对。 |
| record |
记录跨度上的取消事件。 使用取消原因将范围状态设置为 ERROR,并将错误类型标记为“TaskCanceledException”。 |
| record |
记录作期间发生的错误 |
| set |
设置范围的自定义结束时间。
设置后, 释放 会将此值 |
| with |
使此范围在异步回调执行期间处于活动状态 |
| [dispose]() | 释放范围并完成遥测数据收集 |
方法详细信息
recordContentOutput(string)
记录护栏评估的输出内容值(选择加入)。
function recordContentOutput(outputValue: string)
参数
- outputValue
-
string
护栏处理后的输出内容。
recordDecision(GuardrailDecisionType, string)
记录有关护栏范围的更新决定。 在创建跨度后确定护栏决策时,请使用此功能。
function recordDecision(decisionType: GuardrailDecisionType, reason?: string)
参数
- decisionType
- GuardrailDecisionType
监护人做出的决定类型。
- reason
-
string
决定的可选人工可读解释。
recordFinding(GuardrailFinding)
记录当前范围的安全查找事件。 每个护栏评估可能会记录多个发现。
function recordFinding(finding: GuardrailFinding)
参数
- finding
- GuardrailFinding
要记录的安全发现。
start(GuardrailDetails, AgentDetails, Request, UserDetails, SpanDetails)
创建并启动一个新的护栏评估跟踪范围。
static function start(details: GuardrailDetails, agentDetails: AgentDetails, request?: Request, userDetails?: UserDetails, spanDetails?: SpanDetails): ApplyGuardrailScope
参数
- details
- GuardrailDetails
护栏评估的详细信息(目标、决策、监护人信息、政策)。
- agentDetails
- AgentDetails
有关要保护的代理的信息。
- request
- Request
会话上下文的可选请求详细信息。
- userDetails
- UserDetails
可选的人工用户详细信息。
- spanDetails
- SpanDetails
可选范围配置(父上下文、计时、种类、跨度链接)。
返回
新的 ApplyGuardrailScope 实例。
继承的方法详细信息
dispose()
getSpanContext()
获取此范围的范围上下文。 这可用于为跨异步边界的显式父子链接创建 ParentSpanRef。
function getSpanContext(): SpanContext
返回
SpanContext
包含 traceId 和 spanId 的 SpanContext
recordAttributes(Iterable<[string, AttributeValue], any, any> | Record<string, AttributeValue> | null | undefined)
记录多个用于遥测跟踪的属性键/值对。
function recordAttributes(attributes: Iterable<[string, AttributeValue], any, any> | Record<string, AttributeValue> | null | undefined)
参数
- attributes
-
Iterable<[string, AttributeValue], any, any> | Record<string, AttributeValue> | null | undefined
属性键/值对的集合(数组或可迭代 [键,值] 或对象映射)。
recordCancellation(string)
记录跨度上的取消事件。 使用取消原因将范围状态设置为 ERROR,并将错误类型标记为“TaskCanceledException”。
function recordCancellation(reason?: string)
参数
- reason
-
string
可选的取消原因。 默认为“任务已取消”。
recordError(Error)
记录作期间发生的错误
function recordError(error: Error)
参数
- error
-
Error
发生的错误
setEndTime(TimeInput)
设置范围的自定义结束时间。
设置后, 释放 会将此值 span.end() 传递给而不是使用当前的时钟时间。
当在释放作用域之前已知操作的实际结束时间时,这非常有用。
function setEndTime(endTime: TimeInput)
参数
- endTime
-
TimeInput
自纪元、日期或 HrTime 元组以来的结束时间(以毫秒为单位)。
withActiveSpanAsync<T>(() => Promise<T>)
使此范围在异步回调执行期间处于活动状态
function withActiveSpanAsync<T>(callback: () => Promise<T>): Promise<T>
参数
- callback
-
() => Promise<T>
返回
Promise<T>