google-cloud-logging 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2040c01767882892eec9ab8951ae42563a026a48
4
- data.tar.gz: 5024c4eae693b2e0822d5928da4a305837ffcac7
3
+ metadata.gz: 43b8c5db09219ded373243da0ca00c843a9fc621
4
+ data.tar.gz: 1f7283f517b86783fa2411b7a03f93020762851f
5
5
  SHA512:
6
- metadata.gz: 394d202895b1719f155846ea0b38423aabc9b8c173f39283348a12a3ec69d915a3e6e17d1193dc7dcd7f251f3560f6d78b4338a3be44eb53978319cecaebcada
7
- data.tar.gz: 8274d6c0f7686057113cb07a5cf5e89cd0302b3861fc3095ee96adacc134fdd9b4b05b810a8ac982ec5389915c162e5be0f6d7de3e813290f72aafe0c9c13812
6
+ metadata.gz: cd23872d6e35733f0bdf08775bf74922c1be1263dff90af212be364a5a763b58b9a1b41ab3d77bbcdecfeee6b339057deebcbdec66ef8fdfb3033dd2d484ab02
7
+ data.tar.gz: 3fbbb4a987dd9f3012d1917bdcbe09d7f808fb15d815fd3b3c932e92f6bba78a70435766288cab945d912ce37697b507d70985601add2afeb6bd1ab0fd982e37
data/README.md CHANGED
@@ -95,8 +95,6 @@ This library is supported on Ruby 2.0+.
95
95
 
96
96
  This library follows [Semantic Versioning](http://semver.org/).
97
97
 
98
- It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
99
-
100
98
  ## Contributing
101
99
 
102
100
  Contributions to this library are always welcome and highly encouraged.
@@ -47,7 +47,7 @@ module Google
47
47
  # The log_name is a String that controls the name of the Stackdriver
48
48
  # log to write to. If it is nil, the default log_name for this Logger
49
49
  # is used.
50
- RequestInfo = ::Struct.new :trace_id, :log_name
50
+ RequestInfo = ::Struct.new :trace_id, :log_name, :env
51
51
 
52
52
  ##
53
53
  # The Google Cloud writer object that calls to {#write_entries} are made
@@ -429,11 +429,14 @@ module Google
429
429
  # should be logged.
430
430
  # @param [String, nil] log_name The log name to use, or nil to use
431
431
  # this logger's default.
432
+ # @param [Hash, nil] env The request's Rack environment or `nil` if not
433
+ # available.
432
434
  #
433
435
  def add_request_info info: nil,
436
+ env: nil,
434
437
  trace_id: nil,
435
438
  log_name: nil
436
- info ||= RequestInfo.new trace_id, log_name
439
+ info ||= RequestInfo.new trace_id, log_name, env
437
440
  @request_info[current_thread_id] = info
438
441
 
439
442
  # Start removing old entries if hash gets too large.
@@ -549,7 +552,9 @@ module Google
549
552
  end
550
553
  end
551
554
 
552
- labels.merge(merged_labels)
555
+ request_env = info && request_info.env || {}
556
+
557
+ compute_labels(request_env).merge(merged_labels)
553
558
  end
554
559
 
555
560
  ##
@@ -582,6 +587,29 @@ module Google
582
587
  def current_thread_id
583
588
  Thread.current.object_id
584
589
  end
590
+
591
+ private
592
+
593
+ ##
594
+ # @private Compute values for labels
595
+ def compute_labels request_env
596
+ Hash[
597
+ labels.map do |k, value_or_proc|
598
+ [k, compute_label_value(request_env, value_or_proc)]
599
+ end
600
+ ]
601
+ end
602
+
603
+ ##
604
+ # @private Compute individual label value.
605
+ # Value can be a Proc (function of the request env) or a static value.
606
+ def compute_label_value request_env, value_or_proc
607
+ if value_or_proc.respond_to?(:call)
608
+ value_or_proc.call(request_env)
609
+ else
610
+ value_or_proc
611
+ end
612
+ end
585
613
  end
586
614
  end
587
615
  end
@@ -83,7 +83,8 @@ module Google
83
83
  env["rack.logger"] = logger
84
84
  trace_id = get_trace_id env
85
85
  log_name = get_log_name env
86
- logger.add_request_info trace_id: trace_id, log_name: log_name
86
+ logger.add_request_info trace_id: trace_id, log_name: log_name,
87
+ env: env
87
88
  begin
88
89
  @app.call env
89
90
  ensure
@@ -362,7 +362,8 @@ module Google
362
362
  # @param [Google::Cloud::Logging::Resource] resource The monitored
363
363
  # resource to be associated with written log entries.
364
364
  # @param [Hash] labels A set of user-defined data to be associated with
365
- # written log entries.
365
+ # written log entries. Values can be strings or Procs which are
366
+ # functions of the request environment.
366
367
  #
367
368
  # @return [Google::Cloud::Logging::Logger] a Logger object that can be
368
369
  # used in place of a ruby standard library logger object.
@@ -63,6 +63,7 @@ module Google
63
63
  resource_type = Logging.configure.monitored_resource.type
64
64
  resource_labels = Logging.configure.monitored_resource.labels
65
65
  log_name = Logging.configure.log_name
66
+ labels = Logging.configure.labels
66
67
 
67
68
  logging = Google::Cloud::Logging.new project: project_id,
68
69
  keyfile: keyfile
@@ -70,7 +71,7 @@ module Google
70
71
  Logging::Middleware.build_monitored_resource resource_type,
71
72
  resource_labels
72
73
 
73
- app.config.logger = logging.logger log_name, resource
74
+ app.config.logger = logging.logger log_name, resource, labels
74
75
  app.middleware.insert_before Rails::Rack::Logger,
75
76
  Google::Cloud::Logging::Middleware,
76
77
  logger: app.config.logger
@@ -109,7 +110,7 @@ module Google
109
110
  ##
110
111
  # @private Merge Rails configuration into Logging instrumentation
111
112
  # configuration.
112
- def self.merge_rails_config rails_config
113
+ def self.merge_rails_config rails_config # rubocop:disable AbcSize
113
114
  gcp_config = rails_config.google_cloud
114
115
  logging_config = gcp_config.logging
115
116
 
@@ -119,6 +120,7 @@ module Google
119
120
  gcp_config.project_id
120
121
  config.keyfile ||= logging_config.keyfile || gcp_config.keyfile
121
122
  config.log_name ||= logging_config.log_name
123
+ config.labels ||= logging_config.labels
122
124
  config.log_name_map ||= logging_config.log_name_map
123
125
  config.monitored_resource.type ||=
124
126
  logging_config.monitored_resource.type
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Logging
19
- VERSION = "1.2.1"
19
+ VERSION = "1.2.2"
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-12 00:00:00.000000000 Z
12
+ date: 2017-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -286,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
286
  version: '0'
287
287
  requirements: []
288
288
  rubyforge_project:
289
- rubygems_version: 2.6.12
289
+ rubygems_version: 2.6.13
290
290
  signing_key:
291
291
  specification_version: 4
292
292
  summary: API Client library for Stackdriver Logging