-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add LogStasher instrumentation --------- Co-authored-by: fallwith <[email protected]> Co-authored-by: Kayla Reopelle (she/her) <[email protected]>
- Loading branch information
1 parent
82824c6
commit 49c220a
Showing
13 changed files
with
571 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require_relative 'logstasher/instrumentation' | ||
require_relative 'logstasher/chain' | ||
require_relative 'logstasher/prepend' | ||
|
||
DependencyDetection.defer do | ||
named :logstasher | ||
|
||
depends_on do | ||
defined?(LogStasher) && | ||
Gem::Version.new(LogStasher::VERSION) >= Gem::Version.new('1.0.0') && | ||
NewRelic::Agent.config[:'application_logging.enabled'] | ||
end | ||
|
||
executes do | ||
NewRelic::Agent.logger.info('Installing LogStasher instrumentation') | ||
|
||
if use_prepend? | ||
prepend_instrument LogStasher.singleton_class, NewRelic::Agent::Instrumentation::LogStasher::Prepend | ||
else | ||
chain_instrument NewRelic::Agent::Instrumentation::LogStasher::Chain | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
module NewRelic::Agent::Instrumentation | ||
module LogStasher::Chain | ||
def self.instrument! | ||
::LogStasher.singleton_class.class_eval do | ||
include NewRelic::Agent::Instrumentation::LogStasher | ||
|
||
alias_method(:build_logstash_event_without_new_relic, :build_logstash_event) | ||
|
||
def build_logstash_event(*args) | ||
build_logstash_event_with_new_relic(*args) do | ||
build_logstash_event_without_new_relic(*args) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
lib/new_relic/agent/instrumentation/logstasher/instrumentation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
module NewRelic::Agent::Instrumentation | ||
module LogStasher | ||
INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name) | ||
|
||
def self.enabled? | ||
NewRelic::Agent.config[:'instrumentation.logstasher'] != 'disabled' | ||
end | ||
|
||
def build_logstash_event_with_new_relic(*args) | ||
logstasher_event = yield | ||
log = logstasher_event.instance_variable_get(:@data) | ||
|
||
::NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) | ||
::NewRelic::Agent.agent.log_event_aggregator.record_logstasher_event(log) | ||
::NewRelic::Agent::LocalLogDecorator.decorate(log) | ||
|
||
logstasher_event | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
module NewRelic::Agent::Instrumentation | ||
module LogStasher::Prepend | ||
include NewRelic::Agent::Instrumentation::LogStasher | ||
|
||
def build_logstash_event(*args) | ||
build_logstash_event_with_new_relic(*args) { super } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
instrumentation_methods :chain, :prepend | ||
|
||
logstasher_versions = [ | ||
[nil, 2.7] | ||
] | ||
|
||
# Lock down activesupport version due to a logstasher test incompatiability with 7.1. | ||
def gem_list(logstasher_versions = nil) | ||
<<~RB | ||
gem 'logstasher'#{logstasher_versions} | ||
gem 'activesupport', '< 7.1' | ||
RB | ||
end | ||
|
||
create_gemfiles(logstasher_versions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
development: | ||
error_collector: | ||
enabled: true | ||
apdex_t: 0.5 | ||
monitor_mode: true | ||
license_key: bootstrap_newrelic_admin_license_key_000 | ||
instrumentation: | ||
logstasher: <%= $instrumentation_method %> | ||
app_name: test | ||
log_level: debug | ||
host: 127.0.0.1 | ||
api_host: 127.0.0.1 | ||
transaction_trace: | ||
record_sql: obfuscated | ||
enabled: true | ||
stack_trace_threshold: 0.5 | ||
transaction_threshold: 1.0 | ||
capture_params: false | ||
application_logging: | ||
forwarding: | ||
enabled: true |
Oops, something went wrong.