google-cloud-trace 0.29.0 → 0.30.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/v2.rb +114 -0
- data/lib/google/cloud/trace/v2/doc/google/devtools/cloudtrace/v2/trace.rb +320 -0
- data/lib/google/cloud/trace/v2/doc/google/protobuf/any.rb +124 -0
- data/lib/google/cloud/trace/v2/doc/google/protobuf/timestamp.rb +106 -0
- data/lib/google/cloud/trace/v2/doc/google/protobuf/wrappers.rb +89 -0
- data/lib/google/cloud/trace/v2/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/trace/v2/doc/overview.rb +67 -0
- data/lib/google/cloud/trace/v2/trace_service_client.rb +364 -0
- data/lib/google/cloud/trace/v2/trace_service_client_config.json +36 -0
- data/lib/google/cloud/trace/version.rb +1 -1
- data/lib/google/devtools/cloudtrace/v2/trace_pb.rb +129 -0
- data/lib/google/devtools/cloudtrace/v2/tracing_pb.rb +25 -0
- data/lib/google/devtools/cloudtrace/v2/tracing_services_pb.rb +52 -0
- metadata +15 -3
@@ -0,0 +1,106 @@
|
|
1
|
+
# Copyright 2017 Google LLC
|
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
|
+
# https://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
|
+
module Google
|
16
|
+
module Protobuf
|
17
|
+
# A Timestamp represents a point in time independent of any time zone
|
18
|
+
# or calendar, represented as seconds and fractions of seconds at
|
19
|
+
# nanosecond resolution in UTC Epoch time. It is encoded using the
|
20
|
+
# Proleptic Gregorian Calendar which extends the Gregorian calendar
|
21
|
+
# backwards to year one. It is encoded assuming all minutes are 60
|
22
|
+
# seconds long, i.e. leap seconds are "smeared" so that no leap second
|
23
|
+
# table is needed for interpretation. Range is from
|
24
|
+
# 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
|
25
|
+
# By restricting to that range, we ensure that we can convert to
|
26
|
+
# and from RFC 3339 date strings.
|
27
|
+
# See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
|
28
|
+
#
|
29
|
+
# = Examples
|
30
|
+
#
|
31
|
+
# Example 1: Compute Timestamp from POSIX +time()+.
|
32
|
+
#
|
33
|
+
# Timestamp timestamp;
|
34
|
+
# timestamp.set_seconds(time(NULL));
|
35
|
+
# timestamp.set_nanos(0);
|
36
|
+
#
|
37
|
+
# Example 2: Compute Timestamp from POSIX +gettimeofday()+.
|
38
|
+
#
|
39
|
+
# struct timeval tv;
|
40
|
+
# gettimeofday(&tv, NULL);
|
41
|
+
#
|
42
|
+
# Timestamp timestamp;
|
43
|
+
# timestamp.set_seconds(tv.tv_sec);
|
44
|
+
# timestamp.set_nanos(tv.tv_usec * 1000);
|
45
|
+
#
|
46
|
+
# Example 3: Compute Timestamp from Win32 +GetSystemTimeAsFileTime()+.
|
47
|
+
#
|
48
|
+
# FILETIME ft;
|
49
|
+
# GetSystemTimeAsFileTime(&ft);
|
50
|
+
# UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
|
51
|
+
#
|
52
|
+
# // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
|
53
|
+
# // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
|
54
|
+
# Timestamp timestamp;
|
55
|
+
# timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
|
56
|
+
# timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
|
57
|
+
#
|
58
|
+
# Example 4: Compute Timestamp from Java +System.currentTimeMillis()+.
|
59
|
+
#
|
60
|
+
# long millis = System.currentTimeMillis();
|
61
|
+
#
|
62
|
+
# Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
|
63
|
+
# .setNanos((int) ((millis % 1000) * 1000000)).build();
|
64
|
+
#
|
65
|
+
#
|
66
|
+
# Example 5: Compute Timestamp from current time in Python.
|
67
|
+
#
|
68
|
+
# timestamp = Timestamp()
|
69
|
+
# timestamp.GetCurrentTime()
|
70
|
+
#
|
71
|
+
# = JSON Mapping
|
72
|
+
#
|
73
|
+
# In JSON format, the Timestamp type is encoded as a string in the
|
74
|
+
# [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
|
75
|
+
# format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
|
76
|
+
# where {year} is always expressed using four digits while {month}, {day},
|
77
|
+
# {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
|
78
|
+
# seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
|
79
|
+
# are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
|
80
|
+
# is required, though only UTC (as indicated by "Z") is presently supported.
|
81
|
+
#
|
82
|
+
# For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
|
83
|
+
# 01:30 UTC on January 15, 2017.
|
84
|
+
#
|
85
|
+
# In JavaScript, one can convert a Date object to this format using the
|
86
|
+
# standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString]
|
87
|
+
# method. In Python, a standard +datetime.datetime+ object can be converted
|
88
|
+
# to this format using [+strftime+](https://docs.python.org/2/library/time.html#time.strftime)
|
89
|
+
# with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
|
90
|
+
# can use the Joda Time's [+ISODateTimeFormat.dateTime()+](
|
91
|
+
# http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime())
|
92
|
+
# to obtain a formatter capable of generating timestamps in this format.
|
93
|
+
# @!attribute [rw] seconds
|
94
|
+
# @return [Integer]
|
95
|
+
# Represents seconds of UTC time since Unix epoch
|
96
|
+
# 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
97
|
+
# 9999-12-31T23:59:59Z inclusive.
|
98
|
+
# @!attribute [rw] nanos
|
99
|
+
# @return [Integer]
|
100
|
+
# Non-negative fractions of a second at nanosecond resolution. Negative
|
101
|
+
# second values with fractions must still have non-negative nanos values
|
102
|
+
# that count forward in time. Must be from 0 to 999,999,999
|
103
|
+
# inclusive.
|
104
|
+
class Timestamp; end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Copyright 2017 Google LLC
|
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
|
+
# https://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
|
+
module Google
|
16
|
+
module Protobuf
|
17
|
+
# Wrapper message for +double+.
|
18
|
+
#
|
19
|
+
# The JSON representation for +DoubleValue+ is JSON number.
|
20
|
+
# @!attribute [rw] value
|
21
|
+
# @return [Float]
|
22
|
+
# The double value.
|
23
|
+
class DoubleValue; end
|
24
|
+
|
25
|
+
# Wrapper message for +float+.
|
26
|
+
#
|
27
|
+
# The JSON representation for +FloatValue+ is JSON number.
|
28
|
+
# @!attribute [rw] value
|
29
|
+
# @return [Float]
|
30
|
+
# The float value.
|
31
|
+
class FloatValue; end
|
32
|
+
|
33
|
+
# Wrapper message for +int64+.
|
34
|
+
#
|
35
|
+
# The JSON representation for +Int64Value+ is JSON string.
|
36
|
+
# @!attribute [rw] value
|
37
|
+
# @return [Integer]
|
38
|
+
# The int64 value.
|
39
|
+
class Int64Value; end
|
40
|
+
|
41
|
+
# Wrapper message for +uint64+.
|
42
|
+
#
|
43
|
+
# The JSON representation for +UInt64Value+ is JSON string.
|
44
|
+
# @!attribute [rw] value
|
45
|
+
# @return [Integer]
|
46
|
+
# The uint64 value.
|
47
|
+
class UInt64Value; end
|
48
|
+
|
49
|
+
# Wrapper message for +int32+.
|
50
|
+
#
|
51
|
+
# The JSON representation for +Int32Value+ is JSON number.
|
52
|
+
# @!attribute [rw] value
|
53
|
+
# @return [Integer]
|
54
|
+
# The int32 value.
|
55
|
+
class Int32Value; end
|
56
|
+
|
57
|
+
# Wrapper message for +uint32+.
|
58
|
+
#
|
59
|
+
# The JSON representation for +UInt32Value+ is JSON number.
|
60
|
+
# @!attribute [rw] value
|
61
|
+
# @return [Integer]
|
62
|
+
# The uint32 value.
|
63
|
+
class UInt32Value; end
|
64
|
+
|
65
|
+
# Wrapper message for +bool+.
|
66
|
+
#
|
67
|
+
# The JSON representation for +BoolValue+ is JSON +true+ and +false+.
|
68
|
+
# @!attribute [rw] value
|
69
|
+
# @return [true, false]
|
70
|
+
# The bool value.
|
71
|
+
class BoolValue; end
|
72
|
+
|
73
|
+
# Wrapper message for +string+.
|
74
|
+
#
|
75
|
+
# The JSON representation for +StringValue+ is JSON string.
|
76
|
+
# @!attribute [rw] value
|
77
|
+
# @return [String]
|
78
|
+
# The string value.
|
79
|
+
class StringValue; end
|
80
|
+
|
81
|
+
# Wrapper message for +bytes+.
|
82
|
+
#
|
83
|
+
# The JSON representation for +BytesValue+ is JSON string.
|
84
|
+
# @!attribute [rw] value
|
85
|
+
# @return [String]
|
86
|
+
# The bytes value.
|
87
|
+
class BytesValue; end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright 2017 Google LLC
|
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
|
+
# https://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
|
+
module Google
|
16
|
+
module Rpc
|
17
|
+
# The +Status+ type defines a logical error model that is suitable for different
|
18
|
+
# programming environments, including REST APIs and RPC APIs. It is used by
|
19
|
+
# [gRPC](https://github.com/grpc). The error model is designed to be:
|
20
|
+
#
|
21
|
+
# * Simple to use and understand for most users
|
22
|
+
# * Flexible enough to meet unexpected needs
|
23
|
+
#
|
24
|
+
# = Overview
|
25
|
+
#
|
26
|
+
# The +Status+ message contains three pieces of data: error code, error message,
|
27
|
+
# and error details. The error code should be an enum value of
|
28
|
+
# {Google::Rpc::Code}, but it may accept additional error codes if needed. The
|
29
|
+
# error message should be a developer-facing English message that helps
|
30
|
+
# developers *understand* and *resolve* the error. If a localized user-facing
|
31
|
+
# error message is needed, put the localized message in the error details or
|
32
|
+
# localize it in the client. The optional error details may contain arbitrary
|
33
|
+
# information about the error. There is a predefined set of error detail types
|
34
|
+
# in the package +google.rpc+ that can be used for common error conditions.
|
35
|
+
#
|
36
|
+
# = Language mapping
|
37
|
+
#
|
38
|
+
# The +Status+ message is the logical representation of the error model, but it
|
39
|
+
# is not necessarily the actual wire format. When the +Status+ message is
|
40
|
+
# exposed in different client libraries and different wire protocols, it can be
|
41
|
+
# mapped differently. For example, it will likely be mapped to some exceptions
|
42
|
+
# in Java, but more likely mapped to some error codes in C.
|
43
|
+
#
|
44
|
+
# = Other uses
|
45
|
+
#
|
46
|
+
# The error model and the +Status+ message can be used in a variety of
|
47
|
+
# environments, either with or without APIs, to provide a
|
48
|
+
# consistent developer experience across different environments.
|
49
|
+
#
|
50
|
+
# Example uses of this error model include:
|
51
|
+
#
|
52
|
+
# * Partial errors. If a service needs to return partial errors to the client,
|
53
|
+
# it may embed the +Status+ in the normal response to indicate the partial
|
54
|
+
# errors.
|
55
|
+
#
|
56
|
+
# * Workflow errors. A typical workflow has multiple steps. Each step may
|
57
|
+
# have a +Status+ message for error reporting.
|
58
|
+
#
|
59
|
+
# * Batch operations. If a client uses batch request and batch response, the
|
60
|
+
# +Status+ message should be used directly inside batch response, one for
|
61
|
+
# each error sub-response.
|
62
|
+
#
|
63
|
+
# * Asynchronous operations. If an API call embeds asynchronous operation
|
64
|
+
# results in its response, the status of those operations should be
|
65
|
+
# represented directly using the +Status+ message.
|
66
|
+
#
|
67
|
+
# * Logging. If some API errors are stored in logs, the message +Status+ could
|
68
|
+
# be used directly after any stripping needed for security/privacy reasons.
|
69
|
+
# @!attribute [rw] code
|
70
|
+
# @return [Integer]
|
71
|
+
# The status code, which should be an enum value of {Google::Rpc::Code}.
|
72
|
+
# @!attribute [rw] message
|
73
|
+
# @return [String]
|
74
|
+
# A developer-facing error message, which should be in English. Any
|
75
|
+
# user-facing error message should be localized and sent in the
|
76
|
+
# {Google::Rpc::Status#details} field, or localized by the client.
|
77
|
+
# @!attribute [rw] details
|
78
|
+
# @return [Array<Google::Protobuf::Any>]
|
79
|
+
# A list of messages that carry the error details. There is a common set of
|
80
|
+
# message types for APIs to use.
|
81
|
+
class Status; end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright 2017 Google LLC
|
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
|
+
# https://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
|
+
module Google
|
16
|
+
module Cloud
|
17
|
+
# rubocop:disable LineLength
|
18
|
+
|
19
|
+
##
|
20
|
+
# # Ruby Client for Stackdriver Trace API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
|
21
|
+
#
|
22
|
+
# [Stackdriver Trace API][Product Documentation]:
|
23
|
+
# Sends application trace data to Stackdriver Trace for viewing. Trace data is
|
24
|
+
# collected for all App Engine applications by default. Trace data from other
|
25
|
+
# applications can be provided using this API.
|
26
|
+
# - [Product Documentation][]
|
27
|
+
#
|
28
|
+
# ## Quick Start
|
29
|
+
# In order to use this library, you first need to go through the following
|
30
|
+
# steps:
|
31
|
+
#
|
32
|
+
# 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
|
33
|
+
# 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
|
34
|
+
# 3. [Enable the Stackdriver Trace API.](https://console.cloud.google.com/apis/api/trace)
|
35
|
+
# 4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
|
36
|
+
#
|
37
|
+
# ### Installation
|
38
|
+
# ```
|
39
|
+
# $ gem install google-cloud-trace
|
40
|
+
# ```
|
41
|
+
#
|
42
|
+
# ### Preview
|
43
|
+
# #### TraceServiceClient
|
44
|
+
# ```rb
|
45
|
+
# require "google/cloud/trace"
|
46
|
+
#
|
47
|
+
# trace_service_client = Google::Cloud::Trace.new
|
48
|
+
# formatted_name = Google::Cloud::Trace::V2::TraceServiceClient.project_path(project_id)
|
49
|
+
# spans = []
|
50
|
+
# trace_service_client.batch_write_spans(formatted_name, spans)
|
51
|
+
# ```
|
52
|
+
#
|
53
|
+
# ### Next Steps
|
54
|
+
# - Read the [Stackdriver Trace API Product documentation][Product Documentation]
|
55
|
+
# to learn more about the product and see How-to Guides.
|
56
|
+
# - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
|
57
|
+
# to see the full list of Cloud APIs that we cover.
|
58
|
+
#
|
59
|
+
# [Product Documentation]: https://cloud.google.com/trace
|
60
|
+
#
|
61
|
+
#
|
62
|
+
module Trace
|
63
|
+
module V2
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,364 @@
|
|
1
|
+
# Copyright 2017 Google LLC
|
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
|
+
# https://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
|
+
# EDITING INSTRUCTIONS
|
16
|
+
# This file was generated from the file
|
17
|
+
# https://github.com/googleapis/googleapis/blob/master/google/devtools/cloudtrace/v2/tracing.proto,
|
18
|
+
# and updates to that file get reflected here through a refresh process.
|
19
|
+
# For the short term, the refresh process will only be runnable by Google
|
20
|
+
# engineers.
|
21
|
+
#
|
22
|
+
# The only allowed edits are to method and file documentation. A 3-way
|
23
|
+
# merge preserves those additions if the generated source changes.
|
24
|
+
|
25
|
+
require "json"
|
26
|
+
require "pathname"
|
27
|
+
|
28
|
+
require "google/gax"
|
29
|
+
|
30
|
+
require "google/devtools/cloudtrace/v2/tracing_pb"
|
31
|
+
require "google/cloud/trace/credentials"
|
32
|
+
|
33
|
+
module Google
|
34
|
+
module Cloud
|
35
|
+
module Trace
|
36
|
+
module V2
|
37
|
+
# This file describes an API for collecting and viewing traces and spans
|
38
|
+
# within a trace. A Trace is a collection of spans corresponding to a single
|
39
|
+
# operation or set of operations for an application. A span is an individual
|
40
|
+
# timed event which forms a node of the trace tree. A single trace may
|
41
|
+
# contain span(s) from multiple services.
|
42
|
+
#
|
43
|
+
# @!attribute [r] trace_service_stub
|
44
|
+
# @return [Google::Devtools::Cloudtrace::V2::TraceService::Stub]
|
45
|
+
class TraceServiceClient
|
46
|
+
attr_reader :trace_service_stub
|
47
|
+
|
48
|
+
# The default address of the service.
|
49
|
+
SERVICE_ADDRESS = "cloudtrace.googleapis.com".freeze
|
50
|
+
|
51
|
+
# The default port of the service.
|
52
|
+
DEFAULT_SERVICE_PORT = 443
|
53
|
+
|
54
|
+
DEFAULT_TIMEOUT = 30
|
55
|
+
|
56
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
57
|
+
# this service.
|
58
|
+
ALL_SCOPES = [
|
59
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
60
|
+
"https://www.googleapis.com/auth/trace.append"
|
61
|
+
].freeze
|
62
|
+
|
63
|
+
|
64
|
+
PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
65
|
+
"projects/{project}"
|
66
|
+
)
|
67
|
+
|
68
|
+
private_constant :PROJECT_PATH_TEMPLATE
|
69
|
+
|
70
|
+
SPAN_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
71
|
+
"projects/{project}/traces/{trace}/spans/{span}"
|
72
|
+
)
|
73
|
+
|
74
|
+
private_constant :SPAN_PATH_TEMPLATE
|
75
|
+
|
76
|
+
# Returns a fully-qualified project resource name string.
|
77
|
+
# @param project [String]
|
78
|
+
# @return [String]
|
79
|
+
def self.project_path project
|
80
|
+
PROJECT_PATH_TEMPLATE.render(
|
81
|
+
:"project" => project
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns a fully-qualified span resource name string.
|
86
|
+
# @param project [String]
|
87
|
+
# @param trace [String]
|
88
|
+
# @param span [String]
|
89
|
+
# @return [String]
|
90
|
+
def self.span_path project, trace, span
|
91
|
+
SPAN_PATH_TEMPLATE.render(
|
92
|
+
:"project" => project,
|
93
|
+
:"trace" => trace,
|
94
|
+
:"span" => span
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
99
|
+
# Provides the means for authenticating requests made by the client. This parameter can
|
100
|
+
# be many types.
|
101
|
+
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
|
102
|
+
# authenticating requests made by this client.
|
103
|
+
# A `String` will be treated as the path to the keyfile to be used for the construction of
|
104
|
+
# credentials for this client.
|
105
|
+
# A `Hash` will be treated as the contents of a keyfile to be used for the construction of
|
106
|
+
# credentials for this client.
|
107
|
+
# A `GRPC::Core::Channel` will be used to make calls through.
|
108
|
+
# A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
|
109
|
+
# should already be composed with a `GRPC::Core::CallCredentials` object.
|
110
|
+
# A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
|
111
|
+
# metadata for requests, generally, to give OAuth credentials.
|
112
|
+
# @param scopes [Array<String>]
|
113
|
+
# The OAuth scopes for this service. This parameter is ignored if
|
114
|
+
# an updater_proc is supplied.
|
115
|
+
# @param client_config [Hash]
|
116
|
+
# A Hash for call options for each method. See
|
117
|
+
# Google::Gax#construct_settings for the structure of
|
118
|
+
# this data. Falls back to the default config if not specified
|
119
|
+
# or the specified config is missing data points.
|
120
|
+
# @param timeout [Numeric]
|
121
|
+
# The default timeout, in seconds, for calls made through this client.
|
122
|
+
def initialize \
|
123
|
+
credentials: nil,
|
124
|
+
scopes: ALL_SCOPES,
|
125
|
+
client_config: {},
|
126
|
+
timeout: DEFAULT_TIMEOUT,
|
127
|
+
lib_name: nil,
|
128
|
+
lib_version: ""
|
129
|
+
# These require statements are intentionally placed here to initialize
|
130
|
+
# the gRPC module only when it's required.
|
131
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
132
|
+
require "google/gax/grpc"
|
133
|
+
require "google/devtools/cloudtrace/v2/tracing_services_pb"
|
134
|
+
|
135
|
+
credentials ||= Google::Cloud::Trace::Credentials.default
|
136
|
+
|
137
|
+
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
138
|
+
updater_proc = Google::Cloud::Trace::Credentials.new(credentials).updater_proc
|
139
|
+
end
|
140
|
+
if credentials.is_a?(GRPC::Core::Channel)
|
141
|
+
channel = credentials
|
142
|
+
end
|
143
|
+
if credentials.is_a?(GRPC::Core::ChannelCredentials)
|
144
|
+
chan_creds = credentials
|
145
|
+
end
|
146
|
+
if credentials.is_a?(Proc)
|
147
|
+
updater_proc = credentials
|
148
|
+
end
|
149
|
+
if credentials.is_a?(Google::Auth::Credentials)
|
150
|
+
updater_proc = credentials.updater_proc
|
151
|
+
end
|
152
|
+
|
153
|
+
package_version = Gem.loaded_specs['google-cloud-trace'].version.version
|
154
|
+
|
155
|
+
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
156
|
+
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
157
|
+
google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
|
158
|
+
google_api_client << " grpc/#{GRPC::VERSION}"
|
159
|
+
google_api_client.freeze
|
160
|
+
|
161
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
162
|
+
client_config_file = Pathname.new(__dir__).join(
|
163
|
+
"trace_service_client_config.json"
|
164
|
+
)
|
165
|
+
defaults = client_config_file.open do |f|
|
166
|
+
Google::Gax.construct_settings(
|
167
|
+
"google.devtools.cloudtrace.v2.TraceService",
|
168
|
+
JSON.parse(f.read),
|
169
|
+
client_config,
|
170
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
171
|
+
timeout,
|
172
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
173
|
+
kwargs: headers
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Allow overriding the service path/port in subclasses.
|
178
|
+
service_path = self.class::SERVICE_ADDRESS
|
179
|
+
port = self.class::DEFAULT_SERVICE_PORT
|
180
|
+
@trace_service_stub = Google::Gax::Grpc.create_stub(
|
181
|
+
service_path,
|
182
|
+
port,
|
183
|
+
chan_creds: chan_creds,
|
184
|
+
channel: channel,
|
185
|
+
updater_proc: updater_proc,
|
186
|
+
scopes: scopes,
|
187
|
+
&Google::Devtools::Cloudtrace::V2::TraceService::Stub.method(:new)
|
188
|
+
)
|
189
|
+
|
190
|
+
@batch_write_spans = Google::Gax.create_api_call(
|
191
|
+
@trace_service_stub.method(:batch_write_spans),
|
192
|
+
defaults["batch_write_spans"]
|
193
|
+
)
|
194
|
+
@create_span = Google::Gax.create_api_call(
|
195
|
+
@trace_service_stub.method(:create_span),
|
196
|
+
defaults["create_span"]
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Service calls
|
201
|
+
|
202
|
+
# Sends new spans to new or existing traces. You cannot update
|
203
|
+
# existing spans.
|
204
|
+
#
|
205
|
+
# @param name [String]
|
206
|
+
# Required. The name of the project where the spans belong. The format is
|
207
|
+
# +projects/[PROJECT_ID]+.
|
208
|
+
# @param spans [Array<Google::Devtools::Cloudtrace::V2::Span | Hash>]
|
209
|
+
# A list of new spans. The span names must not match existing
|
210
|
+
# spans, or the results are undefined.
|
211
|
+
# A hash of the same form as `Google::Devtools::Cloudtrace::V2::Span`
|
212
|
+
# can also be provided.
|
213
|
+
# @param options [Google::Gax::CallOptions]
|
214
|
+
# Overrides the default settings for this call, e.g, timeout,
|
215
|
+
# retries, etc.
|
216
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
217
|
+
# @example
|
218
|
+
# require "google/cloud/trace/v2"
|
219
|
+
#
|
220
|
+
# trace_service_client = Google::Cloud::Trace::V2.new
|
221
|
+
# formatted_name = Google::Cloud::Trace::V2::TraceServiceClient.project_path("[PROJECT]")
|
222
|
+
# spans = []
|
223
|
+
# trace_service_client.batch_write_spans(formatted_name, spans)
|
224
|
+
|
225
|
+
def batch_write_spans \
|
226
|
+
name,
|
227
|
+
spans,
|
228
|
+
options: nil
|
229
|
+
req = {
|
230
|
+
name: name,
|
231
|
+
spans: spans
|
232
|
+
}.delete_if { |_, v| v.nil? }
|
233
|
+
req = Google::Gax::to_proto(req, Google::Devtools::Cloudtrace::V2::BatchWriteSpansRequest)
|
234
|
+
@batch_write_spans.call(req, options)
|
235
|
+
nil
|
236
|
+
end
|
237
|
+
|
238
|
+
# Creates a new span.
|
239
|
+
#
|
240
|
+
# @param name [String]
|
241
|
+
# The resource name of the span in the following format:
|
242
|
+
#
|
243
|
+
# projects/[PROJECT_ID]/traces/[TRACE_ID]/spans/[SPAN_ID]
|
244
|
+
#
|
245
|
+
# [TRACE_ID] is a unique identifier for a trace within a project;
|
246
|
+
# it is a 32-character hexadecimal encoding of a 16-byte array.
|
247
|
+
#
|
248
|
+
# [SPAN_ID] is a unique identifier for a span within a trace; it
|
249
|
+
# is a 16-character hexadecimal encoding of an 8-byte array.
|
250
|
+
# @param span_id [String]
|
251
|
+
# The [SPAN_ID] portion of the span's resource name.
|
252
|
+
# @param display_name [Google::Devtools::Cloudtrace::V2::TruncatableString | Hash]
|
253
|
+
# A description of the span's operation (up to 128 bytes).
|
254
|
+
# Stackdriver Trace displays the description in the
|
255
|
+
# {% dynamic print site_values.console_name %}.
|
256
|
+
# For example, the display name can be a qualified method name or a file name
|
257
|
+
# and a line number where the operation is called. A best practice is to use
|
258
|
+
# the same display name within an application and at the same call point.
|
259
|
+
# This makes it easier to correlate spans in different traces.
|
260
|
+
# A hash of the same form as `Google::Devtools::Cloudtrace::V2::TruncatableString`
|
261
|
+
# can also be provided.
|
262
|
+
# @param start_time [Google::Protobuf::Timestamp | Hash]
|
263
|
+
# The start time of the span. On the client side, this is the time kept by
|
264
|
+
# the local machine where the span execution starts. On the server side, this
|
265
|
+
# is the time when the server's application handler starts running.
|
266
|
+
# A hash of the same form as `Google::Protobuf::Timestamp`
|
267
|
+
# can also be provided.
|
268
|
+
# @param end_time [Google::Protobuf::Timestamp | Hash]
|
269
|
+
# The end time of the span. On the client side, this is the time kept by
|
270
|
+
# the local machine where the span execution ends. On the server side, this
|
271
|
+
# is the time when the server application handler stops running.
|
272
|
+
# A hash of the same form as `Google::Protobuf::Timestamp`
|
273
|
+
# can also be provided.
|
274
|
+
# @param parent_span_id [String]
|
275
|
+
# The [SPAN_ID] of this span's parent span. If this is a root span,
|
276
|
+
# then this field must be empty.
|
277
|
+
# @param attributes [Google::Devtools::Cloudtrace::V2::Span::Attributes | Hash]
|
278
|
+
# A set of attributes on the span. You can have up to 32 attributes per
|
279
|
+
# span.
|
280
|
+
# A hash of the same form as `Google::Devtools::Cloudtrace::V2::Span::Attributes`
|
281
|
+
# can also be provided.
|
282
|
+
# @param stack_trace [Google::Devtools::Cloudtrace::V2::StackTrace | Hash]
|
283
|
+
# Stack trace captured at the start of the span.
|
284
|
+
# A hash of the same form as `Google::Devtools::Cloudtrace::V2::StackTrace`
|
285
|
+
# can also be provided.
|
286
|
+
# @param time_events [Google::Devtools::Cloudtrace::V2::Span::TimeEvents | Hash]
|
287
|
+
# A set of time events. You can have up to 32 annotations and 128 message
|
288
|
+
# events per span.
|
289
|
+
# A hash of the same form as `Google::Devtools::Cloudtrace::V2::Span::TimeEvents`
|
290
|
+
# can also be provided.
|
291
|
+
# @param links [Google::Devtools::Cloudtrace::V2::Span::Links | Hash]
|
292
|
+
# Links associated with the span. You can have up to 128 links per Span.
|
293
|
+
# A hash of the same form as `Google::Devtools::Cloudtrace::V2::Span::Links`
|
294
|
+
# can also be provided.
|
295
|
+
# @param status [Google::Rpc::Status | Hash]
|
296
|
+
# An optional final status for this span.
|
297
|
+
# A hash of the same form as `Google::Rpc::Status`
|
298
|
+
# can also be provided.
|
299
|
+
# @param same_process_as_parent_span [Google::Protobuf::BoolValue | Hash]
|
300
|
+
# (Optional) Set this parameter to indicate whether this span is in
|
301
|
+
# the same process as its parent. If you do not set this parameter,
|
302
|
+
# Stackdriver Trace is unable to take advantage of this helpful
|
303
|
+
# information.
|
304
|
+
# A hash of the same form as `Google::Protobuf::BoolValue`
|
305
|
+
# can also be provided.
|
306
|
+
# @param child_span_count [Google::Protobuf::Int32Value | Hash]
|
307
|
+
# An optional number of child spans that were generated while this span
|
308
|
+
# was active. If set, allows implementation to detect missing child spans.
|
309
|
+
# A hash of the same form as `Google::Protobuf::Int32Value`
|
310
|
+
# can also be provided.
|
311
|
+
# @param options [Google::Gax::CallOptions]
|
312
|
+
# Overrides the default settings for this call, e.g, timeout,
|
313
|
+
# retries, etc.
|
314
|
+
# @return [Google::Devtools::Cloudtrace::V2::Span]
|
315
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
316
|
+
# @example
|
317
|
+
# require "google/cloud/trace/v2"
|
318
|
+
#
|
319
|
+
# trace_service_client = Google::Cloud::Trace::V2.new
|
320
|
+
# formatted_name = Google::Cloud::Trace::V2::TraceServiceClient.span_path("[PROJECT]", "[TRACE]", "[SPAN]")
|
321
|
+
# span_id = ''
|
322
|
+
# display_name = {}
|
323
|
+
# start_time = {}
|
324
|
+
# end_time = {}
|
325
|
+
# response = trace_service_client.create_span(formatted_name, span_id, display_name, start_time, end_time)
|
326
|
+
|
327
|
+
def create_span \
|
328
|
+
name,
|
329
|
+
span_id,
|
330
|
+
display_name,
|
331
|
+
start_time,
|
332
|
+
end_time,
|
333
|
+
parent_span_id: nil,
|
334
|
+
attributes: nil,
|
335
|
+
stack_trace: nil,
|
336
|
+
time_events: nil,
|
337
|
+
links: nil,
|
338
|
+
status: nil,
|
339
|
+
same_process_as_parent_span: nil,
|
340
|
+
child_span_count: nil,
|
341
|
+
options: nil
|
342
|
+
req = {
|
343
|
+
name: name,
|
344
|
+
span_id: span_id,
|
345
|
+
display_name: display_name,
|
346
|
+
start_time: start_time,
|
347
|
+
end_time: end_time,
|
348
|
+
parent_span_id: parent_span_id,
|
349
|
+
attributes: attributes,
|
350
|
+
stack_trace: stack_trace,
|
351
|
+
time_events: time_events,
|
352
|
+
links: links,
|
353
|
+
status: status,
|
354
|
+
same_process_as_parent_span: same_process_as_parent_span,
|
355
|
+
child_span_count: child_span_count
|
356
|
+
}.delete_if { |_, v| v.nil? }
|
357
|
+
req = Google::Gax::to_proto(req, Google::Devtools::Cloudtrace::V2::Span)
|
358
|
+
@create_span.call(req, options)
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|