Class: NewRelic::Agent::Transaction::DatastoreSegment
- Inherits:
-
Segment
show all
- Defined in:
- lib/new_relic/agent/transaction/datastore_segment.rb
Constant Summary
collapse
- UNKNOWN =
'unknown'.freeze
AbstractSegment::CALLBACK, AbstractSegment::INSPECT_IGNORE, AbstractSegment::SEGMENT
Instance Attribute Summary collapse
Attributes inherited from Segment
#custom_transaction_attributes, #unscoped_metrics
#children_time, #duration, #end_time, #exclusive_duration, #guid, #llm_event, #name, #noticed_error, #parent, #record_on_finish, #record_scoped_metric, #start_time, #starting_segment_key, #transaction, #transaction_name
Instance Method Summary
collapse
-
#_notice_sql(sql, config = nil, explainer = nil, binds = nil, name = nil) ⇒ Object
private
-
#initialize(product, operation, collection = nil, host = nil, port_path_or_id = nil, database_name = nil, start_time = nil) ⇒ DatastoreSegment
constructor
A new instance of DatastoreSegment.
-
#notice_nosql_statement(nosql_statement) ⇒ Object
Method for simplifying attaching non-SQL data statements to a transaction.
-
#notice_sql(sql) ⇒ Object
-
#record_metrics ⇒ Object
-
#set_instance_info(host = nil, port_path_or_id = nil) ⇒ Object
Methods inherited from Segment
#add_agent_attribute, #add_custom_attributes, #attributes, finish, #merge_untrusted_agent_attributes, merge_untrusted_agent_attributes
#all_code_information_present?, #children_time_ranges?, #code_attributes, #code_information=, #concurrent_children?, #finalize, #finish, #finished?, #inspect, #notice_error, #noticed_error_attributes, #params, #params?, #record_metrics?, #record_on_finish?, #record_scoped_metric?, #set_noticed_error, #start, #time_range, #transaction_assigned
Constructor Details
#initialize(product, operation, collection = nil, host = nil, port_path_or_id = nil, database_name = nil, start_time = nil) ⇒ DatastoreSegment
Returns a new instance of DatastoreSegment.
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 19
def initialize(product, operation, collection = nil, host = nil, port_path_or_id = nil, database_name = nil, start_time = nil)
@product = product
@operation = operation
@collection = collection
@sql_statement = nil
@nosql_statement = nil
@record_sql = true
set_instance_info(host, port_path_or_id)
@database_name = database_name&.to_s
super(Datastores::MetricHelper.scoped_metric_for(product, operation, collection),
nil,
start_time)
end
|
Instance Attribute Details
#collection ⇒ Object
16
17
18
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 16
def collection
@collection
end
|
#database_name ⇒ Object
17
18
19
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 17
def database_name
@database_name
end
|
#host ⇒ Object
16
17
18
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 16
def host
@host
end
|
#nosql_statement ⇒ Object
16
17
18
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 16
def nosql_statement
@nosql_statement
end
|
#operation ⇒ Object
16
17
18
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 16
def operation
@operation
end
|
#port_path_or_id ⇒ Object
16
17
18
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 16
def port_path_or_id
@port_path_or_id
end
|
#product ⇒ Object
16
17
18
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 16
def product
@product
end
|
#record_sql ⇒ Object
17
18
19
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 17
def record_sql
@record_sql
end
|
#sql_statement ⇒ Object
16
17
18
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 16
def sql_statement
@sql_statement
end
|
Instance Method Details
#_notice_sql(sql, config = nil, explainer = nil, binds = nil, name = nil) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
64
65
66
67
68
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 64
def _notice_sql(sql, config = nil, explainer = nil, binds = nil, name = nil)
return unless record_sql?
@sql_statement = Database::Statement.new(sql, config, explainer, binds, name, host, port_path_or_id, database_name)
end
|
#notice_nosql_statement(nosql_statement) ⇒ Object
Note:
THERE ARE SECURITY CONCERNS WHEN CAPTURING STATEMENTS! This method will properly ignore statements when the user has turned off capturing queries, but it is not able to obfuscate arbitrary data! To prevent exposing user information embedded in captured queries, please ensure all data passed to this method is safe to transmit to New Relic.
Method for simplifying attaching non-SQL data statements to a transaction. For instance, Mongo or CQL queries, Memcached or Redis keys would all be appropriate data to attach as statements.
Data passed to this method is NOT obfuscated by New Relic, so please ensure that user information is obfuscated if the agent setting ‘transaction_tracer.record_sql` is set to `obfuscated`
87
88
89
90
91
92
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 87
def notice_nosql_statement(nosql_statement)
return unless record_sql?
@nosql_statement = Database.truncate_query(nosql_statement)
nil
end
|
#notice_sql(sql) ⇒ Object
58
59
60
61
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 58
def notice_sql(sql)
_notice_sql(sql)
nil
end
|
#record_metrics ⇒ Object
94
95
96
97
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 94
def record_metrics
@unscoped_metrics = Datastores::MetricHelper.unscoped_metrics_for(product, operation, collection, host, port_path_or_id)
super
end
|
#set_instance_info(host = nil, port_path_or_id = nil) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/new_relic/agent/transaction/datastore_segment.rb', line 33
def set_instance_info(host = nil, port_path_or_id = nil)
port_path_or_id = port_path_or_id.to_s if port_path_or_id
host_present = host && !host.empty?
ppi_present = port_path_or_id && !port_path_or_id.empty?
host = NewRelic::Agent::Hostname.get_external(host) if host_present
case
when host_present && ppi_present
@host = host
@port_path_or_id = port_path_or_id
when host_present && !ppi_present
@host = host
@port_path_or_id = UNKNOWN
when !host_present && ppi_present
@host = UNKNOWN
@port_path_or_id = port_path_or_id
else
@host = @port_path_or_id = nil
end
end
|