opentelemetry-logs-sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +201 -0
- data/lib/opentelemetry/sdk/logs/configuration_patch.rb +71 -0
- data/lib/opentelemetry/sdk/logs/export/batch_log_record_processor.rb +218 -0
- data/lib/opentelemetry/sdk/logs/export/console_log_record_exporter.rb +39 -0
- data/lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb +104 -0
- data/lib/opentelemetry/sdk/logs/export/log_record_exporter.rb +58 -0
- data/lib/opentelemetry/sdk/logs/export/simple_log_record_processor.rb +88 -0
- data/lib/opentelemetry/sdk/logs/export.rb +31 -0
- data/lib/opentelemetry/sdk/logs/log_record.rb +164 -0
- data/lib/opentelemetry/sdk/logs/log_record_data.rb +25 -0
- data/lib/opentelemetry/sdk/logs/log_record_limits.rb +43 -0
- data/lib/opentelemetry/sdk/logs/log_record_processor.rb +47 -0
- data/lib/opentelemetry/sdk/logs/logger.rb +92 -0
- data/lib/opentelemetry/sdk/logs/logger_provider.rb +164 -0
- data/lib/opentelemetry/sdk/logs/version.rb +14 -0
- data/lib/opentelemetry/sdk/logs.rb +24 -0
- data/lib/opentelemetry-logs-sdk.rb +9 -0
- metadata +220 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module SDK
|
9
|
+
module Logs
|
10
|
+
# The SDK implementation of OpenTelemetry::Logs::LoggerProvider.
|
11
|
+
class LoggerProvider < OpenTelemetry::Logs::LoggerProvider
|
12
|
+
Key = Struct.new(:name, :version)
|
13
|
+
private_constant(:Key)
|
14
|
+
|
15
|
+
UNEXPECTED_ERROR_MESSAGE = 'unexpected error in ' \
|
16
|
+
'OpenTelemetry::SDK::Logs::LoggerProvider#%s'
|
17
|
+
|
18
|
+
private_constant :UNEXPECTED_ERROR_MESSAGE
|
19
|
+
|
20
|
+
# Returns a new LoggerProvider instance.
|
21
|
+
#
|
22
|
+
# @param [optional Resource] resource The resource to associate with
|
23
|
+
# new LogRecords created by {Logger}s created by this LoggerProvider.
|
24
|
+
# @param [optional LogRecordLimits] log_record_limits The limits for
|
25
|
+
# attributes count and attribute length for LogRecords.
|
26
|
+
#
|
27
|
+
# @return [OpenTelemetry::SDK::Logs::LoggerProvider]
|
28
|
+
def initialize(resource: OpenTelemetry::SDK::Resources::Resource.create, log_record_limits: LogRecordLimits::DEFAULT)
|
29
|
+
@log_record_processors = []
|
30
|
+
@log_record_limits = log_record_limits
|
31
|
+
@mutex = Mutex.new
|
32
|
+
@resource = resource
|
33
|
+
@stopped = false
|
34
|
+
@registry = {}
|
35
|
+
@registry_mutex = Mutex.new
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns an {OpenTelemetry::SDK::Logs::Logger} instance.
|
39
|
+
#
|
40
|
+
# @param [String] name Instrumentation package name
|
41
|
+
# @param [optional String] version Instrumentation package version
|
42
|
+
#
|
43
|
+
# @return [OpenTelemetry::SDK::Logs::Logger]
|
44
|
+
def logger(name:, version: nil)
|
45
|
+
version ||= ''
|
46
|
+
|
47
|
+
if !name.is_a?(String) || name.empty?
|
48
|
+
OpenTelemetry.logger.warn('LoggerProvider#logger called with an ' \
|
49
|
+
"invalid name. Name provided: #{name.inspect}")
|
50
|
+
end
|
51
|
+
|
52
|
+
@registry_mutex.synchronize do
|
53
|
+
@registry[Key.new(name, version)] ||= Logger.new(name, version, self)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Adds a new log record processor to this LoggerProvider's
|
58
|
+
# log_record_processors.
|
59
|
+
#
|
60
|
+
# @param [LogRecordProcessor] log_record_processor The
|
61
|
+
# {LogRecordProcessor} to add to this LoggerProvider.
|
62
|
+
def add_log_record_processor(log_record_processor)
|
63
|
+
@mutex.synchronize do
|
64
|
+
if @stopped
|
65
|
+
OpenTelemetry.logger.warn('calling LoggerProvider#' \
|
66
|
+
'add_log_record_processor after shutdown.')
|
67
|
+
return
|
68
|
+
end
|
69
|
+
@log_record_processors = @log_record_processors.dup.push(log_record_processor)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Attempts to stop all the activity for this LoggerProvider. Calls
|
74
|
+
# {LogRecordProcessor#shutdown} for all registered {LogRecordProcessor}s.
|
75
|
+
#
|
76
|
+
# This operation may block until all log records are processed. Must
|
77
|
+
# be called before turning off the main application to ensure all data
|
78
|
+
# are processed and exported.
|
79
|
+
#
|
80
|
+
# After this is called all newly created {LogRecord}s will be no-op.
|
81
|
+
#
|
82
|
+
# @param [optional Numeric] timeout An optional timeout in seconds.
|
83
|
+
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
|
84
|
+
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
|
85
|
+
def shutdown(timeout: nil)
|
86
|
+
@mutex.synchronize do
|
87
|
+
if @stopped
|
88
|
+
OpenTelemetry.logger.warn('LoggerProvider#shutdown called multiple times.')
|
89
|
+
return Export::FAILURE
|
90
|
+
end
|
91
|
+
|
92
|
+
start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
|
93
|
+
results = @log_record_processors.map do |processor|
|
94
|
+
remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
|
95
|
+
break [Export::TIMEOUT] if remaining_timeout&.zero?
|
96
|
+
|
97
|
+
processor.shutdown(timeout: remaining_timeout)
|
98
|
+
end
|
99
|
+
|
100
|
+
@stopped = true
|
101
|
+
results.max || Export::SUCCESS
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Immediately export all {LogRecord}s that have not yet been exported
|
106
|
+
# for all the registered {LogRecordProcessor}s.
|
107
|
+
#
|
108
|
+
# This method should only be called in cases where it is absolutely
|
109
|
+
# necessary, such as when using some FaaS providers that may suspend
|
110
|
+
# the process after an invocation, but before the {LogRecordProcessor}
|
111
|
+
# exports the completed {LogRecord}s.
|
112
|
+
#
|
113
|
+
# @param [optional Numeric] timeout An optional timeout in seconds.
|
114
|
+
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
|
115
|
+
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
|
116
|
+
def force_flush(timeout: nil)
|
117
|
+
@mutex.synchronize do
|
118
|
+
return Export::SUCCESS if @stopped
|
119
|
+
|
120
|
+
start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
|
121
|
+
results = @log_record_processors.map do |processor|
|
122
|
+
remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
|
123
|
+
return Export::TIMEOUT if remaining_timeout&.zero?
|
124
|
+
|
125
|
+
processor.force_flush(timeout: remaining_timeout)
|
126
|
+
end
|
127
|
+
|
128
|
+
results.max || Export::SUCCESS
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# @api private
|
133
|
+
def on_emit(timestamp: nil,
|
134
|
+
observed_timestamp: nil,
|
135
|
+
severity_text: nil,
|
136
|
+
severity_number: nil,
|
137
|
+
body: nil,
|
138
|
+
attributes: nil,
|
139
|
+
trace_id: nil,
|
140
|
+
span_id: nil,
|
141
|
+
trace_flags: nil,
|
142
|
+
instrumentation_scope: nil,
|
143
|
+
context: nil)
|
144
|
+
return if @stopped
|
145
|
+
|
146
|
+
log_record = LogRecord.new(timestamp: timestamp,
|
147
|
+
observed_timestamp: observed_timestamp,
|
148
|
+
severity_text: severity_text,
|
149
|
+
severity_number: severity_number,
|
150
|
+
body: body,
|
151
|
+
attributes: attributes,
|
152
|
+
trace_id: trace_id,
|
153
|
+
span_id: span_id,
|
154
|
+
trace_flags: trace_flags,
|
155
|
+
resource: @resource,
|
156
|
+
instrumentation_scope: instrumentation_scope,
|
157
|
+
log_record_limits: @log_record_limits)
|
158
|
+
|
159
|
+
@log_record_processors.each { |processor| processor.on_emit(log_record, context) }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module SDK
|
9
|
+
module Logs
|
10
|
+
# Current OpenTelemetry logs sdk version
|
11
|
+
VERSION = '0.1.0'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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/configuration_patch'
|
9
|
+
require_relative 'logs/logger'
|
10
|
+
require_relative 'logs/logger_provider'
|
11
|
+
require_relative 'logs/log_record'
|
12
|
+
require_relative 'logs/log_record_data'
|
13
|
+
require_relative 'logs/log_record_processor'
|
14
|
+
require_relative 'logs/export'
|
15
|
+
require_relative 'logs/log_record_limits'
|
16
|
+
|
17
|
+
module OpenTelemetry
|
18
|
+
module SDK
|
19
|
+
# The Logs module contains the OpenTelemetry logs reference
|
20
|
+
# implementation.
|
21
|
+
module Logs
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opentelemetry-logs-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OpenTelemetry Authors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: opentelemetry-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: opentelemetry-logs-api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opentelemetry-sdk
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.17'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.19'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.19'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: opentelemetry-test-helpers
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '13.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '13.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.65'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.65'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.22'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.22'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.9'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.9'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: yard-doctest
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.1.17
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.1.17
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- cncf-opentelemetry-contributors@lists.cncf.io
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".yardopts"
|
175
|
+
- CHANGELOG.md
|
176
|
+
- LICENSE
|
177
|
+
- lib/opentelemetry-logs-sdk.rb
|
178
|
+
- lib/opentelemetry/sdk/logs.rb
|
179
|
+
- lib/opentelemetry/sdk/logs/configuration_patch.rb
|
180
|
+
- lib/opentelemetry/sdk/logs/export.rb
|
181
|
+
- lib/opentelemetry/sdk/logs/export/batch_log_record_processor.rb
|
182
|
+
- lib/opentelemetry/sdk/logs/export/console_log_record_exporter.rb
|
183
|
+
- lib/opentelemetry/sdk/logs/export/in_memory_log_record_exporter.rb
|
184
|
+
- lib/opentelemetry/sdk/logs/export/log_record_exporter.rb
|
185
|
+
- lib/opentelemetry/sdk/logs/export/simple_log_record_processor.rb
|
186
|
+
- lib/opentelemetry/sdk/logs/log_record.rb
|
187
|
+
- lib/opentelemetry/sdk/logs/log_record_data.rb
|
188
|
+
- lib/opentelemetry/sdk/logs/log_record_limits.rb
|
189
|
+
- lib/opentelemetry/sdk/logs/log_record_processor.rb
|
190
|
+
- lib/opentelemetry/sdk/logs/logger.rb
|
191
|
+
- lib/opentelemetry/sdk/logs/logger_provider.rb
|
192
|
+
- lib/opentelemetry/sdk/logs/version.rb
|
193
|
+
homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
194
|
+
licenses:
|
195
|
+
- Apache-2.0
|
196
|
+
metadata:
|
197
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-logs-sdk/v0.1.0/file.CHANGELOG.html
|
198
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/logs_sdk
|
199
|
+
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
200
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-logs-sdk/v0.1.0
|
201
|
+
post_install_message:
|
202
|
+
rdoc_options: []
|
203
|
+
require_paths:
|
204
|
+
- lib
|
205
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '3.0'
|
210
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
requirements: []
|
216
|
+
rubygems_version: 3.2.33
|
217
|
+
signing_key:
|
218
|
+
specification_version: 4
|
219
|
+
summary: Logs SDK implementation for OpenTelemetry
|
220
|
+
test_files: []
|