Class: NewRelic::Agent::LLM
- Inherits:
-
Object
- Object
- NewRelic::Agent::LLM
- Defined in:
- lib/new_relic/agent/llm.rb
Constant Summary collapse
- INPUT =
'input'
- CONTENT =
'content'
- SEGMENT_PATTERN =
%r{Llm/.+/OpenAI/.+}.freeze
Class Method Summary collapse
-
.exempt_event_attribute?(type, key) ⇒ Boolean
LLM content-related attributes are exempt from the 4095 byte limit.
- .instrumentation_enabled? ⇒ Boolean
- .openai? ⇒ Boolean
-
.openai_parent?(segment) ⇒ Boolean
Used in NetHTTP instrumentation.
- .populate_openai_response_headers(response, parent) ⇒ Object
Class Method Details
.exempt_event_attribute?(type, key) ⇒ Boolean
LLM content-related attributes are exempt from the 4095 byte limit
23 24 25 26 27 28 |
# File 'lib/new_relic/agent/llm.rb', line 23 def self.exempt_event_attribute?(type, key) return false unless instrumentation_enabled? (type == NewRelic::Agent::Llm::Embedding::EVENT_NAME && key == INPUT) || (type == NewRelic::Agent::Llm::ChatCompletionMessage::EVENT_NAME && key == CONTENT) end |
.instrumentation_enabled? ⇒ Boolean
18 19 20 |
# File 'lib/new_relic/agent/llm.rb', line 18 def self.instrumentation_enabled? NewRelic::Agent.config[:'ai_monitoring.enabled'] end |
.openai? ⇒ Boolean
30 31 32 33 |
# File 'lib/new_relic/agent/llm.rb', line 30 def self.openai? @openai ||= %i[prepend chain].include?(NewRelic::Agent.config[:'instrumentation.ruby_openai']) && NewRelic::Agent.config[:'ai_monitoring.enabled'] end |
.openai_parent?(segment) ⇒ Boolean
Used in NetHTTP instrumentation
36 37 38 39 40 |
# File 'lib/new_relic/agent/llm.rb', line 36 def self.openai_parent?(segment) return false unless openai? segment&.parent&.name&.match?(SEGMENT_PATTERN) end |
.populate_openai_response_headers(response, parent) ⇒ Object
42 43 44 45 46 |
# File 'lib/new_relic/agent/llm.rb', line 42 def self.populate_openai_response_headers(response, parent) return unless parent.instance_variable_defined?(:@llm_event) parent.llm_event.populate_openai_response_headers(response.to_hash) end |