Repository navigation
Remove severity-number exporter patch; map severity at emit time #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d399005
Remove severity-number exporter patch; map severity at emit time
jrothrock 01c87a9
Disable Metrics/AbcSize for transform_body_to_records
jrothrock 27d3c62
Map Logger UNKNOWN to FATAL and add formatter severity specs
jrothrock acc7c8f
Add LogRecordData shim for mismatched exporter/logs SDK versions
jrothrock 6f8a39d
Scope logger_spec's emit_log stub to its own examples
jrothrock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
34 changes: 34 additions & 0 deletions
34
lib/scout_apm/logging/loggers/opentelemetry/log_record_data_compat.rb
This file contains hidden or 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,34 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module OpenTelemetry | ||
| module SDK | ||
| module Logs | ||
| # The OTLP logs exporter and the logs SDK are versioned independently, and every exporter | ||
| # release only requires `opentelemetry-logs-sdk ~> 0.1`, so Bundler can resolve pairs that | ||
| # disagree on LogRecordData's fields: | ||
| # * exporter <= 0.5.1 reads `total_recorded_attributes`, which logs-sdk >= 0.7.0 replaced | ||
| # with `dropped_attributes_count` (read by exporter >= 0.6.0). See #114. | ||
| # * exporter >= 0.5.0 reads `event_name`, which logs-sdk < 0.6.0 does not have. | ||
| # Define whichever of these is missing so any resolved pair can export. | ||
| class LogRecordData | ||
| unless method_defined?(:total_recorded_attributes) | ||
| def total_recorded_attributes | ||
| attributes&.size.to_i + dropped_attributes_count.to_i | ||
| end | ||
| end | ||
|
|
||
| unless method_defined?(:dropped_attributes_count) | ||
| def dropped_attributes_count | ||
| [total_recorded_attributes.to_i - attributes&.size.to_i, 0].max | ||
| end | ||
| end | ||
|
|
||
| unless method_defined?(:event_name) | ||
| def event_name | ||
| nil | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
45 changes: 0 additions & 45 deletions
45
lib/scout_apm/logging/loggers/opentelemetry/log_record_patch.rb
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| require 'logger' | ||
| require 'stringio' | ||
|
|
||
| require 'spec_helper' | ||
|
|
||
| require 'scout_apm_logging' | ||
|
|
||
| describe ScoutApm::Logging::Loggers::Formatter do | ||
| let(:exporter) { OpenTelemetry::SDK::Logs::Export::InMemoryLogRecordExporter.new } | ||
|
|
||
| before do | ||
| ScoutApm::Logging::Context.instance | ||
|
|
||
| provider = OpenTelemetry::SDK::Logs::LoggerProvider.new | ||
| provider.add_log_record_processor(OpenTelemetry::SDK::Logs::Export::SimpleLogRecordProcessor.new(exporter)) | ||
| ScoutApm::Logging::Loggers::OpenTelemetry.logger_provider = provider | ||
| end | ||
|
|
||
| { | ||
| 'DEBUG' => :SEVERITY_NUMBER_DEBUG, | ||
| 'INFO' => :SEVERITY_NUMBER_INFO, | ||
| 'WARN' => :SEVERITY_NUMBER_WARN, | ||
| 'ERROR' => :SEVERITY_NUMBER_ERROR, | ||
| 'FATAL' => :SEVERITY_NUMBER_FATAL, | ||
| 'ANY' => :SEVERITY_NUMBER_FATAL, | ||
| 'SOMETHING_ELSE' => :SEVERITY_NUMBER_UNSPECIFIED | ||
| }.each do |label, expected| | ||
| it "emits #{expected} for #{label}" do | ||
| described_class.new.call(label, Time.now, nil, 'msg') | ||
|
|
||
| record = exporter.emitted_log_records.last | ||
| expect(record.severity_text).to eq(label) | ||
| expect(record.severity_number).to eq(OpenTelemetry::Logs::SeverityNumber.const_get(expected)) | ||
| end | ||
| end | ||
|
|
||
| it 'maps Logger#unknown to FATAL' do | ||
| logger = ::Logger.new(StringIO.new) | ||
| logger.formatter = described_class.new | ||
| logger.unknown('gone') | ||
|
|
||
| expect(exporter.emitted_log_records.last.severity_number).to eq(OpenTelemetry::Logs::SeverityNumber::SEVERITY_NUMBER_FATAL) | ||
| end | ||
| end | ||
This file contains hidden or 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
44 changes: 44 additions & 0 deletions
44
spec/unit/loggers/opentelemetry/log_record_data_compat_spec.rb
This file contains hidden or 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,44 @@ | ||
| require 'spec_helper' | ||
|
|
||
| require_relative '../../../../lib/scout_apm/logging/loggers/opentelemetry/opentelemetry' | ||
|
|
||
| describe OpenTelemetry::SDK::Logs::LogRecordData do | ||
| let(:exporter) { OpenTelemetry::SDK::Logs::Export::InMemoryLogRecordExporter.new } | ||
|
|
||
| let(:log_record_data) do | ||
| provider = OpenTelemetry::SDK::Logs::LoggerProvider.new | ||
| provider.add_log_record_processor(OpenTelemetry::SDK::Logs::Export::SimpleLogRecordProcessor.new(exporter)) | ||
|
|
||
| provider.logger(name: 'scout_apm', version: '0.1.0').on_emit( | ||
| severity_text: 'INFO', | ||
| severity_number: OpenTelemetry::Logs::SeverityNumber::SEVERITY_NUMBER_INFO, | ||
| attributes: { 'controller' => 'UsersController' }, | ||
| timestamp: Time.now, | ||
| body: 'Processing by UsersController#index' | ||
| ) | ||
|
|
||
| exporter.emitted_log_records.first | ||
| end | ||
|
|
||
| it 'responds to the fields read by every supported exporter version' do | ||
| expect(log_record_data.total_recorded_attributes).to eq(1) | ||
| expect(log_record_data.dropped_attributes_count).to eq(0) | ||
| expect(log_record_data).to respond_to(:event_name) | ||
| end | ||
|
|
||
| it 'exports through the installed OTLP exporter without raising' do | ||
| otlp_exporter = OpenTelemetry::Exporter::OTLP::Logs::LogsExporter.new | ||
| # Exporter >= 0.7.0 moved encoding into opentelemetry-exporter-otlp-common. | ||
| encoded = if otlp_exporter.respond_to?(:encode, true) | ||
| otlp_exporter.send(:encode, [log_record_data]) | ||
| else | ||
| OpenTelemetry::Exporter::OTLP::Common.as_encoded_elsr([log_record_data]) | ||
| end | ||
| request = Opentelemetry::Proto::Collector::Logs::V1::ExportLogsServiceRequest.decode(encoded) | ||
| record = request.resource_logs.first.scope_logs.first.log_records.first | ||
|
|
||
| expect(record.body.string_value).to eq('Processing by UsersController#index') | ||
| expect(record.severity_number).to eq(:SEVERITY_NUMBER_INFO) | ||
| expect(record.dropped_attributes_count).to eq(0) | ||
| end | ||
| end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.