scout_apm_logging 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +17 -2
  3. data/.rubocop.yml +1 -1
  4. data/CHANGELOG.md +6 -0
  5. data/README.md +7 -2
  6. data/lib/scout_apm/logging/config.rb +1 -1
  7. data/lib/scout_apm/logging/loggers/formatter.rb +1 -1
  8. data/lib/scout_apm/logging/loggers/opentelemetry/log_record_patch.rb +38 -0
  9. data/lib/scout_apm/logging/loggers/opentelemetry/opentelemetry.rb +8 -31
  10. data/lib/scout_apm/logging/version.rb +1 -1
  11. data/scout_apm_logging.gemspec +4 -2
  12. data/spec/integration/rails/lifecycle_spec.rb +1 -1
  13. metadata +36 -31
  14. data/lib/scout_apm/logging/loggers/opentelemetry/LICENSE +0 -201
  15. data/lib/scout_apm/logging/loggers/opentelemetry/api/logs/log_record.rb +0 -18
  16. data/lib/scout_apm/logging/loggers/opentelemetry/api/logs/logger.rb +0 -64
  17. data/lib/scout_apm/logging/loggers/opentelemetry/api/logs/logger_provider.rb +0 -31
  18. data/lib/scout_apm/logging/loggers/opentelemetry/api/logs/severity_number.rb +0 -43
  19. data/lib/scout_apm/logging/loggers/opentelemetry/api/logs/version.rb +0 -18
  20. data/lib/scout_apm/logging/loggers/opentelemetry/api/logs.rb +0 -28
  21. data/lib/scout_apm/logging/loggers/opentelemetry/exporter/exporter/otlp/logs_exporter.rb +0 -398
  22. data/lib/scout_apm/logging/loggers/opentelemetry/exporter/exporter/otlp/version.rb +0 -20
  23. data/lib/scout_apm/logging/loggers/opentelemetry/exporter/proto/collector/logs/v1/logs_service_pb.rb +0 -43
  24. data/lib/scout_apm/logging/loggers/opentelemetry/exporter/proto/common/v1/common_pb.rb +0 -58
  25. data/lib/scout_apm/logging/loggers/opentelemetry/exporter/proto/logs/v1/logs_pb.rb +0 -91
  26. data/lib/scout_apm/logging/loggers/opentelemetry/exporter/proto/resource/v1/resource_pb.rb +0 -33
  27. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/export/batch_log_record_processor.rb +0 -223
  28. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/export/log_record_exporter.rb +0 -64
  29. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/export.rb +0 -34
  30. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/log_record.rb +0 -170
  31. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/log_record_data.rb +0 -31
  32. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/log_record_limits.rb +0 -49
  33. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/log_record_processor.rb +0 -52
  34. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/logger.rb +0 -98
  35. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/logger_provider.rb +0 -170
  36. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs/version.rb +0 -20
  37. data/lib/scout_apm/logging/loggers/opentelemetry/sdk/logs.rb +0 -29
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module ScoutApm
8
- module Logging
9
- module Loggers
10
- module OpenTelemetry
11
- module SDK
12
- module Logs
13
- # LogRecordData is a Struct containing {LogRecord} data for export.
14
- LogRecordData = Struct.new(:timestamp, # optional Integer nanoseconds since Epoch
15
- :observed_timestamp, # Integer nanoseconds since Epoch
16
- :severity_text, # optional String
17
- :severity_number, # optional Integer
18
- :body, # optional String, Numeric, Boolean, Array<String, Numeric, Boolean>, Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
19
- :attributes, # optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
20
- :trace_id, # optional String (16-byte binary)
21
- :span_id, # optional String (8-byte binary)
22
- :trace_flags, # optional Integer (8-bit byte of bit flags)
23
- :resource, # optional OpenTelemetry::SDK::Resources::Resource
24
- :instrumentation_scope, # optional OpenTelemetry::SDK::InstrumentationScope
25
- :total_recorded_attributes) # Integer
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module ScoutApm
8
- module Logging
9
- module Loggers
10
- module OpenTelemetry
11
- module SDK
12
- module Logs
13
- # Class that holds log record attribute limit parameters.
14
- class LogRecordLimits
15
- # The global default max number of attributes per {LogRecord}.
16
- attr_reader :attribute_count_limit
17
-
18
- # The global default max length of attribute value per {LogRecord}.
19
- attr_reader :attribute_length_limit
20
-
21
- # Returns a {LogRecordLimits} with the desired values.
22
- #
23
- # @return [LogRecordLimits] with the desired values.
24
- # @raise [ArgumentError] if any of the max numbers are not positive.
25
- def initialize(attribute_count_limit: Integer(::OpenTelemetry::Common::Utilities.config_opt(
26
- 'OTEL_LOG_RECORD_ATTRIBUTE_COUNT_LIMIT',
27
- 'OTEL_ATTRIBUTE_COUNT_LIMIT',
28
- default: 128
29
- )),
30
- attribute_length_limit: ::OpenTelemetry::Common::Utilities.config_opt(
31
- 'OTEL_LOG_RECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT',
32
- 'OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT'
33
- ))
34
- raise ArgumentError, 'attribute_count_limit must be positive' unless attribute_count_limit.positive?
35
- raise ArgumentError, 'attribute_length_limit must not be less than 32' unless attribute_length_limit.nil? || Integer(attribute_length_limit) >= 32
36
-
37
- @attribute_count_limit = attribute_count_limit
38
- @attribute_length_limit = attribute_length_limit.nil? ? nil : Integer(attribute_length_limit)
39
- end
40
-
41
- # The default {LogRecordLimits}.
42
- DEFAULT = new
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
- module ScoutApm
7
- module Logging
8
- module Loggers
9
- module OpenTelemetry
10
- module SDK
11
- module Logs
12
- # LogRecordProcessor describes a duck type and provides a synchronous no-op hook for when a
13
- # {LogRecord} is emitted. It is not required to subclass this
14
- # class to provide an implementation of LogRecordProcessor, provided the interface is
15
- # satisfied.
16
- class LogRecordProcessor
17
- # Called when a {LogRecord} is emitted. Subsequent calls are not
18
- # permitted after shutdown is called.
19
- # @param [LogRecord] log_record The emitted {LogRecord}
20
- # @param [Context] context The {Context}
21
- def on_emit(log_record, context); end
22
-
23
- # Export all log records to the configured `Exporter` that have not yet
24
- # been exported.
25
- #
26
- # This method should only be called in cases where it is absolutely
27
- # necessary, such as when using some FaaS providers that may suspend
28
- # the process after an invocation, but before the `Processor` exports
29
- # the completed spans.
30
- #
31
- # @param [optional Numeric] timeout An optional timeout in seconds.
32
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
33
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
34
- def force_flush(timeout: nil)
35
- Export::SUCCESS
36
- end
37
-
38
- # Called when {LoggerProvider#shutdown} is called.
39
- #
40
- # @param [optional Numeric] timeout An optional timeout in seconds.
41
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
42
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
43
- def shutdown(timeout: nil)
44
- Export::SUCCESS
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module ScoutApm
8
- module Logging
9
- module Loggers
10
- module OpenTelemetry
11
- module SDK
12
- module Logs
13
- # The SDK implementation of OpenTelemetry::Logs::Logger
14
- class Logger < OpenTelemetry::Logs::Logger
15
- # @api private
16
- #
17
- # Returns a new {OpenTelemetry::SDK::Logs::Logger} instance. This should
18
- # not be called directly. New loggers should be created using
19
- # {LoggerProvider#logger}.
20
- #
21
- # @param [String] name Instrumentation package name
22
- # @param [String] version Instrumentation package version
23
- # @param [LoggerProvider] logger_provider The {LoggerProvider} that
24
- # initialized the logger
25
- #
26
- # @return [OpenTelemetry::SDK::Logs::Logger]
27
- def initialize(name, version, logger_provider)
28
- @instrumentation_scope = ::OpenTelemetry::SDK::InstrumentationScope.new(name, version)
29
- @logger_provider = logger_provider
30
- end
31
-
32
- # Emit a {LogRecord} to the processing pipeline.
33
- #
34
- # @param [optional Time] timestamp Time when the event occurred.
35
- # @param [optional Time] observed_timestamp Time when the event was
36
- # observed by the collection system.
37
- # @param [optional OpenTelemetry::Trace::SpanContext] span_context The
38
- # OpenTelemetry::Trace::SpanContext to associate with the
39
- # {LogRecord}.
40
- # @param [optional String] severity_text Original string representation of
41
- # the severity as it is known at the source. Also known as log level.
42
- # @param severity_number [optional Integer] Numerical value of the
43
- # severity. Smaller numerical values correspond to less severe events
44
- # (such as debug events), larger numerical values correspond to more
45
- # severe events (such as errors and critical events).
46
- # @param [optional String, Numeric, Boolean, Array<String, Numeric,
47
- # Boolean>, Hash{String => String, Numeric, Boolean, Array<String,
48
- # Numeric, Boolean>}] body A value containing the body of the log record.
49
- # @param [optional Hash{String => String, Numeric, Boolean,
50
- # Array<String, Numeric, Boolean>}] attributes Additional information
51
- # about the event.
52
- # @param [optional String (16-byte binary)] trace_id Request trace id as
53
- # defined in {https://www.w3.org/TR/trace-context/#trace-id W3C Trace Context}.
54
- # Can be set for logs that are part of request processing and have an
55
- # assigned trace id.
56
- # @param [optional String (8-byte binary)] span_id Span id. Can be set
57
- # for logs that are part of a particular processing span. If span_id
58
- # is present trace_id should also be present.
59
- # @param [optional Integer (8-bit byte of bit flags)] trace_flags Trace
60
- # flag as defined in {https://www.w3.org/TR/trace-context/#trace-flags W3C Trace Context}
61
- # specification. At the time of writing the specification defines one
62
- # flag - the SAMPLED flag.
63
- # @param [optional OpenTelemetry::Context] context The OpenTelemetry::Context
64
- # to associate with the {LogRecord}.
65
- #
66
- # @api public
67
- def on_emit(timestamp: nil,
68
- observed_timestamp: Time.now,
69
- severity_text: nil,
70
- severity_number: nil,
71
- body: nil,
72
- attributes: nil,
73
- trace_id: nil,
74
- span_id: nil,
75
- trace_flags: nil,
76
- context: ::OpenTelemetry::Context.current)
77
- current_span = ::OpenTelemetry::Trace.current_span(context)
78
- span_context = current_span.context unless current_span == ::OpenTelemetry::Trace::Span::INVALID
79
-
80
- @logger_provider.on_emit(timestamp: timestamp,
81
- observed_timestamp: observed_timestamp,
82
- severity_text: severity_text,
83
- severity_number: severity_number,
84
- body: body,
85
- attributes: attributes,
86
- trace_id: trace_id || span_context&.trace_id,
87
- span_id: span_id || span_context&.span_id,
88
- trace_flags: trace_flags || span_context&.trace_flags,
89
- instrumentation_scope: @instrumentation_scope,
90
- context: context)
91
- end
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,170 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module ScoutApm
8
- module Logging
9
- module Loggers
10
- module OpenTelemetry
11
- module SDK
12
- module Logs
13
- # The SDK implementation of OpenTelemetry::Logs::LoggerProvider.
14
- class LoggerProvider < OpenTelemetry::Logs::LoggerProvider
15
- Key = Struct.new(:name, :version)
16
- private_constant(:Key)
17
-
18
- UNEXPECTED_ERROR_MESSAGE = 'unexpected error in ' \
19
- 'OpenTelemetry::SDK::Logs::LoggerProvider#%s'
20
-
21
- private_constant :UNEXPECTED_ERROR_MESSAGE
22
-
23
- # Returns a new LoggerProvider instance.
24
- #
25
- # @param [optional Resource] resource The resource to associate with
26
- # new LogRecords created by {Logger}s created by this LoggerProvider.
27
- # @param [optional LogRecordLimits] log_record_limits The limits for
28
- # attributes count and attribute length for LogRecords.
29
- #
30
- # @return [OpenTelemetry::SDK::Logs::LoggerProvider]
31
- def initialize(resource: OpenTelemetry::SDK::Resources::Resource.create, log_record_limits: LogRecordLimits::DEFAULT)
32
- @log_record_processors = []
33
- @log_record_limits = log_record_limits
34
- @mutex = Mutex.new
35
- @resource = resource
36
- @stopped = false
37
- @registry = {}
38
- @registry_mutex = Mutex.new
39
- end
40
-
41
- # Returns an {OpenTelemetry::SDK::Logs::Logger} instance.
42
- #
43
- # @param [String] name Instrumentation package name
44
- # @param [optional String] version Instrumentation package version
45
- #
46
- # @return [OpenTelemetry::SDK::Logs::Logger]
47
- def logger(name:, version: nil)
48
- version ||= ''
49
-
50
- if !name.is_a?(String) || name.empty?
51
- OpenTelemetry.logger.warn('LoggerProvider#logger called with an ' \
52
- "invalid name. Name provided: #{name.inspect}")
53
- end
54
-
55
- @registry_mutex.synchronize do
56
- @registry[Key.new(name, version)] ||= Logger.new(name, version, self)
57
- end
58
- end
59
-
60
- # Adds a new log record processor to this LoggerProvider's
61
- # log_record_processors.
62
- #
63
- # @param [LogRecordProcessor] log_record_processor The
64
- # {LogRecordProcessor} to add to this LoggerProvider.
65
- def add_log_record_processor(log_record_processor)
66
- @mutex.synchronize do
67
- if @stopped
68
- OpenTelemetry.logger.warn('calling LoggerProvider#' \
69
- 'add_log_record_processor after shutdown.')
70
- return
71
- end
72
- @log_record_processors = @log_record_processors.dup.push(log_record_processor)
73
- end
74
- end
75
-
76
- # Attempts to stop all the activity for this LoggerProvider. Calls
77
- # {LogRecordProcessor#shutdown} for all registered {LogRecordProcessor}s.
78
- #
79
- # This operation may block until all log records are processed. Must
80
- # be called before turning off the main application to ensure all data
81
- # are processed and exported.
82
- #
83
- # After this is called all newly created {LogRecord}s will be no-op.
84
- #
85
- # @param [optional Numeric] timeout An optional timeout in seconds.
86
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
87
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
88
- def shutdown(timeout: nil)
89
- @mutex.synchronize do
90
- if @stopped
91
- OpenTelemetry.logger.warn('LoggerProvider#shutdown called multiple times.')
92
- return Export::FAILURE
93
- end
94
-
95
- start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
96
- results = @log_record_processors.map do |processor|
97
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
98
- break [Export::TIMEOUT] if remaining_timeout&.zero?
99
-
100
- processor.shutdown(timeout: remaining_timeout)
101
- end
102
-
103
- @stopped = true
104
- results.max || Export::SUCCESS
105
- end
106
- end
107
-
108
- # Immediately export all {LogRecord}s that have not yet been exported
109
- # for all the registered {LogRecordProcessor}s.
110
- #
111
- # This method should only be called in cases where it is absolutely
112
- # necessary, such as when using some FaaS providers that may suspend
113
- # the process after an invocation, but before the {LogRecordProcessor}
114
- # exports the completed {LogRecord}s.
115
- #
116
- # @param [optional Numeric] timeout An optional timeout in seconds.
117
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
118
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
119
- def force_flush(timeout: nil)
120
- @mutex.synchronize do
121
- return Export::SUCCESS if @stopped
122
-
123
- start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
124
- results = @log_record_processors.map do |processor|
125
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
126
- return Export::TIMEOUT if remaining_timeout&.zero?
127
-
128
- processor.force_flush(timeout: remaining_timeout)
129
- end
130
-
131
- results.max || Export::SUCCESS
132
- end
133
- end
134
-
135
- # @api private
136
- def on_emit(timestamp: nil,
137
- observed_timestamp: nil,
138
- severity_text: nil,
139
- severity_number: nil,
140
- body: nil,
141
- attributes: nil,
142
- trace_id: nil,
143
- span_id: nil,
144
- trace_flags: nil,
145
- instrumentation_scope: nil,
146
- context: nil)
147
- return if @stopped
148
-
149
- log_record = LogRecord.new(timestamp: timestamp,
150
- observed_timestamp: observed_timestamp,
151
- severity_text: severity_text,
152
- severity_number: severity_number,
153
- body: body,
154
- attributes: attributes,
155
- trace_id: trace_id,
156
- span_id: span_id,
157
- trace_flags: trace_flags,
158
- resource: @resource,
159
- instrumentation_scope: instrumentation_scope,
160
- log_record_limits: @log_record_limits)
161
-
162
- @log_record_processors.each { |processor| processor.on_emit(log_record, context) }
163
- end
164
- end
165
- end
166
- end
167
- end
168
- end
169
- end
170
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module ScoutApm
8
- module Logging
9
- module Loggers
10
- module OpenTelemetry
11
- module SDK
12
- module Logs
13
- # Current OpenTelemetry logs sdk version
14
- VERSION = '0.2.0'
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require_relative 'logs/version'
8
- require_relative 'logs/logger'
9
- require_relative 'logs/logger_provider'
10
- require_relative 'logs/log_record'
11
- require_relative 'logs/log_record_data'
12
- require_relative 'logs/log_record_processor'
13
- require_relative 'logs/export'
14
- require_relative 'logs/log_record_limits'
15
-
16
- module ScoutApm
17
- module Logging
18
- module Loggers
19
- module OpenTelemetry
20
- module SDK
21
- # The Logs module contains the OpenTelemetry logs reference
22
- # implementation.
23
- module Logs
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end