google-cloud-logging 1.5.7 → 1.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/CONTRIBUTING.md +1 -1
- data/lib/google-cloud-logging.rb +7 -5
- data/lib/google/cloud/logging.rb +22 -8
- data/lib/google/cloud/logging/async_writer.rb +308 -187
- data/lib/google/cloud/logging/convert.rb +15 -9
- data/lib/google/cloud/logging/entry.rb +43 -13
- data/lib/google/cloud/logging/entry/source_location.rb +3 -3
- data/lib/google/cloud/logging/errors.rb +101 -0
- data/lib/google/cloud/logging/log/list.rb +1 -1
- data/lib/google/cloud/logging/logger.rb +6 -4
- data/lib/google/cloud/logging/middleware.rb +24 -11
- data/lib/google/cloud/logging/project.rb +38 -15
- data/lib/google/cloud/logging/rails.rb +56 -5
- data/lib/google/cloud/logging/resource.rb +1 -1
- data/lib/google/cloud/logging/service.rb +42 -32
- data/lib/google/cloud/logging/v2/config_service_v2_client.rb +1 -1
- data/lib/google/cloud/logging/v2/credentials.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/api/distribution.rb +1 -37
- data/lib/google/cloud/logging/v2/doc/google/api/label.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/api/metric.rb +1 -13
- data/lib/google/cloud/logging/v2/doc/google/api/monitored_resource.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/logging/type/http_request.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/log_entry.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging.rb +1 -12
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging_config.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging_metrics.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/protobuf/any.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/protobuf/duration.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/protobuf/empty.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/protobuf/field_mask.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/protobuf/struct.rb +1 -1
- data/lib/google/cloud/logging/v2/doc/google/protobuf/timestamp.rb +1 -1
- data/lib/google/cloud/logging/v2/logging_service_v2_client.rb +1 -1
- data/lib/google/cloud/logging/v2/logging_service_v2_client_config.json +1 -1
- data/lib/google/cloud/logging/v2/metrics_service_v2_client.rb +1 -1
- data/lib/google/cloud/logging/version.rb +1 -1
- metadata +5 -4
@@ -30,8 +30,12 @@ module Google
|
|
30
30
|
# {Google::Cloud::Logging::Logger} instance to be used by the Rails
|
31
31
|
# application.
|
32
32
|
#
|
33
|
-
# The
|
34
|
-
#
|
33
|
+
# The middleware is loaded only when certain conditions are met. These
|
34
|
+
# conditions are when the configuration
|
35
|
+
# `Google::Cloud.configure.use_logging` (also available as
|
36
|
+
# `Rails.application.config.google_cloud.use_logging` for a Rails
|
37
|
+
# application) is set to `true`, or, if the configuration is left unset
|
38
|
+
# but `Rails.env.production?` is `true`.
|
35
39
|
#
|
36
40
|
# When loaded, the {Google::Cloud::Logging::Middleware} will be inserted
|
37
41
|
# before the `Rails::Rack::Logger Middleware`, which allows it to set the
|
@@ -66,16 +70,59 @@ module Google
|
|
66
70
|
log_name = Logging.configure.log_name
|
67
71
|
labels = Logging.configure.labels
|
68
72
|
|
69
|
-
logging = Google::Cloud::Logging.new project_id:
|
73
|
+
logging = Google::Cloud::Logging.new project_id: project_id,
|
70
74
|
credentials: credentials
|
71
75
|
resource =
|
72
76
|
Logging::Middleware.build_monitored_resource resource_type,
|
73
77
|
resource_labels
|
74
78
|
|
75
|
-
|
79
|
+
Middleware.logger = logging.logger log_name, resource, labels
|
80
|
+
# Set the default Rails logger
|
81
|
+
if Logging.configure.set_default_logger_on_rails_init
|
82
|
+
set_default_logger
|
83
|
+
end
|
84
|
+
init_callback = -> { set_default_logger }
|
76
85
|
app.middleware.insert_before Rails::Rack::Logger,
|
77
86
|
Google::Cloud::Logging::Middleware,
|
78
|
-
logger:
|
87
|
+
logger: Middleware.logger,
|
88
|
+
on_init: init_callback
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
# This should be called once the application determines that it is safe
|
93
|
+
# to start background threads and open gRPC connections. It informs the
|
94
|
+
# middleware system that it is safe to use Google Cloud Logging. This is
|
95
|
+
# called during Rails initialization when the
|
96
|
+
# `set_default_logger_on_rails_init` configuration is set.
|
97
|
+
#
|
98
|
+
# Generally, this matters if the application forks worker processes;
|
99
|
+
# this method should be called only after workers are forked, since
|
100
|
+
# threads and network connections interact badly with fork. For example,
|
101
|
+
# when running Puma in [clustered
|
102
|
+
# mode](https://github.com/puma/puma#clustered-mode), this method should
|
103
|
+
# be called in an `on_worker_boot` block.
|
104
|
+
#
|
105
|
+
# If the application does no forking, this method can be called any time
|
106
|
+
# early in the application initialization process. Or by setting the
|
107
|
+
# `set_default_logger_on_rails_init` configuration.
|
108
|
+
#
|
109
|
+
# If the `set_default_logger_on_rails_init` configuration is not set,
|
110
|
+
# and {Railtie.set_default_logger} is not called in a post-fork hook,
|
111
|
+
# the default Rails logger object will not be set to use the Google
|
112
|
+
# Cloud Logging Logger object. For best results, an application should
|
113
|
+
# call this method at the appropriate time, such as a post-fork hook.
|
114
|
+
#
|
115
|
+
def self.set_default_logger
|
116
|
+
return if Middleware.logger.nil?
|
117
|
+
return if Rails.logger.is_a? Google::Cloud::Logging::Logger
|
118
|
+
|
119
|
+
# configure the Middleware logger to use the same settings as Rails
|
120
|
+
Middleware.logger.level = Rails.logger.level
|
121
|
+
# TODO: are there more settings to be set here?
|
122
|
+
|
123
|
+
# Replace the Rails default logger
|
124
|
+
Rails.application.config.logger = Middleware.logger
|
125
|
+
Rails.logger = Middleware.logger
|
79
126
|
end
|
80
127
|
|
81
128
|
##
|
@@ -132,6 +179,10 @@ module Google
|
|
132
179
|
log_config.monitored_resource.type
|
133
180
|
config.monitored_resource.labels ||=
|
134
181
|
log_config.monitored_resource.labels.to_h
|
182
|
+
if config.set_default_logger_on_rails_init.nil?
|
183
|
+
config.set_default_logger_on_rails_init = \
|
184
|
+
log_config.set_default_logger_on_rails_init
|
185
|
+
end
|
135
186
|
end
|
136
187
|
end
|
137
188
|
|
@@ -40,11 +40,11 @@ module Google
|
|
40
40
|
return mocked_logging if mocked_logging
|
41
41
|
@logging ||= \
|
42
42
|
V2::LoggingServiceV2Client.new(
|
43
|
-
credentials:
|
44
|
-
timeout:
|
43
|
+
credentials: credentials,
|
44
|
+
timeout: timeout,
|
45
45
|
client_config: client_config,
|
46
|
-
lib_name:
|
47
|
-
lib_version:
|
46
|
+
lib_name: "gccl",
|
47
|
+
lib_version: Google::Cloud::Logging::VERSION
|
48
48
|
)
|
49
49
|
end
|
50
50
|
attr_accessor :mocked_logging
|
@@ -53,11 +53,11 @@ module Google
|
|
53
53
|
return mocked_sinks if mocked_sinks
|
54
54
|
@sinks ||= \
|
55
55
|
V2::ConfigServiceV2Client.new(
|
56
|
-
credentials:
|
57
|
-
timeout:
|
56
|
+
credentials: credentials,
|
57
|
+
timeout: timeout,
|
58
58
|
client_config: client_config,
|
59
|
-
lib_name:
|
60
|
-
lib_version:
|
59
|
+
lib_name: "gccl",
|
60
|
+
lib_version: Google::Cloud::Logging::VERSION
|
61
61
|
)
|
62
62
|
end
|
63
63
|
attr_accessor :mocked_sinks
|
@@ -66,11 +66,11 @@ module Google
|
|
66
66
|
return mocked_metrics if mocked_metrics
|
67
67
|
@metrics ||= \
|
68
68
|
V2::MetricsServiceV2Client.new(
|
69
|
-
credentials:
|
70
|
-
timeout:
|
69
|
+
credentials: credentials,
|
70
|
+
timeout: timeout,
|
71
71
|
client_config: client_config,
|
72
|
-
lib_name:
|
73
|
-
lib_version:
|
72
|
+
lib_name: "gccl",
|
73
|
+
lib_version: Google::Cloud::Logging::VERSION
|
74
74
|
)
|
75
75
|
end
|
76
76
|
attr_accessor :mocked_metrics
|
@@ -83,8 +83,10 @@ module Google
|
|
83
83
|
resource_names = ["projects/#{@project}"] if resource_names.empty?
|
84
84
|
call_opts = default_options
|
85
85
|
if token
|
86
|
-
call_opts = Google::Gax::CallOptions.new(
|
87
|
-
|
86
|
+
call_opts = Google::Gax::CallOptions.new(
|
87
|
+
kwargs: default_headers,
|
88
|
+
page_token: token
|
89
|
+
)
|
88
90
|
end
|
89
91
|
|
90
92
|
execute do
|
@@ -117,13 +119,15 @@ module Google
|
|
117
119
|
parent = resource || "projects/#{@project}"
|
118
120
|
call_opts = default_options
|
119
121
|
if token
|
120
|
-
call_opts = Google::Gax::CallOptions.new(
|
121
|
-
|
122
|
+
call_opts = Google::Gax::CallOptions.new(
|
123
|
+
kwargs: default_headers,
|
124
|
+
page_token: token
|
125
|
+
)
|
122
126
|
end
|
123
127
|
|
124
128
|
execute do
|
125
129
|
paged_enum = logging.list_logs parent, page_size: max,
|
126
|
-
options:
|
130
|
+
options: call_opts
|
127
131
|
paged_enum.page.response
|
128
132
|
end
|
129
133
|
end
|
@@ -137,8 +141,10 @@ module Google
|
|
137
141
|
def list_resource_descriptors token: nil, max: nil
|
138
142
|
call_opts = default_options
|
139
143
|
if token
|
140
|
-
call_opts = Google::Gax::CallOptions.new(
|
141
|
-
|
144
|
+
call_opts = Google::Gax::CallOptions.new(
|
145
|
+
kwargs: default_headers,
|
146
|
+
page_token: token
|
147
|
+
)
|
142
148
|
end
|
143
149
|
|
144
150
|
execute do
|
@@ -150,8 +156,10 @@ module Google
|
|
150
156
|
def list_sinks token: nil, max: nil
|
151
157
|
call_opts = default_options
|
152
158
|
if token
|
153
|
-
call_opts = Google::Gax::CallOptions.new(
|
154
|
-
|
159
|
+
call_opts = Google::Gax::CallOptions.new(
|
160
|
+
kwargs: default_headers,
|
161
|
+
page_token: token
|
162
|
+
)
|
155
163
|
end
|
156
164
|
|
157
165
|
execute do
|
@@ -169,7 +177,7 @@ module Google
|
|
169
177
|
execute do
|
170
178
|
sinks.create_sink project_path, sink,
|
171
179
|
unique_writer_identity: unique_writer_identity,
|
172
|
-
options:
|
180
|
+
options: default_options
|
173
181
|
end
|
174
182
|
end
|
175
183
|
|
@@ -187,7 +195,7 @@ module Google
|
|
187
195
|
execute do
|
188
196
|
sinks.update_sink sink_path(name), sink,
|
189
197
|
unique_writer_identity: unique_writer_identity,
|
190
|
-
options:
|
198
|
+
options: default_options
|
191
199
|
end
|
192
200
|
end
|
193
201
|
|
@@ -200,8 +208,10 @@ module Google
|
|
200
208
|
def list_metrics token: nil, max: nil
|
201
209
|
call_opts = default_options
|
202
210
|
if token
|
203
|
-
call_opts = Google::Gax::CallOptions.new(
|
204
|
-
|
211
|
+
call_opts = Google::Gax::CallOptions.new(
|
212
|
+
kwargs: default_headers,
|
213
|
+
page_token: token
|
214
|
+
)
|
205
215
|
end
|
206
216
|
|
207
217
|
execute do
|
@@ -248,6 +258,13 @@ module Google
|
|
248
258
|
end
|
249
259
|
end
|
250
260
|
|
261
|
+
def log_path log_name
|
262
|
+
return nil if log_name.nil?
|
263
|
+
return log_name if log_name.empty?
|
264
|
+
return log_name if log_name.to_s.include? "/"
|
265
|
+
"#{project_path}/logs/#{log_name}"
|
266
|
+
end
|
267
|
+
|
251
268
|
def inspect
|
252
269
|
"#{self.class}(#{@project})"
|
253
270
|
end
|
@@ -258,13 +275,6 @@ module Google
|
|
258
275
|
"projects/#{@project}"
|
259
276
|
end
|
260
277
|
|
261
|
-
def log_path log_name
|
262
|
-
return nil if log_name.nil?
|
263
|
-
return log_name if log_name.empty?
|
264
|
-
return log_name if log_name.to_s.include? "/"
|
265
|
-
"#{project_path}/logs/#{log_name}"
|
266
|
-
end
|
267
|
-
|
268
278
|
def sink_path sink_name
|
269
279
|
return sink_name if sink_name.to_s.include? "/"
|
270
280
|
"#{project_path}/sinks/#{sink_name}"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2019 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -78,15 +78,6 @@ module Google
|
|
78
78
|
# @return [Array<Google::Api::Distribution::Exemplar>]
|
79
79
|
# Must be in increasing order of `value` field.
|
80
80
|
class Distribution
|
81
|
-
# The range of the population values.
|
82
|
-
# @!attribute [rw] min
|
83
|
-
# @return [Float]
|
84
|
-
# The minimum of the population values.
|
85
|
-
# @!attribute [rw] max
|
86
|
-
# @return [Float]
|
87
|
-
# The maximum of the population values.
|
88
|
-
class Range; end
|
89
|
-
|
90
81
|
# `BucketOptions` describes the bucket boundaries used to create a histogram
|
91
82
|
# for the distribution. The buckets can be in a linear sequence, an
|
92
83
|
# exponential sequence, or each bucket can be specified explicitly.
|
@@ -168,33 +159,6 @@ module Google
|
|
168
159
|
# The values must be monotonically increasing.
|
169
160
|
class Explicit; end
|
170
161
|
end
|
171
|
-
|
172
|
-
# Exemplars are example points that may be used to annotate aggregated
|
173
|
-
# distribution values. They are metadata that gives information about a
|
174
|
-
# particular value added to a Distribution bucket, such as a trace ID that
|
175
|
-
# was active when a value was added. They may contain further information,
|
176
|
-
# such as a example values and timestamps, origin, etc.
|
177
|
-
# @!attribute [rw] value
|
178
|
-
# @return [Float]
|
179
|
-
# Value of the exemplar point. This value determines to which bucket the
|
180
|
-
# exemplar belongs.
|
181
|
-
# @!attribute [rw] timestamp
|
182
|
-
# @return [Google::Protobuf::Timestamp]
|
183
|
-
# The observation (sampling) time of the above value.
|
184
|
-
# @!attribute [rw] attachments
|
185
|
-
# @return [Array<Google::Protobuf::Any>]
|
186
|
-
# Contextual information about the example value. Examples are:
|
187
|
-
#
|
188
|
-
# Trace ID: type.googleapis.com/google.devtools.cloudtrace.v1.Trace
|
189
|
-
#
|
190
|
-
# Literal string: type.googleapis.com/google.protobuf.StringValue
|
191
|
-
#
|
192
|
-
# Labels dropped during aggregation:
|
193
|
-
# type.googleapis.com/google.monitoring.v3.DroppedLabels
|
194
|
-
#
|
195
|
-
# There may be only a single attachment of any given message type in a
|
196
|
-
# single exemplar, and this is enforced by the system.
|
197
|
-
class Exemplar; end
|
198
162
|
end
|
199
163
|
end
|
200
164
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2019 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -189,17 +189,5 @@ module Google
|
|
189
189
|
MONEY = 6
|
190
190
|
end
|
191
191
|
end
|
192
|
-
|
193
|
-
# A specific metric, identified by specifying values for all of the
|
194
|
-
# labels of a {Google::Api::MetricDescriptor `MetricDescriptor`}.
|
195
|
-
# @!attribute [rw] type
|
196
|
-
# @return [String]
|
197
|
-
# An existing metric type, see {Google::Api::MetricDescriptor}.
|
198
|
-
# For example, `custom.googleapis.com/invoice/paid/amount`.
|
199
|
-
# @!attribute [rw] labels
|
200
|
-
# @return [Hash{String => String}]
|
201
|
-
# The set of label values that uniquely identify this metric. All
|
202
|
-
# labels listed in the `MetricDescriptor` must be assigned values.
|
203
|
-
class Metric; end
|
204
192
|
end
|
205
193
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2019 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -112,17 +112,6 @@ module Google
|
|
112
112
|
# empty
|
113
113
|
class WriteLogEntriesResponse; end
|
114
114
|
|
115
|
-
# Error details for WriteLogEntries with partial success.
|
116
|
-
# @!attribute [rw] log_entry_errors
|
117
|
-
# @return [Hash{Integer => Google::Rpc::Status}]
|
118
|
-
# When `WriteLogEntriesRequest.partial_success` is true, records the error
|
119
|
-
# status for entries that were not written due to a permanent error, keyed
|
120
|
-
# by the entry's zero-based index in `WriteLogEntriesRequest.entries`.
|
121
|
-
#
|
122
|
-
# Failed requests for which no entries are written will not include
|
123
|
-
# per-entry errors.
|
124
|
-
class WriteLogEntriesPartialErrors; end
|
125
|
-
|
126
115
|
# The parameters to `ListLogEntries`.
|
127
116
|
# @!attribute [rw] project_ids
|
128
117
|
# @return [Array<String>]
|