Module: NewRelic::Agent::Instrumentation::OpenAI

Included in:
OpenAI::Prepend
Defined in:
lib/new_relic/agent/instrumentation/ruby_openai/instrumentation.rb

Defined Under Namespace

Modules: Chain, Prepend

Constant Summary collapse

VENDOR =

AIM expects this capitalization style for the UI

'openAI'
INSTRUMENTATION_NAME =
NewRelic::Agent.base_name(name)
EMBEDDINGS_PATH =
'/embeddings'
CHAT_COMPLETIONS_PATH =
'/chat/completions'
EMBEDDINGS_SEGMENT_NAME =
'Llm/embedding/OpenAI/embeddings'
CHAT_COMPLETIONS_SEGMENT_NAME =
'Llm/completion/OpenAI/chat'

Instance Method Summary collapse

Instance Method Details

#json_post_with_new_relic(path:, parameters:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/new_relic/agent/instrumentation/ruby_openai/instrumentation.rb', line 14

def json_post_with_new_relic(path:, parameters:)
  return yield unless path == EMBEDDINGS_PATH || path == CHAT_COMPLETIONS_PATH

  NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
  NewRelic::Agent::Llm::LlmEvent.set_llm_agent_attribute_on_transaction
  record_openai_metric

  if path == EMBEDDINGS_PATH
    embeddings_instrumentation(parameters) { yield }
  elsif path == CHAT_COMPLETIONS_PATH
    chat_completions_instrumentation(parameters) { yield }
  end
end