google-cloud-trace 0.26.1 → 0.27.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/lib/google/cloud/trace/label_key.rb +3 -0
- data/lib/google/cloud/trace/patches/active_call_with_trace.rb +45 -0
- data/lib/google/cloud/trace/patches/call_with_trace.rb +89 -0
- data/lib/google/cloud/trace/service.rb +8 -2
- data/lib/google/cloud/trace/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb2670fad7d9b85c3b7104c80152e12fe04419c0
|
4
|
+
data.tar.gz: 4d09dae2b9e81c947aae3364f0009485fc0886e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45b1826655a68c86c68aed322ae5f1cc83753f1594479cf3c191b006cac50b0012736aa671088512253d1ef11fd1ec9a428487643deefa5f8508cca591d1851a
|
7
|
+
data.tar.gz: f10668b16724af1a1d67d78afeb6e140c781dc6fa7e1bad6781dfd41d9340713cd65aef1a9dc6e4c6c22e241e641dbaa9edbc988675d123cb064604b31444a0b
|
@@ -70,8 +70,11 @@ module Google
|
|
70
70
|
GAE_MEMCACHE_SIZE = "g.co/gae/memcache/size"
|
71
71
|
GAE_REQUEST_LOG_ID = "g.co/gae/request_log_id"
|
72
72
|
|
73
|
+
RPC_HOST = "/rpc/host"
|
74
|
+
RPC_REQUEST_TYPE = "/rpc/request/type"
|
73
75
|
RPC_REQUEST_SIZE = "/rpc/request/size"
|
74
76
|
RPC_RESPONSE_SIZE = "/rpc/response/size"
|
77
|
+
RPC_STATUS_CODE = "/rpc/status_code"
|
75
78
|
|
76
79
|
##
|
77
80
|
# Set the stack trace label in the given labels hash. The current call
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright 2017 Google Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
require "google/cloud/trace"
|
17
|
+
|
18
|
+
module GRPC
|
19
|
+
##
|
20
|
+
# Stackdriver Trace instrumentation of GRPC by patching GRPC::ActiveCall
|
21
|
+
# class. Intercept each GRPC request and create a Trace span with basic
|
22
|
+
# request information.
|
23
|
+
module ActiveCallWithTrace
|
24
|
+
SPAN_NAME = "gRPC request"
|
25
|
+
|
26
|
+
##
|
27
|
+
# Override GRPC::ActiveCall#request_response method. Wrap the original
|
28
|
+
# method with a trace span that will get submitted with the overall request
|
29
|
+
# trace span tree.
|
30
|
+
def request_response *args
|
31
|
+
Google::Cloud::Trace.in_span SPAN_NAME do |span|
|
32
|
+
if span && !args.empty?
|
33
|
+
grpc_request = args[0]
|
34
|
+
label_key = Google::Cloud::Trace::LabelKey::RPC_REQUEST_TYPE
|
35
|
+
span.labels[label_key] = grpc_request.class.name.gsub(/^.*::/, "")
|
36
|
+
end
|
37
|
+
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Patch GRPC::ActiveCall#request_response method
|
44
|
+
::GRPC::ActiveCall.send(:prepend, ActiveCallWithTrace)
|
45
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Copyright 2017 Google Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
require "google/cloud/trace"
|
17
|
+
|
18
|
+
module GRPC
|
19
|
+
module Core
|
20
|
+
##
|
21
|
+
# Stackdriver Trace instrumentation of GRPC by patching GRPC::Core::Call
|
22
|
+
# class. Add more RPC information into the trace span created by upstream
|
23
|
+
# patch from GRPC::ActiveCallWithTrace
|
24
|
+
module CallWithTrace
|
25
|
+
##
|
26
|
+
# @private Add request labels from the Call object and message.
|
27
|
+
def self.add_request_labels call, message, labels
|
28
|
+
label_keys = Google::Cloud::Trace::LabelKey
|
29
|
+
|
30
|
+
message_size = message.to_s.bytesize.to_s
|
31
|
+
|
32
|
+
set_label labels, label_keys::RPC_REQUEST_SIZE, message_size
|
33
|
+
set_label labels, label_keys::RPC_HOST, call.peer.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# @private Add response labels from gRPC response
|
38
|
+
def self.add_response_labels response, labels
|
39
|
+
label_keys = Google::Cloud::Trace::LabelKey
|
40
|
+
|
41
|
+
response_size = response.message.to_s.bytesize.to_s
|
42
|
+
status = status_code_to_label response.status.code
|
43
|
+
|
44
|
+
set_label labels, label_keys::RPC_RESPONSE_SIZE, response_size
|
45
|
+
set_label labels, label_keys::RPC_STATUS_CODE, status
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# @private Helper method to set label
|
50
|
+
def self.set_label labels, key, value
|
51
|
+
labels[key] = value if value.is_a? ::String
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# @private Reverse lookup from numeric status code to readable string.
|
56
|
+
def self.status_code_to_label code
|
57
|
+
@lookup ||= Hash[GRPC::Core::StatusCodes.constants.map do |c|
|
58
|
+
[GRPC::Core::StatusCodes.const_get(c), c.to_s]
|
59
|
+
end]
|
60
|
+
|
61
|
+
@lookup[code]
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Override GRPC::Core::Call#run_batch method. Reuse the "gRPC request"
|
66
|
+
# span created in ActiveCallWithTrace patch to add more information from
|
67
|
+
# the request.
|
68
|
+
def run_batch *args
|
69
|
+
span = Google::Cloud::Trace.get
|
70
|
+
# Make sure we're in a "gRPC request" span
|
71
|
+
span = nil if span && span.name != GRPC::ActiveCallWithTrace::SPAN_NAME
|
72
|
+
|
73
|
+
if span && !args.empty?
|
74
|
+
message = args[0]
|
75
|
+
CallWithTrace.add_request_labels self, message, span.labels
|
76
|
+
end
|
77
|
+
|
78
|
+
response = super
|
79
|
+
|
80
|
+
CallWithTrace.add_response_labels response, span.labels if span
|
81
|
+
|
82
|
+
response
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Patch GRPC::Core::Call#run_batch method
|
87
|
+
::GRPC::Core::Call.send(:prepend, CallWithTrace)
|
88
|
+
end
|
89
|
+
end
|
@@ -59,13 +59,13 @@ module Google
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def channel
|
62
|
-
|
62
|
+
load_grpc
|
63
63
|
GRPC::Core::Channel.new host, nil, chan_creds
|
64
64
|
end
|
65
65
|
|
66
66
|
def chan_creds
|
67
67
|
return credentials if insecure?
|
68
|
-
|
68
|
+
load_grpc
|
69
69
|
GRPC::Core::ChannelCredentials.new.compose \
|
70
70
|
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
71
71
|
end
|
@@ -160,6 +160,12 @@ module Google
|
|
160
160
|
# GaxError wraps BadStatus, but exposes it as #cause
|
161
161
|
raise Google::Cloud::Error.from_error(e.cause)
|
162
162
|
end
|
163
|
+
|
164
|
+
def load_grpc
|
165
|
+
require "grpc"
|
166
|
+
require "google/cloud/trace/patches/active_call_with_trace"
|
167
|
+
require "google/cloud/trace/patches/call_with_trace"
|
168
|
+
end
|
163
169
|
end
|
164
170
|
end
|
165
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-trace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-core
|
@@ -224,6 +224,8 @@ files:
|
|
224
224
|
- lib/google/cloud/trace/label_key.rb
|
225
225
|
- lib/google/cloud/trace/middleware.rb
|
226
226
|
- lib/google/cloud/trace/notifications.rb
|
227
|
+
- lib/google/cloud/trace/patches/active_call_with_trace.rb
|
228
|
+
- lib/google/cloud/trace/patches/call_with_trace.rb
|
227
229
|
- lib/google/cloud/trace/project.rb
|
228
230
|
- lib/google/cloud/trace/rails.rb
|
229
231
|
- lib/google/cloud/trace/result_set.rb
|