logstruct 0.0.2 → 0.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -22
- data/README.md +25 -2
- data/lib/log_struct/boot_buffer.rb +28 -0
- data/lib/log_struct/builders/active_job.rb +84 -0
- data/lib/log_struct/concerns/configuration.rb +126 -13
- data/lib/log_struct/concerns/error_handling.rb +3 -7
- data/lib/log_struct/concerns/logging.rb +5 -5
- data/lib/log_struct/config_struct/filters.rb +18 -0
- data/lib/log_struct/config_struct/integrations.rb +16 -12
- data/lib/log_struct/configuration.rb +13 -0
- data/lib/log_struct/enums/event.rb +13 -0
- data/lib/log_struct/enums/log_field.rb +154 -0
- data/lib/log_struct/enums/source.rb +4 -1
- data/lib/log_struct/formatter.rb +29 -17
- data/lib/log_struct/integrations/action_mailer/error_handling.rb +3 -11
- data/lib/log_struct/integrations/action_mailer/event_logging.rb +22 -12
- data/lib/log_struct/integrations/active_job/log_subscriber.rb +52 -48
- data/lib/log_struct/integrations/active_model_serializers.rb +49 -0
- data/lib/log_struct/integrations/active_record.rb +35 -5
- data/lib/log_struct/integrations/active_storage.rb +59 -20
- data/lib/log_struct/integrations/ahoy.rb +54 -0
- data/lib/log_struct/integrations/carrierwave.rb +13 -16
- data/lib/log_struct/integrations/dotenv.rb +278 -0
- data/lib/log_struct/integrations/good_job/log_subscriber.rb +86 -136
- data/lib/log_struct/integrations/good_job/logger.rb +8 -10
- data/lib/log_struct/integrations/good_job.rb +5 -7
- data/lib/log_struct/integrations/host_authorization.rb +25 -4
- data/lib/log_struct/integrations/lograge.rb +20 -14
- data/lib/log_struct/integrations/puma.rb +482 -0
- data/lib/log_struct/integrations/rack_error_handler/middleware.rb +11 -18
- data/lib/log_struct/integrations/shrine.rb +44 -19
- data/lib/log_struct/integrations/sorbet.rb +48 -0
- data/lib/log_struct/integrations.rb +25 -0
- data/lib/log_struct/log/action_mailer/delivered.rb +99 -0
- data/lib/log_struct/log/action_mailer/delivery.rb +99 -0
- data/lib/log_struct/log/action_mailer.rb +30 -45
- data/lib/log_struct/log/active_job/enqueue.rb +125 -0
- data/lib/log_struct/log/active_job/finish.rb +130 -0
- data/lib/log_struct/log/active_job/schedule.rb +125 -0
- data/lib/log_struct/log/active_job/start.rb +130 -0
- data/lib/log_struct/log/active_job.rb +41 -54
- data/lib/log_struct/log/active_model_serializers.rb +94 -0
- data/lib/log_struct/log/active_storage/delete.rb +87 -0
- data/lib/log_struct/log/active_storage/download.rb +103 -0
- data/lib/log_struct/log/active_storage/exist.rb +93 -0
- data/lib/log_struct/log/active_storage/metadata.rb +93 -0
- data/lib/log_struct/log/active_storage/stream.rb +93 -0
- data/lib/log_struct/log/active_storage/upload.rb +118 -0
- data/lib/log_struct/log/active_storage/url.rb +93 -0
- data/lib/log_struct/log/active_storage.rb +32 -68
- data/lib/log_struct/log/ahoy.rb +88 -0
- data/lib/log_struct/log/carrierwave/delete.rb +115 -0
- data/lib/log_struct/log/carrierwave/download.rb +131 -0
- data/lib/log_struct/log/carrierwave/upload.rb +141 -0
- data/lib/log_struct/log/carrierwave.rb +37 -72
- data/lib/log_struct/log/dotenv/load.rb +76 -0
- data/lib/log_struct/log/dotenv/restore.rb +76 -0
- data/lib/log_struct/log/dotenv/save.rb +76 -0
- data/lib/log_struct/log/dotenv/update.rb +76 -0
- data/lib/log_struct/log/dotenv.rb +12 -0
- data/lib/log_struct/log/error.rb +58 -46
- data/lib/log_struct/log/good_job/enqueue.rb +126 -0
- data/lib/log_struct/log/good_job/error.rb +151 -0
- data/lib/log_struct/log/good_job/finish.rb +136 -0
- data/lib/log_struct/log/good_job/log.rb +131 -0
- data/lib/log_struct/log/good_job/schedule.rb +136 -0
- data/lib/log_struct/log/good_job/start.rb +136 -0
- data/lib/log_struct/log/good_job.rb +40 -141
- data/lib/log_struct/log/interfaces/additional_data_field.rb +1 -17
- data/lib/log_struct/log/interfaces/common_fields.rb +1 -39
- data/lib/log_struct/log/interfaces/public_common_fields.rb +4 -0
- data/lib/log_struct/log/interfaces/request_fields.rb +1 -33
- data/lib/log_struct/log/plain.rb +59 -34
- data/lib/log_struct/log/puma/shutdown.rb +80 -0
- data/lib/log_struct/log/puma/start.rb +120 -0
- data/lib/log_struct/log/puma.rb +10 -0
- data/lib/log_struct/log/request.rb +132 -48
- data/lib/log_struct/log/security/blocked_host.rb +141 -0
- data/lib/log_struct/log/security/csrf_violation.rb +131 -0
- data/lib/log_struct/log/security/ip_spoof.rb +141 -0
- data/lib/log_struct/log/security.rb +40 -70
- data/lib/log_struct/log/shared/add_request_fields.rb +1 -26
- data/lib/log_struct/log/shared/merge_additional_data_fields.rb +1 -25
- data/lib/log_struct/log/shared/serialize_common.rb +1 -33
- data/lib/log_struct/log/shared/serialize_common_public.rb +44 -0
- data/lib/log_struct/log/shrine/delete.rb +85 -0
- data/lib/log_struct/log/shrine/download.rb +90 -0
- data/lib/log_struct/log/shrine/exist.rb +90 -0
- data/lib/log_struct/log/shrine/metadata.rb +90 -0
- data/lib/log_struct/log/shrine/upload.rb +105 -0
- data/lib/log_struct/log/shrine.rb +10 -67
- data/lib/log_struct/log/sidekiq.rb +65 -26
- data/lib/log_struct/log/sql.rb +113 -106
- data/lib/log_struct/log.rb +31 -32
- data/lib/log_struct/multi_error_reporter.rb +80 -22
- data/lib/log_struct/param_filters.rb +50 -7
- data/lib/log_struct/rails_boot_banner_silencer.rb +123 -0
- data/lib/log_struct/railtie.rb +71 -0
- data/lib/log_struct/semantic_logger/formatter.rb +4 -2
- data/lib/log_struct/semantic_logger/setup.rb +34 -18
- data/lib/log_struct/shared/interfaces/additional_data_field.rb +22 -0
- data/lib/log_struct/shared/interfaces/common_fields.rb +39 -0
- data/lib/log_struct/shared/interfaces/public_common_fields.rb +29 -0
- data/lib/log_struct/shared/interfaces/request_fields.rb +39 -0
- data/lib/log_struct/shared/shared/add_request_fields.rb +28 -0
- data/lib/log_struct/shared/shared/merge_additional_data_fields.rb +27 -0
- data/lib/log_struct/shared/shared/serialize_common.rb +58 -0
- data/lib/log_struct/version.rb +1 -1
- data/lib/log_struct.rb +22 -4
- data/logstruct.gemspec +3 -0
- metadata +108 -5
- data/lib/log_struct/log/interfaces/message_field.rb +0 -20
- data/lib/log_struct/log_keys.rb +0 -102
@@ -14,11 +14,30 @@ require_relative "integrations/good_job"
|
|
14
14
|
require_relative "integrations/active_storage"
|
15
15
|
require_relative "integrations/carrierwave"
|
16
16
|
require_relative "integrations/sorbet"
|
17
|
+
require_relative "integrations/ahoy"
|
18
|
+
require_relative "integrations/active_model_serializers"
|
19
|
+
require_relative "integrations/dotenv"
|
20
|
+
require_relative "integrations/puma"
|
17
21
|
|
18
22
|
module LogStruct
|
19
23
|
module Integrations
|
20
24
|
extend T::Sig
|
21
25
|
|
26
|
+
# Register generic initializers on the Railtie to keep integration
|
27
|
+
# wiring centralized (boot replay interception and resolution).
|
28
|
+
sig { params(railtie: T.untyped).void }
|
29
|
+
def self.setup_initializers(railtie)
|
30
|
+
# Intercept any boot-time replays (e.g., dotenv) before those railties run
|
31
|
+
railtie.initializer "logstruct.intercept_boot_replays", before: "dotenv" do
|
32
|
+
LogStruct::Integrations::Dotenv.intercept_logger_setter!
|
33
|
+
end
|
34
|
+
|
35
|
+
# Decide which set of boot logs to emit after user initializers
|
36
|
+
railtie.initializer "logstruct.resolve_boot_logs", after: :load_config_initializers do
|
37
|
+
LogStruct::Integrations::Dotenv.resolve_boot_logs!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
22
41
|
sig { void }
|
23
42
|
def self.setup_integrations
|
24
43
|
config = LogStruct.config
|
@@ -30,12 +49,18 @@ module LogStruct
|
|
30
49
|
Integrations::ActiveRecord.setup(config) if config.integrations.enable_sql_logging
|
31
50
|
Integrations::Sidekiq.setup(config) if config.integrations.enable_sidekiq
|
32
51
|
Integrations::GoodJob.setup(config) if config.integrations.enable_goodjob
|
52
|
+
Integrations::Ahoy.setup(config) if config.integrations.enable_ahoy
|
53
|
+
Integrations::ActiveModelSerializers.setup(config) if config.integrations.enable_active_model_serializers
|
33
54
|
Integrations::HostAuthorization.setup(config) if config.integrations.enable_host_authorization
|
34
55
|
Integrations::RackErrorHandler.setup(config) if config.integrations.enable_rack_error_handler
|
35
56
|
Integrations::Shrine.setup(config) if config.integrations.enable_shrine
|
36
57
|
Integrations::ActiveStorage.setup(config) if config.integrations.enable_activestorage
|
37
58
|
Integrations::CarrierWave.setup(config) if config.integrations.enable_carrierwave
|
38
59
|
Integrations::Sorbet.setup(config) if config.integrations.enable_sorbet_error_handlers
|
60
|
+
if config.enabled && config.integrations.enable_dotenv
|
61
|
+
Integrations::Dotenv.setup(config)
|
62
|
+
end
|
63
|
+
Integrations::Puma.setup(config) if config.integrations.enable_puma
|
39
64
|
end
|
40
65
|
end
|
41
66
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# AUTO-GENERATED: DO NOT EDIT
|
5
|
+
# Generated by scripts/generate_structs.rb
|
6
|
+
# Schemas dir: schemas/log_sources/
|
7
|
+
# Template: tools/codegen/templates/sorbet/event.rb.erb
|
8
|
+
|
9
|
+
require "log_struct/shared/interfaces/common_fields"
|
10
|
+
require "log_struct/shared/interfaces/additional_data_field"
|
11
|
+
require "log_struct/shared/interfaces/request_fields"
|
12
|
+
require "log_struct/shared/shared/serialize_common"
|
13
|
+
require "log_struct/shared/shared/merge_additional_data_fields"
|
14
|
+
require "log_struct/shared/shared/add_request_fields"
|
15
|
+
require_relative "../../enums/source"
|
16
|
+
require_relative "../../enums/event"
|
17
|
+
require_relative "../../enums/level"
|
18
|
+
require_relative "../../enums/log_field"
|
19
|
+
|
20
|
+
module LogStruct
|
21
|
+
module Log
|
22
|
+
class ActionMailer
|
23
|
+
class Delivered < T::Struct
|
24
|
+
# typed: strict
|
25
|
+
# frozen_string_literal: true
|
26
|
+
|
27
|
+
extend T::Sig
|
28
|
+
|
29
|
+
extend T::Sig
|
30
|
+
|
31
|
+
# Shared/common fields
|
32
|
+
const :source, Source::Mailer, default: Source::Mailer
|
33
|
+
const :event, Event, default: Event::Delivered
|
34
|
+
const :timestamp, Time, factory: -> { Time.now }
|
35
|
+
const :level, Level, default: Level::Info
|
36
|
+
|
37
|
+
const :to, T.nilable(T::Array[String]), default: nil
|
38
|
+
const :from, T.nilable(String), default: nil
|
39
|
+
const :subject, T.nilable(String), default: nil
|
40
|
+
|
41
|
+
# Event-specific fields
|
42
|
+
|
43
|
+
# Additional data
|
44
|
+
include LogStruct::Log::Interfaces::AdditionalDataField
|
45
|
+
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
|
46
|
+
include LogStruct::Log::Shared::MergeAdditionalDataFields
|
47
|
+
|
48
|
+
# Request fields (optional)
|
49
|
+
|
50
|
+
# Serialize shared fields
|
51
|
+
include LogStruct::Log::Interfaces::CommonFields
|
52
|
+
include LogStruct::Log::Shared::SerializeCommon
|
53
|
+
|
54
|
+
sig {
|
55
|
+
params(to: T.untyped,
|
56
|
+
from: T.untyped,
|
57
|
+
subject: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
58
|
+
}
|
59
|
+
def self.base_hash(to: nil,
|
60
|
+
from: nil,
|
61
|
+
subject: nil)
|
62
|
+
h = {}
|
63
|
+
h[LogField::To] = to unless to.nil?
|
64
|
+
h[LogField::From] = from unless from.nil?
|
65
|
+
h[LogField::Subject] = subject unless subject.nil?
|
66
|
+
h
|
67
|
+
end
|
68
|
+
|
69
|
+
sig {
|
70
|
+
params(to: T.untyped,
|
71
|
+
from: T.untyped,
|
72
|
+
subject: T.untyped,
|
73
|
+
additional_data: T.untyped,
|
74
|
+
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
75
|
+
}
|
76
|
+
def self.build(to: nil,
|
77
|
+
from: nil,
|
78
|
+
subject: nil,
|
79
|
+
additional_data: nil,
|
80
|
+
timestamp: Time.now)
|
81
|
+
base_hash(to: to,
|
82
|
+
from: from,
|
83
|
+
subject: subject)
|
84
|
+
end
|
85
|
+
|
86
|
+
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
87
|
+
def to_h
|
88
|
+
self.class.build(
|
89
|
+
to: to,
|
90
|
+
from: from,
|
91
|
+
subject: subject,
|
92
|
+
additional_data: additional_data,
|
93
|
+
timestamp: timestamp
|
94
|
+
)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# AUTO-GENERATED: DO NOT EDIT
|
5
|
+
# Generated by scripts/generate_structs.rb
|
6
|
+
# Schemas dir: schemas/log_sources/
|
7
|
+
# Template: tools/codegen/templates/sorbet/event.rb.erb
|
8
|
+
|
9
|
+
require "log_struct/shared/interfaces/common_fields"
|
10
|
+
require "log_struct/shared/interfaces/additional_data_field"
|
11
|
+
require "log_struct/shared/interfaces/request_fields"
|
12
|
+
require "log_struct/shared/shared/serialize_common"
|
13
|
+
require "log_struct/shared/shared/merge_additional_data_fields"
|
14
|
+
require "log_struct/shared/shared/add_request_fields"
|
15
|
+
require_relative "../../enums/source"
|
16
|
+
require_relative "../../enums/event"
|
17
|
+
require_relative "../../enums/level"
|
18
|
+
require_relative "../../enums/log_field"
|
19
|
+
|
20
|
+
module LogStruct
|
21
|
+
module Log
|
22
|
+
class ActionMailer
|
23
|
+
class Delivery < T::Struct
|
24
|
+
# typed: strict
|
25
|
+
# frozen_string_literal: true
|
26
|
+
|
27
|
+
extend T::Sig
|
28
|
+
|
29
|
+
extend T::Sig
|
30
|
+
|
31
|
+
# Shared/common fields
|
32
|
+
const :source, Source::Mailer, default: Source::Mailer
|
33
|
+
const :event, Event, default: Event::Delivery
|
34
|
+
const :timestamp, Time, factory: -> { Time.now }
|
35
|
+
const :level, Level, default: Level::Info
|
36
|
+
|
37
|
+
const :to, T.nilable(T::Array[String]), default: nil
|
38
|
+
const :from, T.nilable(String), default: nil
|
39
|
+
const :subject, T.nilable(String), default: nil
|
40
|
+
|
41
|
+
# Event-specific fields
|
42
|
+
|
43
|
+
# Additional data
|
44
|
+
include LogStruct::Log::Interfaces::AdditionalDataField
|
45
|
+
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
|
46
|
+
include LogStruct::Log::Shared::MergeAdditionalDataFields
|
47
|
+
|
48
|
+
# Request fields (optional)
|
49
|
+
|
50
|
+
# Serialize shared fields
|
51
|
+
include LogStruct::Log::Interfaces::CommonFields
|
52
|
+
include LogStruct::Log::Shared::SerializeCommon
|
53
|
+
|
54
|
+
sig {
|
55
|
+
params(to: T.untyped,
|
56
|
+
from: T.untyped,
|
57
|
+
subject: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
58
|
+
}
|
59
|
+
def self.base_hash(to: nil,
|
60
|
+
from: nil,
|
61
|
+
subject: nil)
|
62
|
+
h = {}
|
63
|
+
h[LogField::To] = to unless to.nil?
|
64
|
+
h[LogField::From] = from unless from.nil?
|
65
|
+
h[LogField::Subject] = subject unless subject.nil?
|
66
|
+
h
|
67
|
+
end
|
68
|
+
|
69
|
+
sig {
|
70
|
+
params(to: T.untyped,
|
71
|
+
from: T.untyped,
|
72
|
+
subject: T.untyped,
|
73
|
+
additional_data: T.untyped,
|
74
|
+
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
75
|
+
}
|
76
|
+
def self.build(to: nil,
|
77
|
+
from: nil,
|
78
|
+
subject: nil,
|
79
|
+
additional_data: nil,
|
80
|
+
timestamp: Time.now)
|
81
|
+
base_hash(to: to,
|
82
|
+
from: from,
|
83
|
+
subject: subject)
|
84
|
+
end
|
85
|
+
|
86
|
+
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
87
|
+
def to_h
|
88
|
+
self.class.build(
|
89
|
+
to: to,
|
90
|
+
from: from,
|
91
|
+
subject: subject,
|
92
|
+
additional_data: additional_data,
|
93
|
+
timestamp: timestamp
|
94
|
+
)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -1,54 +1,39 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
require_relative "
|
10
|
-
require_relative "
|
11
|
-
require_relative "../log_keys"
|
4
|
+
# AUTO-GENERATED: DO NOT EDIT
|
5
|
+
# Generated by scripts/generate_structs.rb
|
6
|
+
# Schemas dir: schemas/log_sources/
|
7
|
+
# Template: tools/codegen/templates/sorbet/source_parent.rb.erb
|
8
|
+
|
9
|
+
require_relative "action_mailer/delivery"
|
10
|
+
require_relative "action_mailer/delivered"
|
12
11
|
|
13
12
|
module LogStruct
|
14
13
|
module Log
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
const :additional_data, T::Hash[Symbol, T.untyped], default: {}
|
39
|
-
|
40
|
-
# Convert the log entry to a hash for serialization
|
41
|
-
sig { override.params(strict: T::Boolean).returns(T::Hash[Symbol, T.untyped]) }
|
42
|
-
def serialize(strict = true)
|
43
|
-
hash = serialize_common(strict)
|
44
|
-
merge_additional_data_fields(hash)
|
45
|
-
|
46
|
-
# Add email-specific fields if they're present
|
47
|
-
hash[LOG_KEYS.fetch(:to)] = to if to
|
48
|
-
hash[LOG_KEYS.fetch(:from)] = from if from
|
49
|
-
hash[LOG_KEYS.fetch(:subject)] = subject if subject
|
50
|
-
|
51
|
-
hash
|
14
|
+
class ActionMailer
|
15
|
+
class BaseFields < T::Struct
|
16
|
+
extend T::Sig
|
17
|
+
const :to, T.nilable(T::Array[String]), default: nil
|
18
|
+
const :from, T.nilable(String), default: nil
|
19
|
+
const :subject, T.nilable(String), default: nil
|
20
|
+
|
21
|
+
Kwargs = T.type_alias do
|
22
|
+
{
|
23
|
+
to: T.nilable(T::Array[String]),
|
24
|
+
from: T.nilable(String),
|
25
|
+
subject: T.nilable(String)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
sig { returns(Kwargs) }
|
30
|
+
def to_kwargs
|
31
|
+
{
|
32
|
+
to: to,
|
33
|
+
from: from,
|
34
|
+
subject: subject
|
35
|
+
}
|
36
|
+
end
|
52
37
|
end
|
53
38
|
end
|
54
39
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# AUTO-GENERATED: DO NOT EDIT
|
5
|
+
# Generated by scripts/generate_structs.rb
|
6
|
+
# Schemas dir: schemas/log_sources/
|
7
|
+
# Template: tools/codegen/templates/sorbet/event.rb.erb
|
8
|
+
|
9
|
+
require "log_struct/shared/interfaces/common_fields"
|
10
|
+
require "log_struct/shared/interfaces/additional_data_field"
|
11
|
+
require "log_struct/shared/interfaces/request_fields"
|
12
|
+
require "log_struct/shared/shared/serialize_common"
|
13
|
+
require "log_struct/shared/shared/merge_additional_data_fields"
|
14
|
+
require "log_struct/shared/shared/add_request_fields"
|
15
|
+
require_relative "../../enums/source"
|
16
|
+
require_relative "../../enums/event"
|
17
|
+
require_relative "../../enums/level"
|
18
|
+
require_relative "../../enums/log_field"
|
19
|
+
|
20
|
+
module LogStruct
|
21
|
+
module Log
|
22
|
+
class ActiveJob
|
23
|
+
class Enqueue < T::Struct
|
24
|
+
# typed: strict
|
25
|
+
# frozen_string_literal: true
|
26
|
+
|
27
|
+
extend T::Sig
|
28
|
+
|
29
|
+
extend T::Sig
|
30
|
+
|
31
|
+
# Shared/common fields
|
32
|
+
const :source, Source::Job, default: Source::Job
|
33
|
+
const :event, Event, default: Event::Enqueue
|
34
|
+
const :timestamp, Time, factory: -> { Time.now }
|
35
|
+
const :level, Level, default: Level::Info
|
36
|
+
|
37
|
+
const :job_id, String
|
38
|
+
const :job_class, String
|
39
|
+
const :queue_name, T.nilable(String), default: nil
|
40
|
+
const :arguments, T.nilable(T::Array[T.untyped]), default: nil
|
41
|
+
const :executions, T.nilable(Integer), default: nil
|
42
|
+
const :provider_job_id, T.nilable(String), default: nil
|
43
|
+
|
44
|
+
# Event-specific fields
|
45
|
+
const :retries, T.nilable(Integer), default: nil
|
46
|
+
|
47
|
+
# Additional data
|
48
|
+
|
49
|
+
# Request fields (optional)
|
50
|
+
|
51
|
+
# Serialize shared fields
|
52
|
+
include LogStruct::Log::Interfaces::CommonFields
|
53
|
+
include LogStruct::Log::Shared::SerializeCommon
|
54
|
+
|
55
|
+
sig {
|
56
|
+
params(job_id: T.untyped,
|
57
|
+
job_class: T.untyped,
|
58
|
+
queue_name: T.untyped,
|
59
|
+
arguments: T.untyped,
|
60
|
+
executions: T.untyped,
|
61
|
+
provider_job_id: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
62
|
+
}
|
63
|
+
def self.base_hash(job_id: nil,
|
64
|
+
job_class: nil,
|
65
|
+
queue_name: nil,
|
66
|
+
arguments: nil,
|
67
|
+
executions: nil,
|
68
|
+
provider_job_id: nil)
|
69
|
+
h = {}
|
70
|
+
h[LogField::JobId] = job_id unless job_id.nil?
|
71
|
+
h[LogField::JobClass] = job_class unless job_class.nil?
|
72
|
+
h[LogField::QueueName] = queue_name unless queue_name.nil?
|
73
|
+
h[LogField::Arguments] = arguments unless arguments.nil?
|
74
|
+
h[LogField::Executions] = executions unless executions.nil?
|
75
|
+
h[LogField::ProviderJobId] = provider_job_id unless provider_job_id.nil?
|
76
|
+
h
|
77
|
+
end
|
78
|
+
|
79
|
+
sig {
|
80
|
+
params(job_id: T.untyped,
|
81
|
+
job_class: T.untyped,
|
82
|
+
queue_name: T.untyped,
|
83
|
+
arguments: T.untyped,
|
84
|
+
executions: T.untyped,
|
85
|
+
provider_job_id: T.untyped,
|
86
|
+
retries: T.untyped,
|
87
|
+
additional_data: T.untyped,
|
88
|
+
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
89
|
+
}
|
90
|
+
def self.build(job_id:,
|
91
|
+
job_class:,
|
92
|
+
queue_name: nil,
|
93
|
+
arguments: nil,
|
94
|
+
executions: nil,
|
95
|
+
provider_job_id: nil,
|
96
|
+
retries: nil,
|
97
|
+
additional_data: nil,
|
98
|
+
timestamp: Time.now)
|
99
|
+
h = base_hash(job_id: job_id,
|
100
|
+
job_class: job_class,
|
101
|
+
queue_name: queue_name,
|
102
|
+
arguments: arguments,
|
103
|
+
executions: executions,
|
104
|
+
provider_job_id: provider_job_id)
|
105
|
+
h[LogField::Retries] = retries unless retries.nil?
|
106
|
+
h
|
107
|
+
end
|
108
|
+
|
109
|
+
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
110
|
+
def to_h
|
111
|
+
self.class.build(
|
112
|
+
job_id: job_id,
|
113
|
+
job_class: job_class,
|
114
|
+
queue_name: queue_name,
|
115
|
+
arguments: arguments,
|
116
|
+
executions: executions,
|
117
|
+
provider_job_id: provider_job_id,
|
118
|
+
retries: retries,
|
119
|
+
timestamp: timestamp
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# AUTO-GENERATED: DO NOT EDIT
|
5
|
+
# Generated by scripts/generate_structs.rb
|
6
|
+
# Schemas dir: schemas/log_sources/
|
7
|
+
# Template: tools/codegen/templates/sorbet/event.rb.erb
|
8
|
+
|
9
|
+
require "log_struct/shared/interfaces/common_fields"
|
10
|
+
require "log_struct/shared/interfaces/additional_data_field"
|
11
|
+
require "log_struct/shared/interfaces/request_fields"
|
12
|
+
require "log_struct/shared/shared/serialize_common"
|
13
|
+
require "log_struct/shared/shared/merge_additional_data_fields"
|
14
|
+
require "log_struct/shared/shared/add_request_fields"
|
15
|
+
require_relative "../../enums/source"
|
16
|
+
require_relative "../../enums/event"
|
17
|
+
require_relative "../../enums/level"
|
18
|
+
require_relative "../../enums/log_field"
|
19
|
+
|
20
|
+
module LogStruct
|
21
|
+
module Log
|
22
|
+
class ActiveJob
|
23
|
+
class Finish < T::Struct
|
24
|
+
# typed: strict
|
25
|
+
# frozen_string_literal: true
|
26
|
+
|
27
|
+
extend T::Sig
|
28
|
+
|
29
|
+
extend T::Sig
|
30
|
+
|
31
|
+
# Shared/common fields
|
32
|
+
const :source, Source::Job, default: Source::Job
|
33
|
+
const :event, Event, default: Event::Finish
|
34
|
+
const :timestamp, Time, factory: -> { Time.now }
|
35
|
+
const :level, Level, default: Level::Info
|
36
|
+
|
37
|
+
const :job_id, String
|
38
|
+
const :job_class, String
|
39
|
+
const :queue_name, T.nilable(String), default: nil
|
40
|
+
const :arguments, T.nilable(T::Array[T.untyped]), default: nil
|
41
|
+
const :executions, T.nilable(Integer), default: nil
|
42
|
+
const :provider_job_id, T.nilable(String), default: nil
|
43
|
+
|
44
|
+
# Event-specific fields
|
45
|
+
const :duration_ms, Float
|
46
|
+
const :finished_at, Time
|
47
|
+
|
48
|
+
# Additional data
|
49
|
+
|
50
|
+
# Request fields (optional)
|
51
|
+
|
52
|
+
# Serialize shared fields
|
53
|
+
include LogStruct::Log::Interfaces::CommonFields
|
54
|
+
include LogStruct::Log::Shared::SerializeCommon
|
55
|
+
|
56
|
+
sig {
|
57
|
+
params(job_id: T.untyped,
|
58
|
+
job_class: T.untyped,
|
59
|
+
queue_name: T.untyped,
|
60
|
+
arguments: T.untyped,
|
61
|
+
executions: T.untyped,
|
62
|
+
provider_job_id: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
63
|
+
}
|
64
|
+
def self.base_hash(job_id: nil,
|
65
|
+
job_class: nil,
|
66
|
+
queue_name: nil,
|
67
|
+
arguments: nil,
|
68
|
+
executions: nil,
|
69
|
+
provider_job_id: nil)
|
70
|
+
h = {}
|
71
|
+
h[LogField::JobId] = job_id unless job_id.nil?
|
72
|
+
h[LogField::JobClass] = job_class unless job_class.nil?
|
73
|
+
h[LogField::QueueName] = queue_name unless queue_name.nil?
|
74
|
+
h[LogField::Arguments] = arguments unless arguments.nil?
|
75
|
+
h[LogField::Executions] = executions unless executions.nil?
|
76
|
+
h[LogField::ProviderJobId] = provider_job_id unless provider_job_id.nil?
|
77
|
+
h
|
78
|
+
end
|
79
|
+
|
80
|
+
sig {
|
81
|
+
params(duration_ms: T.untyped,
|
82
|
+
finished_at: T.untyped,
|
83
|
+
job_id: T.untyped,
|
84
|
+
job_class: T.untyped,
|
85
|
+
queue_name: T.untyped,
|
86
|
+
arguments: T.untyped,
|
87
|
+
executions: T.untyped,
|
88
|
+
provider_job_id: T.untyped,
|
89
|
+
additional_data: T.untyped,
|
90
|
+
timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
|
91
|
+
}
|
92
|
+
def self.build(duration_ms:,
|
93
|
+
finished_at:,
|
94
|
+
job_id:,
|
95
|
+
job_class:,
|
96
|
+
queue_name: nil,
|
97
|
+
arguments: nil,
|
98
|
+
executions: nil,
|
99
|
+
provider_job_id: nil,
|
100
|
+
additional_data: nil,
|
101
|
+
timestamp: Time.now)
|
102
|
+
h = base_hash(job_id: job_id,
|
103
|
+
job_class: job_class,
|
104
|
+
queue_name: queue_name,
|
105
|
+
arguments: arguments,
|
106
|
+
executions: executions,
|
107
|
+
provider_job_id: provider_job_id)
|
108
|
+
h[LogField::DurationMs] = duration_ms
|
109
|
+
h[LogField::FinishedAt] = finished_at
|
110
|
+
h
|
111
|
+
end
|
112
|
+
|
113
|
+
sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
|
114
|
+
def to_h
|
115
|
+
self.class.build(
|
116
|
+
job_id: job_id,
|
117
|
+
job_class: job_class,
|
118
|
+
queue_name: queue_name,
|
119
|
+
arguments: arguments,
|
120
|
+
executions: executions,
|
121
|
+
provider_job_id: provider_job_id,
|
122
|
+
duration_ms: duration_ms,
|
123
|
+
finished_at: finished_at,
|
124
|
+
timestamp: timestamp
|
125
|
+
)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|