Skip to content

Commit ceb2144

Browse files
committed
Add RBS for newrelic_rpm 9.19
1 parent 707b93b commit ceb2144

File tree

3 files changed

+313
-0
lines changed

3 files changed

+313
-0
lines changed

gems/newrelic_rpm/.rubocop.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This configuration inherits from /.rubocop.yml.
2+
# You can configure RBS style of this gem.
3+
# This file is used on CI. It is configured to automatically
4+
# make rubocop suggestions on pull requests for this gem.
5+
# If you do not like the style enforcement, you should remove this file.
6+
inherit_from: ../../.rubocop.yml
7+
8+
##
9+
# If you want to customize the style, please consult with the gem reviewers.
10+
# You can see the list of cops at https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages/cops.adoc
11+
12+
RBS/Layout:
13+
Enabled: true
14+
15+
RBS/Lint:
16+
Enabled: true
17+
18+
RBS/Style:
19+
Enabled: true

gems/newrelic_rpm/9.19/_test/test.rb

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
require 'newrelic_rpm'
2+
3+
# Test NewRelic version constants
4+
puts NewRelic::VERSION::STRING
5+
puts NewRelic::VERSION::MAJOR
6+
puts NewRelic::VERSION::MINOR
7+
puts NewRelic::VERSION::TINY
8+
9+
# Test manual agent control
10+
NewRelic::Agent.manual_start(
11+
app_name: 'TestApp',
12+
log_level: 'info',
13+
env: 'test'
14+
)
15+
16+
# Test after_fork
17+
NewRelic::Agent.after_fork(force_reconnect: true)
18+
19+
# Test recording metrics
20+
NewRelic::Agent.record_metric('Custom/TestMetric', 1.5)
21+
NewRelic::Agent.record_metric('Custom/TestMetric2', { count: 5, total: 10.0, min: 1.0, max: 3.0 })
22+
NewRelic::Agent.increment_metric('Custom/Counter')
23+
NewRelic::Agent.increment_metric('Custom/Counter2', 5)
24+
25+
# Test error handling
26+
begin
27+
raise StandardError, "Test error"
28+
rescue => e
29+
NewRelic::Agent.notice_error(e)
30+
NewRelic::Agent.notice_error(e, custom_params: { user_id: 123 })
31+
NewRelic::Agent.notice_error(e, expected: true, uri: '/test', metric: 'Controller/test')
32+
end
33+
34+
# Test error filter - just test the method call without checking the block content
35+
NewRelic::Agent.ignore_error_filter do |_error|
36+
nil
37+
end
38+
39+
# Test error group callback - simplified to avoid untyped issues
40+
NewRelic::Agent.set_error_group_callback(->(hash) {
41+
"error_group_test"
42+
})
43+
44+
# Test custom events
45+
NewRelic::Agent.record_custom_event('TestEvent', { user_id: 123, action: 'click' })
46+
NewRelic::Agent.record_custom_event(:AnotherEvent, { value: 99.9, active: true })
47+
48+
# Test LLM feedback
49+
NewRelic::Agent.record_llm_feedback_event(
50+
trace_id: '1234567890',
51+
rating: 'Good',
52+
category: 'helpful',
53+
message: 'Very helpful response',
54+
metadata: { session_id: 'abc123' }
55+
)
56+
57+
# Test LLM token count callback - simplified to avoid untyped issues
58+
NewRelic::Agent.set_llm_token_count_callback(->(hash) {
59+
42 # Just return a constant
60+
})
61+
62+
# Test transaction control
63+
NewRelic::Agent.set_transaction_name('TestTransaction')
64+
NewRelic::Agent.set_transaction_name('TestTransaction2', category: :task)
65+
name = NewRelic::Agent.get_transaction_name
66+
67+
NewRelic::Agent.ignore_transaction
68+
NewRelic::Agent.ignore_apdex
69+
NewRelic::Agent.ignore_enduser
70+
71+
# Test tracing control
72+
result = NewRelic::Agent.disable_all_tracing do
73+
"traced block result"
74+
end
75+
76+
sql_result = NewRelic::Agent.disable_sql_recording do
77+
"sql recording disabled"
78+
end
79+
80+
# Test custom attributes
81+
NewRelic::Agent.add_custom_attributes(user_id: 123, plan: 'premium')
82+
NewRelic::Agent.add_custom_span_attributes(span_type: 'http', duration: 100)
83+
NewRelic::Agent.add_custom_log_attributes(environment: 'production', service: 'api')
84+
NewRelic::Agent.set_user_id('user123')
85+
86+
# Test database metric name
87+
NewRelic::Agent.with_database_metric_name('User', 'find') do
88+
"database operation"
89+
end
90+
91+
# Test browser timing
92+
header = NewRelic::Agent.browser_timing_header
93+
header_with_nonce = NewRelic::Agent.browser_timing_header('abc123nonce')
94+
95+
# Test linking metadata
96+
metadata = NewRelic::Agent.linking_metadata
97+
98+
# Test instrumentation
99+
NewRelic::Agent.add_instrumentation('lib/custom/*.rb')
100+
101+
# Test SQL obfuscator
102+
NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
103+
sql.gsub(/\d+/, '?')
104+
end
105+
106+
# Test drop_buffered_data without agent running
107+
NewRelic::Agent.drop_buffered_data
108+
109+
# Test that modules are included properly (just verify they exist)
110+
NewRelic::Agent::MethodTracer
111+
NewRelic::Agent::MethodTracer::ClassMethods
112+
NewRelic::Agent::Instrumentation::ControllerInstrumentation
113+
NewRelic::Agent::Instrumentation::ControllerInstrumentation::ClassMethods
114+
115+
# Test constants
116+
NewRelic::Agent::Instrumentation::ControllerInstrumentation::NR_DO_NOT_TRACE_KEY
117+
NewRelic::Agent::Instrumentation::ControllerInstrumentation::NR_IGNORE_APDEX_KEY
118+
NewRelic::Agent::Instrumentation::ControllerInstrumentation::NR_IGNORE_ENDUSER_KEY
119+
NewRelic::Agent::Instrumentation::ControllerInstrumentation::NR_DEFAULT_OPTIONS
120+
121+
# Cleanup
122+
NewRelic::Agent.drop_buffered_data
123+
NewRelic::Agent.shutdown
124+
125+
puts "All NewRelic RPM tests completed"
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# TypeProf 0.21.7
2+
3+
module NewRelic
4+
module VERSION
5+
MAJOR: Integer
6+
MINOR: Integer
7+
TINY: Integer
8+
STRING: String
9+
end
10+
11+
module Agent
12+
extend ::NewRelic::Agent
13+
14+
class LicenseException < StandardError
15+
end
16+
17+
class ForceDisconnectException < StandardError
18+
end
19+
20+
class AutomaticTracerParseException < StandardError
21+
end
22+
23+
class AutomaticTracerTraceException < StandardError
24+
end
25+
26+
class ForceRestartException < StandardError
27+
def message: () -> String
28+
end
29+
30+
class BusyCalculator
31+
def self.busy_count: () -> Integer
32+
end
33+
34+
class UnrecoverableError < StandardError
35+
end
36+
37+
class BackgroundLoadingError < StandardError
38+
end
39+
40+
class InternalAgentError < StandardError
41+
end
42+
43+
TRACE_ID_KEY: String
44+
SPAN_ID_KEY: String
45+
ENTITY_NAME_KEY: String
46+
ENTITY_TYPE_KEY: String
47+
ENTITY_GUID_KEY: String
48+
HOSTNAME_KEY: String
49+
ENTITY_TYPE: String
50+
LLM_FEEDBACK_MESSAGE: String
51+
SUPPORTABILITY_INCREMENT_METRIC: String
52+
EMPTY_STR: String
53+
54+
# Recording custom metrics
55+
def record_metric: (String metric_name, (Numeric | Hash[Symbol, Numeric]) value) -> void
56+
57+
def increment_metric: (String metric_name, ?Integer amount) -> void
58+
59+
# Recording custom errors
60+
def ignore_error_filter: () { (Exception) -> (Exception | nil) } -> (^(Exception) -> (Exception | nil))
61+
| () -> (^(Exception) -> (Exception | nil))?
62+
63+
def notice_error: (Exception exception, ?Hash[Symbol, untyped] options) -> nil
64+
65+
def set_error_group_callback: (^(Hash[Symbol, untyped]) -> String callback_proc) -> void
66+
67+
# Recording custom Insights events
68+
def record_custom_event: ((Symbol | String) event_type, Hash[untyped, untyped] event_attrs) -> nil
69+
70+
def record_llm_feedback_event: (
71+
trace_id: String,
72+
rating: (String | Integer),
73+
?category: String?,
74+
?message: String?,
75+
?metadata: Hash[untyped, untyped]
76+
) -> void
77+
78+
# LLM callbacks
79+
def set_llm_token_count_callback: (^(Hash[Symbol, untyped]) -> Integer callback_proc) -> void
80+
81+
# Manual agent configuration and startup/shutdown
82+
def manual_start: (?Hash[Symbol, untyped] options) -> void
83+
84+
def after_fork: (?Hash[Symbol, untyped] options) -> void
85+
86+
def shutdown: (?Hash[untyped, untyped] options) -> void
87+
88+
def drop_buffered_data: () -> void
89+
90+
def add_instrumentation: (String file_pattern) -> void
91+
92+
def require_test_helper: () -> void
93+
94+
def set_sql_obfuscator: (?(:before | :replace | :after) type) { (String) -> String } -> void
95+
96+
# Ignoring or excluding data
97+
def ignore_transaction: () -> void
98+
99+
def ignore_apdex: () -> void
100+
101+
def ignore_enduser: () -> void
102+
103+
def disable_all_tracing: [T] () { () -> T } -> T
104+
105+
def disable_sql_recording: [T] () { () -> T } -> T
106+
107+
# Adding custom attributes to traces
108+
def add_custom_attributes: (Hash[untyped, untyped] params) -> void
109+
110+
def add_custom_span_attributes: (Hash[untyped, untyped] params) -> void
111+
112+
def add_custom_log_attributes: (Hash[untyped, untyped] params) -> void
113+
114+
def set_user_id: (String user_id) -> void
115+
116+
# Transaction naming
117+
def set_transaction_name: (String name, ?Hash[Symbol, untyped] options) -> void
118+
119+
def get_transaction_name: () -> String?
120+
121+
def with_database_metric_name: [T] (untyped model, ?String? method, ?String? product) { () -> T } -> T
122+
123+
# Trace and Entity metadata
124+
def linking_metadata: () -> Hash[String, String]
125+
126+
# Manual browser monitoring configuration
127+
def browser_timing_header: (?String? nonce) -> String
128+
129+
130+
module MethodTracer
131+
def trace_execution_scoped: [T] ((String | Array[String]) metric_names, ?Hash[Symbol, untyped] options) { () -> T } -> T
132+
133+
def trace_execution_unscoped: [T] ((String | Array[String]) metric_names, ?Hash[Symbol, untyped] options) { () -> T } -> T
134+
135+
module ClassMethods
136+
def add_method_tracer: (Symbol method_name, ?String? metric_name, ?Hash[Symbol, untyped] options) -> void
137+
138+
def remove_method_tracer: (Symbol method_name) -> void
139+
end
140+
141+
def self.included: (Module klass) -> void
142+
143+
def self.extended: (Module klass) -> void
144+
end
145+
146+
module Instrumentation
147+
module ControllerInstrumentation
148+
NR_DO_NOT_TRACE_KEY: Symbol
149+
NR_IGNORE_APDEX_KEY: Symbol
150+
NR_IGNORE_ENDUSER_KEY: Symbol
151+
NR_DEFAULT_OPTIONS: Hash[untyped, untyped]
152+
153+
module ClassMethods
154+
def newrelic_ignore: (?Hash[Symbol, untyped] specifiers) -> void
155+
156+
def newrelic_ignore_apdex: (?Hash[Symbol, untyped] specifiers) -> void
157+
158+
def newrelic_ignore_enduser: (?Hash[Symbol, untyped] specifiers) -> void
159+
160+
def add_transaction_tracer: (Symbol method, ?Hash[Symbol, untyped] options) -> void
161+
end
162+
163+
def perform_action_with_newrelic_trace: [T] (?Hash[Symbol, untyped] options) { () -> T } -> T
164+
165+
def self.included: (Module clazz) -> void
166+
end
167+
end
168+
end
169+
end

0 commit comments

Comments
 (0)