147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/sashiko/adapters/anthropic.rb', line 147
def create(**params)
attrs = { "gen_ai.system" => "anthropic", "gen_ai.operation.name" => "chat" }
attrs["gen_ai.request.model"] = params[:model] if params.key?(:model)
attrs["gen_ai.request.max_tokens"] = params[:max_tokens] if params.key?(:max_tokens)
attrs["gen_ai.request.temperature"] = params[:temperature] if params.key?(:temperature)
attrs["gen_ai.request.top_p"] = params[:top_p] if params.key?(:top_p)
tracer = self.class.instance_variable_get(:@__sashiko_tracer) || Sashiko.tracer
tracer.in_span("chat #{params[:model]}", attributes: attrs, kind: :client) do |span|
response = super(**params)
Anthropic.record_response(span, response)
response
rescue => e
span.record_exception(e)
span.status = OpenTelemetry::Trace::Status.error(e.message)
raise
end
end
|