class NewRelic::Agent::Llm::LlmEvent
Constants
- AGENT_DEFINED_ATTRIBUTES
-
These attributes should not be passed as arguments to initialize and will be set by the agent
- ATTRIBUTES
-
Every subclass must define its own
ATTRIBUTES
constant, an array of symbols representing that class’s unique attributes - ATTRIBUTE_NAME_EXCEPTIONS
-
Some attributes have names that can’t be written as symbols used for metaprogramming. The
ATTRIBUTE_NAME_EXCEPTIONS
hash should use the symbolized version of the name as the key and the string version expected by the UI as the value. - CODE_STRING
- ERROR_ATTRIBUTE_CODE
- ERROR_ATTRIBUTE_PARAM
- ERROR_ATTRIBUTE_STATUS_CODE
- ERROR_STRING
- INGEST_SOURCE
- PARAM_STRING
Public Class Methods
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 38 def initialize(opts = {}) (attributes - AGENT_DEFINED_ATTRIBUTES).each do |attr| instance_variable_set(:"@#{attr}", opts[attr]) if opts.key?(attr) end @id = id || NewRelic::Agent::GuidGenerator.generate_guid @span_id = NewRelic::Agent::Tracer.current_span_id @trace_id = NewRelic::Agent::Tracer.current_trace_id @ingest_source = INGEST_SOURCE end
This initialize method is used for all subclasses. It leverages the subclass’s ‘attributes` method to iterate through all the attributes for that subclass. It assigns instance variables for all arguments passed to the method. It also assigns agent-defined attributes.
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 29 def self.set_llm_agent_attribute_on_transaction NewRelic::Agent::Transaction.add_agent_attribute(:llm, true, NewRelic::Agent::AttributeFilter::DST_TRANSACTION_EVENTS) end
Public Instance Methods
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 74 def attribute_name_exceptions ATTRIBUTE_NAME_EXCEPTIONS end
Some attribute names include periods, which aren’t valid values for Ruby method names. This method returns a Hash with the key as the Ruby symbolized version of the attribute and the value as the period-delimited string expected upstream.
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 62 def attributes ATTRIBUTES end
Subclasses define an attributes method to concatenate attributes defined across their ancestors and other modules
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 83 def error_attributes(exception) NewRelic::EMPTY_HASH end
Subclasses that add attributes to noticed errors will override this method
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 51 def event_attributes attributes_hash = attributes.each_with_object({}) do |attr, hash| hash[replace_attr_with_string(attr)] = instance_variable_get(:"@#{attr}") end attributes_hash.merge!(metadata) && attributes_hash.delete(:metadata) if !metadata.nil? attributes_hash end
All subclasses use event_attributes
to get a full hash of all attributes and their values
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 67 def event_name end
Subclasses that record events will override this method
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 78 def record NewRelic::Agent.record_custom_event(event_name, event_attributes) end
Private Instance Methods
Source
# File lib/new_relic/agent/llm/llm_event.rb, line 89 def replace_attr_with_string(attr) attribute_name_exceptions.fetch(attr, attr) end