google-cloud-trace 0.33.3 → 0.33.4
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/AUTHENTICATION.md +178 -0
- data/CHANGELOG.md +106 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +188 -0
- data/INSTRUMENTATION.md +60 -0
- data/LOGGING.md +32 -0
- data/OVERVIEW.md +161 -0
- data/TROUBLESHOOTING.md +37 -0
- data/lib/google/cloud/trace/version.rb +1 -1
- metadata +10 -3
- data/README.md +0 -250
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f65232342ef80608b2f8550bd38b0265d9594f9a0fee1537e7b5e9a47b992374
|
4
|
+
data.tar.gz: b002288b95f33f62d702cd714bbf512b188ddb1aaab672a7a9736fa1f300f2df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 517a2c8b4f5acc438cd17d863754bad9e0550ee34195a373116f199df735d720ebf771cb5c6b1a6c11f03e44c7236c0f616c8dcf10b44421a42ceeeb9d59cea2
|
7
|
+
data.tar.gz: 826ae7991412c32dd82570c31c081e1dc4c34cbb9d4dedff5f71107cd4f027392d921ea5f58dc5193d7d0f22f9a0ac835c2903937fe4c0b859a1b3c2991a17dd
|
data/AUTHENTICATION.md
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# Authentication
|
2
|
+
|
3
|
+
In general, the google-cloud-trace library uses [Service
|
4
|
+
Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
|
5
|
+
credentials to connect to Google Cloud services. When running on Compute Engine
|
6
|
+
the credentials will be discovered automatically. When running on other
|
7
|
+
environments, the Service Account credentials can be specified by providing the
|
8
|
+
path to the [JSON
|
9
|
+
keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys) for
|
10
|
+
the account (or the JSON itself) in environment variables. Additionally, Cloud
|
11
|
+
SDK credentials can also be discovered automatically, but this is only
|
12
|
+
recommended during development.
|
13
|
+
|
14
|
+
## Project and Credential Lookup
|
15
|
+
|
16
|
+
The google-cloud-trace library aims to make authentication as simple as
|
17
|
+
possible, and provides several mechanisms to configure your system without
|
18
|
+
providing **Project ID** and **Service Account Credentials** directly in code.
|
19
|
+
|
20
|
+
**Project ID** is discovered in the following order:
|
21
|
+
|
22
|
+
1. Specify project ID in method arguments
|
23
|
+
2. Specify project ID in configuration
|
24
|
+
3. Discover project ID in environment variables
|
25
|
+
4. Discover GCE project ID
|
26
|
+
|
27
|
+
**Credentials** are discovered in the following order:
|
28
|
+
|
29
|
+
1. Specify credentials in method arguments
|
30
|
+
2. Specify credentials in configuration
|
31
|
+
3. Discover credentials path in environment variables
|
32
|
+
4. Discover credentials JSON in environment variables
|
33
|
+
5. Discover credentials file in the Cloud SDK's path
|
34
|
+
6. Discover GCE credentials
|
35
|
+
|
36
|
+
### Google Cloud Platform environments
|
37
|
+
|
38
|
+
While running on Google Cloud Platform environments such as Google Compute
|
39
|
+
Engine, Google App Engine and Google Kubernetes Engine, no extra work is needed.
|
40
|
+
The **Project ID** and **Credentials** and are discovered automatically. Code
|
41
|
+
should be written as if already authenticated. Just be sure when you [set up the
|
42
|
+
GCE instance][gce-how-to], you add the correct scopes for the APIs you want to
|
43
|
+
access. For example:
|
44
|
+
|
45
|
+
* **All APIs**
|
46
|
+
* `https://www.googleapis.com/auth/cloud-platform`
|
47
|
+
* `https://www.googleapis.com/auth/cloud-platform.read-only`
|
48
|
+
* **BigQuery**
|
49
|
+
* `https://www.googleapis.com/auth/bigquery`
|
50
|
+
* `https://www.googleapis.com/auth/bigquery.insertdata`
|
51
|
+
* **Compute Engine**
|
52
|
+
* `https://www.googleapis.com/auth/compute`
|
53
|
+
* **Datastore**
|
54
|
+
* `https://www.googleapis.com/auth/datastore`
|
55
|
+
* `https://www.googleapis.com/auth/userinfo.email`
|
56
|
+
* **DNS**
|
57
|
+
* `https://www.googleapis.com/auth/ndev.clouddns.readwrite`
|
58
|
+
* **Pub/Sub**
|
59
|
+
* `https://www.googleapis.com/auth/pubsub`
|
60
|
+
* **Storage**
|
61
|
+
* `https://www.googleapis.com/auth/devstorage.full_control`
|
62
|
+
* `https://www.googleapis.com/auth/devstorage.read_only`
|
63
|
+
* `https://www.googleapis.com/auth/devstorage.read_write`
|
64
|
+
|
65
|
+
### Environment Variables
|
66
|
+
|
67
|
+
The **Project ID** and **Credentials JSON** can be placed in environment
|
68
|
+
variables instead of declaring them directly in code. Each service has its own
|
69
|
+
environment variable, allowing for different service accounts to be used for
|
70
|
+
different services. (See the READMEs for the individual service gems for
|
71
|
+
details.) The path to the **Credentials JSON** file can be stored in the
|
72
|
+
environment variable, or the **Credentials JSON** itself can be stored for
|
73
|
+
environments such as Docker containers where writing files is difficult or not
|
74
|
+
encouraged.
|
75
|
+
|
76
|
+
The environment variables that Trace checks for project ID are:
|
77
|
+
|
78
|
+
1. `TRACE_PROJECT`
|
79
|
+
2. `GOOGLE_CLOUD_PROJECT`
|
80
|
+
|
81
|
+
The environment variables that Trace checks for credentials are configured on {Google::Cloud::Trace::V1::Credentials}:
|
82
|
+
|
83
|
+
1. `TRACE_CREDENTIALS` - Path to JSON file, or JSON contents
|
84
|
+
2. `TRACE_KEYFILE` - Path to JSON file, or JSON contents
|
85
|
+
3. `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
|
86
|
+
4. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
|
87
|
+
5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require "google/cloud/trace"
|
91
|
+
|
92
|
+
ENV["TRACE_PROJECT"] = "my-project-id"
|
93
|
+
ENV["TRACE_CREDENTIALS"] = "path/to/keyfile.json"
|
94
|
+
|
95
|
+
trace = Google::Cloud::Trace.new
|
96
|
+
```
|
97
|
+
|
98
|
+
### Configuration
|
99
|
+
|
100
|
+
The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
require "google/cloud/trace"
|
104
|
+
|
105
|
+
Google::Cloud::Trace.configure do |config|
|
106
|
+
config.project_id = "my-project-id"
|
107
|
+
config.credentials = "path/to/keyfile.json"
|
108
|
+
end
|
109
|
+
|
110
|
+
trace = Google::Cloud::Trace.new
|
111
|
+
```
|
112
|
+
|
113
|
+
### Cloud SDK
|
114
|
+
|
115
|
+
This option allows for an easy way to authenticate during development. If
|
116
|
+
credentials are not provided in code or in environment variables, then Cloud SDK
|
117
|
+
credentials are discovered.
|
118
|
+
|
119
|
+
To configure your system for this, simply:
|
120
|
+
|
121
|
+
1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
|
122
|
+
2. Authenticate using OAuth 2.0 `$ gcloud auth login`
|
123
|
+
3. Write code as if already authenticated.
|
124
|
+
|
125
|
+
**NOTE:** This is _not_ recommended for running in production. The Cloud SDK
|
126
|
+
*should* only be used during development.
|
127
|
+
|
128
|
+
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
|
129
|
+
[dev-console]: https://console.cloud.google.com/project
|
130
|
+
|
131
|
+
[enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
|
132
|
+
|
133
|
+
[create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
|
134
|
+
[create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
|
135
|
+
[reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
|
136
|
+
|
137
|
+
## Creating a Service Account
|
138
|
+
|
139
|
+
Google Cloud requires a **Project ID** and **Service Account Credentials** to
|
140
|
+
connect to the APIs. You will use the **Project ID** and **JSON key file** to
|
141
|
+
connect to most services with google-cloud-trace.
|
142
|
+
|
143
|
+
If you are not running this client on Google Compute Engine, you need a Google
|
144
|
+
Developers service account.
|
145
|
+
|
146
|
+
1. Visit the [Google Developers Console][dev-console].
|
147
|
+
1. Create a new project or click on an existing project.
|
148
|
+
1. Activate the slide-out navigation tray and select **API Manager**. From
|
149
|
+
here, you will enable the APIs that your application requires.
|
150
|
+
|
151
|
+
![Enable the APIs that your application requires][enable-apis]
|
152
|
+
|
153
|
+
*Note: You may need to enable billing in order to use these services.*
|
154
|
+
|
155
|
+
1. Select **Credentials** from the side navigation.
|
156
|
+
|
157
|
+
You should see a screen like one of the following.
|
158
|
+
|
159
|
+
![Create a new service account][create-new-service-account]
|
160
|
+
|
161
|
+
![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
|
162
|
+
|
163
|
+
Find the "Add credentials" drop down and select "Service account" to be
|
164
|
+
guided through downloading a new JSON key file.
|
165
|
+
|
166
|
+
If you want to re-use an existing service account, you can easily generate a
|
167
|
+
new key file. Just select the account you wish to re-use, and click "Generate
|
168
|
+
new JSON key":
|
169
|
+
|
170
|
+
![Re-use an existing service account][reuse-service-account]
|
171
|
+
|
172
|
+
The key file you download will be used by this library to authenticate API
|
173
|
+
requests and should be stored in a secure location.
|
174
|
+
|
175
|
+
## Troubleshooting
|
176
|
+
|
177
|
+
If you're having trouble authenticating you can ask for help by following the
|
178
|
+
{file:TROUBLESHOOTING.md Troubleshooting Guide}.
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Release History
|
2
|
+
|
3
|
+
### 0.33.4 / 2018-09-12
|
4
|
+
|
5
|
+
* Add missing documentation files to package.
|
6
|
+
|
7
|
+
### 0.33.3 / 2018-09-10
|
8
|
+
|
9
|
+
* Update documentation.
|
10
|
+
|
11
|
+
### 0.33.2 / 2018-08-21
|
12
|
+
|
13
|
+
* Update documentation.
|
14
|
+
|
15
|
+
### 0.33.1 / 2018-07-05
|
16
|
+
|
17
|
+
* Fix issue when disabling Stackdriver components with Rails.env.production.
|
18
|
+
* Add /healthz to the ignored requests. (diegodurs)
|
19
|
+
* Add documentation for enabling gRPC logging.
|
20
|
+
|
21
|
+
### 0.33.0 / 2018-05-01
|
22
|
+
|
23
|
+
* Fix labels in Trace. (tareksamni)
|
24
|
+
|
25
|
+
### 0.31.0 / 2018-02-27
|
26
|
+
|
27
|
+
* Use Google Cloud Shared Configuration.
|
28
|
+
* Update authentication documentation.
|
29
|
+
|
30
|
+
### 0.30.0 / 2017-12-26
|
31
|
+
|
32
|
+
* Add `Google::Cloud::Trace::V2::TraceServiceClient` class.
|
33
|
+
|
34
|
+
### 0.29.0 / 2017-12-19
|
35
|
+
|
36
|
+
* Update google-gax dependency to 1.0.
|
37
|
+
|
38
|
+
### 0.28.1 / 2017-11-15
|
39
|
+
|
40
|
+
* Fix credentials verification bug in Railtie.
|
41
|
+
|
42
|
+
### 0.28.0 / 2017-11-14
|
43
|
+
|
44
|
+
* Add `Google::Cloud::Trace::Credentials` class.
|
45
|
+
* Rename constructor arguments to `project_id` and `credentials`.
|
46
|
+
(The previous arguments `project` and `keyfile` are still supported.)
|
47
|
+
* Document `Google::Auth::Credentials` as `credentials` value.
|
48
|
+
* Update generated low level GAPIC code.
|
49
|
+
* Updated `google-gax` (`grpc`, `google-protobuf`), `googleauth` dependencies.
|
50
|
+
|
51
|
+
### 0.27.2 / 2017-09-20
|
52
|
+
|
53
|
+
* Fix the bug where `Google::Cloud::Trace::Middleware` wasn't using the shared `project_id` parameter.
|
54
|
+
|
55
|
+
### 0.27.1 / 2017-09-08
|
56
|
+
|
57
|
+
* Print captured exception from asynchronous worker thread.
|
58
|
+
|
59
|
+
### 0.27.0 / 2017-08-07
|
60
|
+
|
61
|
+
* Add instrumentation to collect outbound GRPC requests information.
|
62
|
+
|
63
|
+
### 0.26.1 / 2017-07-11
|
64
|
+
|
65
|
+
* stackdriver-core 1.2.0 release
|
66
|
+
|
67
|
+
### 0.26.0 / 2017-07-11
|
68
|
+
|
69
|
+
* Add Faraday Middleware to help collect outbound RPC information.
|
70
|
+
* Update `Google::Cloud::Trace::Middleware` and `Google::Cloud::Trace::Railtie` to submit trace spans asynchronously by default.
|
71
|
+
* Update GAPIC configuration to exclude `UNAVAILABLE` errors from automatic retry.
|
72
|
+
|
73
|
+
### 0.25.0 / 2017-05-25
|
74
|
+
|
75
|
+
* Introduce new `Google::Cloud::Trace.configure` instrumentation configuration interface.
|
76
|
+
|
77
|
+
### 0.24.1 / 2017-04-21
|
78
|
+
|
79
|
+
* If Rails integration fails due to an auth error, the notice is now printed to STDOUT rather than STDERR, which should make it a bit less scary when displayed in Docker output.
|
80
|
+
|
81
|
+
### 0.24.0 / 2017-03-31
|
82
|
+
|
83
|
+
* Updated documentation
|
84
|
+
* Automatic retry on `UNAVAILABLE` errors
|
85
|
+
|
86
|
+
### 0.23.2 / 2017-03-03
|
87
|
+
|
88
|
+
* Update GRPC header value sent to the Trace API.
|
89
|
+
|
90
|
+
### 0.23.1 / 2017-03-01
|
91
|
+
|
92
|
+
* Update GRPC header value sent to the Trace API.
|
93
|
+
|
94
|
+
### 0.23.0 / 2017-02-21
|
95
|
+
|
96
|
+
* Fix GRPC retry bug
|
97
|
+
* The client_config data structure has replaced retry_codes/retry_codes_def with retry_codes
|
98
|
+
* Update GRPC/Protobuf/GAX dependencies
|
99
|
+
|
100
|
+
### 0.22.0 / 2017-01-27
|
101
|
+
|
102
|
+
* Change class names in low-level API (GAPIC)
|
103
|
+
|
104
|
+
### 0.21.0 / 2016-12-22
|
105
|
+
|
106
|
+
* Initial release of google-cloud-trace, providing an API client and application instrumentation.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct.
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or reject
|
24
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
25
|
+
not aligned to this Code of Conduct. By adopting this Code of Conduct, project
|
26
|
+
maintainers commit themselves to fairly and consistently applying these
|
27
|
+
principles to every aspect of managing this project. Project maintainers who do
|
28
|
+
not follow or enforce the Code of Conduct may be permanently removed from the
|
29
|
+
project team.
|
30
|
+
|
31
|
+
This code of conduct applies both within project spaces and in public spaces
|
32
|
+
when an individual is representing the project or its community.
|
33
|
+
|
34
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
35
|
+
reported by opening an issue or contacting one or more of the project
|
36
|
+
maintainers.
|
37
|
+
|
38
|
+
This Code of Conduct is adapted from the [Contributor
|
39
|
+
Covenant](http://contributor-covenant.org), version 1.2.0, available at
|
40
|
+
[http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# Contributing to Google Cloud Trace
|
2
|
+
|
3
|
+
1. **Sign one of the contributor license agreements below.**
|
4
|
+
2. Fork the repo, develop and test your code changes.
|
5
|
+
3. Send a pull request.
|
6
|
+
|
7
|
+
## Contributor License Agreements
|
8
|
+
|
9
|
+
Before we can accept your pull requests you'll need to sign a Contributor
|
10
|
+
License Agreement (CLA):
|
11
|
+
|
12
|
+
- **If you are an individual writing original source code** and **you own the
|
13
|
+
intellectual property**, then you'll need to sign an [individual
|
14
|
+
CLA](https://developers.google.com/open-source/cla/individual).
|
15
|
+
- **If you work for a company that wants to allow you to contribute your work**,
|
16
|
+
then you'll need to sign a [corporate
|
17
|
+
CLA](https://developers.google.com/open-source/cla/corporate).
|
18
|
+
|
19
|
+
You can sign these electronically (just scroll to the bottom). After that, we'll
|
20
|
+
be able to accept your pull requests.
|
21
|
+
|
22
|
+
## Setup
|
23
|
+
|
24
|
+
In order to use the google-cloud-trace console and run the project's tests,
|
25
|
+
there is a small amount of setup:
|
26
|
+
|
27
|
+
1. Install Ruby. google-cloud-trace requires Ruby 2.3+. You may choose to
|
28
|
+
manage your Ruby and gem installations with [RVM](https://rvm.io/),
|
29
|
+
[rbenv](https://github.com/rbenv/rbenv), or
|
30
|
+
[chruby](https://github.com/postmodern/chruby).
|
31
|
+
|
32
|
+
2. Install [Bundler](http://bundler.io/).
|
33
|
+
|
34
|
+
```sh
|
35
|
+
$ gem install bundler
|
36
|
+
```
|
37
|
+
|
38
|
+
3. Install the top-level project dependencies.
|
39
|
+
|
40
|
+
```sh
|
41
|
+
$ bundle install
|
42
|
+
```
|
43
|
+
|
44
|
+
4. Install the Trace dependencies.
|
45
|
+
|
46
|
+
```sh
|
47
|
+
$ cd google-cloud-trace/
|
48
|
+
$ bundle exec rake bundleupdate
|
49
|
+
```
|
50
|
+
|
51
|
+
## Console
|
52
|
+
|
53
|
+
In order to run code interactively, you can automatically load
|
54
|
+
google-cloud-trace and its dependencies in IRB. This requires that your
|
55
|
+
developer environment has already been configured by following the steps
|
56
|
+
described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
|
57
|
+
can be created with:
|
58
|
+
|
59
|
+
```sh
|
60
|
+
$ cd google-cloud-trace/
|
61
|
+
$ bundle exec rake console
|
62
|
+
```
|
63
|
+
|
64
|
+
## Trace Tests
|
65
|
+
|
66
|
+
Tests are very important part of google-cloud-trace. All contributions
|
67
|
+
should include tests that ensure the contributed code behaves as expected.
|
68
|
+
|
69
|
+
To run the unit tests, documentation tests, and code style checks together for a
|
70
|
+
package:
|
71
|
+
|
72
|
+
``` sh
|
73
|
+
$ cd google-cloud-trace/
|
74
|
+
$ bundle exec rake ci
|
75
|
+
```
|
76
|
+
|
77
|
+
To run the command above, plus all acceptance tests, use `rake ci:acceptance` or
|
78
|
+
its handy alias, `rake ci:a`.
|
79
|
+
|
80
|
+
### Trace Unit Tests
|
81
|
+
|
82
|
+
|
83
|
+
The project uses the [minitest](https://github.com/seattlerb/minitest) library,
|
84
|
+
including [specs](https://github.com/seattlerb/minitest#specs),
|
85
|
+
[mocks](https://github.com/seattlerb/minitest#mocks) and
|
86
|
+
[minitest-autotest](https://github.com/seattlerb/minitest-autotest).
|
87
|
+
|
88
|
+
To run the Trace unit tests:
|
89
|
+
|
90
|
+
``` sh
|
91
|
+
$ cd google-cloud-trace/
|
92
|
+
$ bundle exec rake test
|
93
|
+
```
|
94
|
+
|
95
|
+
### Trace Documentation Tests
|
96
|
+
|
97
|
+
The project tests the code examples in the gem's
|
98
|
+
[YARD](https://github.com/lsegal/yard)-based documentation.
|
99
|
+
|
100
|
+
The example testing functions in a way that is very similar to unit testing, and
|
101
|
+
in fact the library providing it,
|
102
|
+
[yard-doctest](https://github.com/p0deje/yard-doctest), is based on the
|
103
|
+
project's unit test library, [minitest](https://github.com/seattlerb/minitest).
|
104
|
+
|
105
|
+
To run the Trace documentation tests:
|
106
|
+
|
107
|
+
``` sh
|
108
|
+
$ cd google-cloud-trace/
|
109
|
+
$ bundle exec rake doctest
|
110
|
+
```
|
111
|
+
|
112
|
+
If you add, remove or modify documentation examples when working on a pull
|
113
|
+
request, you may need to update the setup for the tests. The stubs and mocks
|
114
|
+
required to run the tests are located in `support/doctest_helper.rb`. Please
|
115
|
+
note that much of the setup is matched by the title of the
|
116
|
+
[`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag.
|
117
|
+
If you alter an example's title, you may encounter breaking tests.
|
118
|
+
|
119
|
+
### Trace Acceptance Tests
|
120
|
+
|
121
|
+
The Trace acceptance tests interact with the live service API. Follow the
|
122
|
+
instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
|
123
|
+
the Trace API. Occasionally, some API features may not yet be generally
|
124
|
+
available, making it difficult for some contributors to successfully run the
|
125
|
+
entire acceptance test suite. However, please ensure that you do successfully
|
126
|
+
run acceptance tests for any code areas covered by your pull request.
|
127
|
+
|
128
|
+
To run the acceptance tests, first create and configure a project in the Google
|
129
|
+
Developers Console, as described in the {file:AUTHENTICATION.md Authentication
|
130
|
+
guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
|
131
|
+
the KEYFILE location on your system.
|
132
|
+
|
133
|
+
Before you can run the Trace acceptance tests, you must first create indexes
|
134
|
+
used in the tests.
|
135
|
+
|
136
|
+
#### Running the Trace acceptance tests
|
137
|
+
|
138
|
+
To run the Trace acceptance tests:
|
139
|
+
|
140
|
+
``` sh
|
141
|
+
$ cd google-cloud-trace/
|
142
|
+
$ bundle exec rake acceptance[\\{my-project-id},\\{/path/to/keyfile.json}]
|
143
|
+
```
|
144
|
+
|
145
|
+
Or, if you prefer you can store the values in the `GCLOUD_TEST_PROJECT` and
|
146
|
+
`GCLOUD_TEST_KEYFILE` environment variables:
|
147
|
+
|
148
|
+
``` sh
|
149
|
+
$ cd google-cloud-trace/
|
150
|
+
$ export GCLOUD_TEST_PROJECT=\\{my-project-id}
|
151
|
+
$ export GCLOUD_TEST_KEYFILE=\\{/path/to/keyfile.json}
|
152
|
+
$ bundle exec rake acceptance
|
153
|
+
```
|
154
|
+
|
155
|
+
If you want to use a different project and credentials for acceptance tests, you
|
156
|
+
can use the more specific `TRACE_TEST_PROJECT` and `TRACE_TEST_KEYFILE`
|
157
|
+
environment variables:
|
158
|
+
|
159
|
+
``` sh
|
160
|
+
$ cd google-cloud-trace/
|
161
|
+
$ export TRACE_TEST_PROJECT=\\{my-project-id}
|
162
|
+
$ export TRACE_TEST_KEYFILE=\\{/path/to/keyfile.json}
|
163
|
+
$ bundle exec rake acceptance
|
164
|
+
```
|
165
|
+
|
166
|
+
## Coding Style
|
167
|
+
|
168
|
+
Please follow the established coding style in the library. The style is is
|
169
|
+
largely based on [The Ruby Style
|
170
|
+
Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based
|
171
|
+
on seattle-style:
|
172
|
+
|
173
|
+
* Avoid parenthesis when possible, including in method definitions.
|
174
|
+
* Always use double quotes strings. ([Option
|
175
|
+
B](https://github.com/bbatsov/ruby-style-guide#strings))
|
176
|
+
|
177
|
+
You can check your code against these rules by running Rubocop like so:
|
178
|
+
|
179
|
+
```sh
|
180
|
+
$ cd google-cloud-trace/
|
181
|
+
$ bundle exec rake rubocop
|
182
|
+
```
|
183
|
+
|
184
|
+
## Code of Conduct
|
185
|
+
|
186
|
+
Please note that this project is released with a Contributor Code of Conduct. By
|
187
|
+
participating in this project you agree to abide by its terms. See
|
188
|
+
{file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
|
data/INSTRUMENTATION.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Stackdriver Trace Instrumentation
|
2
|
+
|
3
|
+
Then google-cloud-trace gem provides a Rack Middleware class that integrates
|
4
|
+
with Rack-based application frameworks, such as Rails and Sinatra. When
|
5
|
+
installed, the middleware collects performance traces of requests and, subject
|
6
|
+
to sampling constraints, submits them to the Stackdriver Trace service.
|
7
|
+
|
8
|
+
Additionally, the google-cloud-trace gem provides a Railtie class that
|
9
|
+
automatically enables the Rack Middleware in Rails applications when used.
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
The default configuration enables Stackdriver instrumentation features to run on
|
14
|
+
Google Cloud Platform. You can easily configure the instrumentation library if
|
15
|
+
you want to run on a non Google Cloud environment or you want to customize the
|
16
|
+
default behavior.
|
17
|
+
|
18
|
+
See the [Configuration
|
19
|
+
Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION)
|
20
|
+
for full configuration parameters.
|
21
|
+
|
22
|
+
## Rails Integration
|
23
|
+
|
24
|
+
To use the Stackdriver Logging Railtie for Ruby on Rails applications, simply
|
25
|
+
add this line to `config/application.rb`:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require "google/cloud/trace/rails"
|
29
|
+
```
|
30
|
+
|
31
|
+
Alternatively, check out the
|
32
|
+
[stackdriver](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/stackdriver)
|
33
|
+
gem, which enables this Railtie by default.
|
34
|
+
|
35
|
+
## Rack Integration
|
36
|
+
|
37
|
+
Other Rack base frameworks can also directly leverage the built-in Middleware.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require "google/cloud/trace"
|
41
|
+
use Google::Cloud::Trace::Middleware
|
42
|
+
```
|
43
|
+
|
44
|
+
## Faraday Middleware
|
45
|
+
|
46
|
+
On top of the Rack Middleware, you can also trace outbound Faraday requests by
|
47
|
+
using the Faraday Middleware provided with this gem:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require "google/cloud/trace/faraday_middleware"
|
51
|
+
|
52
|
+
conn = Faraday.new "https://www.google.com"
|
53
|
+
conn.use Google::Cloud::Trace::FaradayMiddleware
|
54
|
+
|
55
|
+
result = conn.get
|
56
|
+
```
|
57
|
+
|
58
|
+
A child span will be create for each outbound Faraday request, and will be
|
59
|
+
submitted together with the overall application request trace by the Rack
|
60
|
+
Middleware.
|
data/LOGGING.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Enabling gRPC Logging
|
2
|
+
|
3
|
+
To enable logging for this library, set the logger for the underlying
|
4
|
+
[gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
|
5
|
+
that you set may be a Ruby stdlib
|
6
|
+
[`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
|
7
|
+
shown below, or a
|
8
|
+
[`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger)
|
9
|
+
that will write logs to [Stackdriver
|
10
|
+
Logging](https://cloud.google.com/logging/). See
|
11
|
+
[grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
|
12
|
+
and the gRPC
|
13
|
+
[spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb)
|
14
|
+
for additional information.
|
15
|
+
|
16
|
+
Configuring a Ruby stdlib logger:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require "logger"
|
20
|
+
|
21
|
+
module MyLogger
|
22
|
+
LOGGER = Logger.new $stderr, level: Logger::WARN
|
23
|
+
def logger
|
24
|
+
LOGGER
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
|
29
|
+
module GRPC
|
30
|
+
extend MyLogger
|
31
|
+
end
|
32
|
+
```
|
data/OVERVIEW.md
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Stackdriver Trace
|
2
|
+
|
3
|
+
The Stackdriver Trace service collects and stores latency data from your
|
4
|
+
application and displays it in the Google Cloud Platform Console, giving
|
5
|
+
you detailed near-real-time insight into application performance.
|
6
|
+
|
7
|
+
The Stackdriver Trace Ruby library, `google-cloud-trace`, provides:
|
8
|
+
|
9
|
+
* Easy-to-use trace instrumentation that collects and collates latency
|
10
|
+
data for your Ruby application. If you just want latency trace data
|
11
|
+
for your application to appear on the Google Cloud Platform Console,
|
12
|
+
see the section on [instrumenting your app](#instrumenting-your-app).
|
13
|
+
* An idiomatic Ruby API for querying, analyzing, and manipulating trace
|
14
|
+
data in your Ruby application. For an introduction to the Trace API,
|
15
|
+
see the section on the [Trace API](#stackdriver-trace-api).
|
16
|
+
|
17
|
+
## Instrumenting Your App
|
18
|
+
|
19
|
+
This library integrates with Rack-based web frameworks such as Ruby On
|
20
|
+
Rails to provide latency trace reports for your application.
|
21
|
+
Specifcally, it:
|
22
|
+
|
23
|
+
* Provides a Rack middleware that automatically reports latency traces
|
24
|
+
for http requests handled by your application, and measures the
|
25
|
+
latency of each request as a whole.
|
26
|
+
* Integrates with `ActiveSupport::Notifications` to add important
|
27
|
+
latency-affecting events such as ActiveRecord queries to the trace.
|
28
|
+
* Provides a simple API for your application code to define and
|
29
|
+
measure latency-affecting processes specific to your application.
|
30
|
+
|
31
|
+
When this library is installed and configured in your running
|
32
|
+
application, you can view your application's latency traces in real time
|
33
|
+
by opening the Google Cloud Console in your web browser and navigating
|
34
|
+
to the "Trace" section. It also integrates with Google App Engine
|
35
|
+
Flexible and Google Container Engine to provide additional information
|
36
|
+
for applications hosted in those environments.
|
37
|
+
|
38
|
+
Note that not all requests will have traces. By default, the library will
|
39
|
+
sample about one trace every ten seconds per Ruby process, to prevent
|
40
|
+
heavily used applications from reporting too much data. It will also
|
41
|
+
omit certain requests used by Google App Engine for health checking. See
|
42
|
+
{Google::Cloud::Trace::TimeSampler} for more details.
|
43
|
+
|
44
|
+
### Using instrumentation with Ruby on Rails
|
45
|
+
|
46
|
+
To install application instrumentation in your Ruby on Rails app, add
|
47
|
+
this gem, `google-cloud-trace`, to your Gemfile and update your bundle.
|
48
|
+
Then add the following line to your `config/application.rb` file:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require "google/cloud/trace/rails"
|
52
|
+
```
|
53
|
+
|
54
|
+
This will install a Railtie that automatically integrates with the
|
55
|
+
Rails framework, installing the middleware and the ActiveSupport
|
56
|
+
integration for you. Your application traces, including basic request
|
57
|
+
tracing, ActiveRecord query measurements, and view render measurements,
|
58
|
+
should then start appearing in the Cloud Console.
|
59
|
+
|
60
|
+
See the {Google::Cloud::Trace::Railtie} class for more information,
|
61
|
+
including how to customize your application traces.
|
62
|
+
|
63
|
+
### Using instrumentation with Sinatra
|
64
|
+
|
65
|
+
To install application instrumentation in your Sinatra app, add this gem,
|
66
|
+
`google-cloud-trace`, to your Gemfile and update your bundle. Then add
|
67
|
+
the following lines to your main application Ruby file:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
require "google/cloud/trace"
|
71
|
+
use Google::Cloud::Trace::Middleware
|
72
|
+
```
|
73
|
+
|
74
|
+
This will install the trace middleware in your application, providing
|
75
|
+
basic request tracing for your application. You may measure additional
|
76
|
+
processes such as database queries or calls to external services using
|
77
|
+
other classes in this library. See the {Google::Cloud::Trace::Middleware}
|
78
|
+
documentation for more information.
|
79
|
+
|
80
|
+
### Using instrumentation with other Rack-based frameworks
|
81
|
+
|
82
|
+
To install application instrumentation in an app using another Rack-based
|
83
|
+
web framework, add this gem, `google-cloud-trace`, to your Gemfile and
|
84
|
+
update your bundle. Then add install the trace middleware in your
|
85
|
+
middleware stack. In most cases, this means adding these lines to your
|
86
|
+
`config.ru` Rack configuration file:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
require "google/cloud/trace"
|
90
|
+
use Google::Cloud::Trace::Middleware
|
91
|
+
```
|
92
|
+
|
93
|
+
Some web frameworks have an alternate mechanism for modifying the
|
94
|
+
middleware stack. Consult your web framework's documentation for more
|
95
|
+
information.
|
96
|
+
|
97
|
+
### The Stackdriver diagnostics suite
|
98
|
+
|
99
|
+
The trace library is part of the Stackdriver diagnostics suite, which
|
100
|
+
also includes error reporting and log analysis. If you include the
|
101
|
+
`stackdriver` gem in your Gemfile, this trace library will be included
|
102
|
+
automatically. In addition, if you include the `stackdriver` gem in an
|
103
|
+
application using Ruby On Rails, the Railtie will be installed
|
104
|
+
automatically; you will not need to write any code to view latency
|
105
|
+
traces for your appl. See the documentation for the "stackdriver" gem
|
106
|
+
for more details.
|
107
|
+
|
108
|
+
## Stackdriver Trace API
|
109
|
+
|
110
|
+
This library also includes an easy to use Ruby client for the
|
111
|
+
Stackdriver Trace API. This API provides calls to report and modify
|
112
|
+
application traces, as well as to query and analyze existing traces.
|
113
|
+
|
114
|
+
For further information on the trace API, see
|
115
|
+
{Google::Cloud::Trace::Project}.
|
116
|
+
|
117
|
+
### Querying traces using the API
|
118
|
+
|
119
|
+
Using the Stackdriver Trace API, your application can query and analyze
|
120
|
+
its own traces and traces of other projects. Here is an example query
|
121
|
+
for all traces in the past hour.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
require "google/cloud/trace"
|
125
|
+
trace_client = Google::Cloud::Trace.new
|
126
|
+
|
127
|
+
traces = trace_client.list_traces Time.now - 3600, Time.now
|
128
|
+
traces.each do |trace|
|
129
|
+
puts "Retrieved trace ID: #{trace.trace_id}"
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
133
|
+
Each trace is an object of type {Google::Cloud::Trace::TraceRecord},
|
134
|
+
which provides methods for analyzing tasks that took place during the
|
135
|
+
request trace. See https://cloud.google.com/trace for more information
|
136
|
+
on the kind of data you can capture in a trace.
|
137
|
+
|
138
|
+
### Reporting traces using the API
|
139
|
+
|
140
|
+
Usually it is easiest to use this library's trace instrumentation
|
141
|
+
features to collect and record application trace information. However,
|
142
|
+
you may also use the trace API to update this data. Here is an example:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
require "google/cloud/trace"
|
146
|
+
|
147
|
+
trace_client = Google::Cloud::Trace.new
|
148
|
+
|
149
|
+
trace = Google::Cloud::Trace.new
|
150
|
+
trace.in_span "root_span" do
|
151
|
+
# Do stuff...
|
152
|
+
end
|
153
|
+
|
154
|
+
trace_client.patch_traces trace
|
155
|
+
```
|
156
|
+
|
157
|
+
## Additional information
|
158
|
+
|
159
|
+
Stackdriver Trace can be configured to be used in Rack applications or to use
|
160
|
+
gRPC's logging. To learn more, see the {file:INSTRUMENTATION.md Instrumentation
|
161
|
+
Guide} and {file:LOGGING.md Logging guide}.
|
data/TROUBLESHOOTING.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Troubleshooting
|
2
|
+
|
3
|
+
## Where can I get more help?
|
4
|
+
|
5
|
+
### Ask the Community
|
6
|
+
|
7
|
+
If you have a question about how to use a Google Cloud client library in your
|
8
|
+
project or are stuck in the Developer's console and don't know where to turn,
|
9
|
+
it's possible your questions have already been addressed by the community.
|
10
|
+
|
11
|
+
First, check out the appropriate tags on StackOverflow:
|
12
|
+
- [`google-cloud-platform+ruby+trace`][so-ruby]
|
13
|
+
|
14
|
+
Next, try searching through the issues on GitHub:
|
15
|
+
|
16
|
+
- [`api:trace` issues][gh-search-ruby]
|
17
|
+
|
18
|
+
Still nothing?
|
19
|
+
|
20
|
+
### Ask the Developers
|
21
|
+
|
22
|
+
If you're experiencing a bug with the code, or have an idea for how it can be
|
23
|
+
improved, *please* create a new issue on GitHub so we can talk about it.
|
24
|
+
|
25
|
+
- [New issue][gh-ruby]
|
26
|
+
|
27
|
+
Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
|
28
|
+
can use the "ruby" channel for general Ruby questions, or use the
|
29
|
+
"google-cloud-ruby" channel if you have questions about this gem in particular.
|
30
|
+
|
31
|
+
[so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+trace
|
32
|
+
|
33
|
+
[gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+trace%22
|
34
|
+
|
35
|
+
[gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
|
36
|
+
|
37
|
+
[slack-ruby]: https://gcp-slack.appspot.com/
|
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.33.
|
4
|
+
version: 0.33.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-core
|
@@ -242,8 +242,15 @@ extensions: []
|
|
242
242
|
extra_rdoc_files: []
|
243
243
|
files:
|
244
244
|
- ".yardopts"
|
245
|
+
- AUTHENTICATION.md
|
246
|
+
- CHANGELOG.md
|
247
|
+
- CODE_OF_CONDUCT.md
|
248
|
+
- CONTRIBUTING.md
|
249
|
+
- INSTRUMENTATION.md
|
245
250
|
- LICENSE
|
246
|
-
-
|
251
|
+
- LOGGING.md
|
252
|
+
- OVERVIEW.md
|
253
|
+
- TROUBLESHOOTING.md
|
247
254
|
- lib/google-cloud-trace.rb
|
248
255
|
- lib/google/cloud/trace.rb
|
249
256
|
- lib/google/cloud/trace/async_reporter.rb
|
data/README.md
DELETED
@@ -1,250 +0,0 @@
|
|
1
|
-
# google-cloud-trace
|
2
|
-
|
3
|
-
[Stackdriver Trace](https://cloud.google.com/trace/) is a distributed tracing
|
4
|
-
system that collects latency data from your applications and displays it in the
|
5
|
-
Google Cloud Platform Console. You can track how requests propagate through your
|
6
|
-
application and receive detailed near real-time performance insights.
|
7
|
-
Stackdriver Trace automatically analyzes all of your application's traces to
|
8
|
-
generate in-depth latency reports to surface performance degradations, and can
|
9
|
-
capture traces from all of your VMs, containers, or Google App Engine projects.
|
10
|
-
|
11
|
-
- [google-cloud-trace API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-trace/latest)
|
12
|
-
- [google-cloud-trace instrumentation documentation](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-trace/latest/file.INSTRUMENTATION)
|
13
|
-
- [google-cloud-trace on RubyGems](https://rubygems.org/gems/google-cloud-trace)
|
14
|
-
- [Stackdriver Trace documentation](https://cloud.google.com/trace/docs/)
|
15
|
-
|
16
|
-
## Quick Start
|
17
|
-
|
18
|
-
Install the gem directly:
|
19
|
-
|
20
|
-
```sh
|
21
|
-
$ gem install google-cloud-trace
|
22
|
-
```
|
23
|
-
|
24
|
-
Or install through Bundler:
|
25
|
-
|
26
|
-
1. Add the `google-cloud-trace` gem to your Gemfile:
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
gem "google-cloud-trace"
|
30
|
-
```
|
31
|
-
|
32
|
-
2. Use Bundler to install the gem:
|
33
|
-
|
34
|
-
```sh
|
35
|
-
$ bundle install
|
36
|
-
```
|
37
|
-
|
38
|
-
Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
|
39
|
-
the `google-cloud-trace` gem.
|
40
|
-
|
41
|
-
## Enable Stackdriver Trace API
|
42
|
-
|
43
|
-
The Stackdriver Trace library needs the [Stackdriver Trace
|
44
|
-
API](https://console.cloud.google.com/apis/library/cloudtrace.googleapis.com)
|
45
|
-
to be enabled on your Google Cloud project. Make sure it's enabled if not
|
46
|
-
already.
|
47
|
-
|
48
|
-
## Tracing on Rack-based frameworks
|
49
|
-
|
50
|
-
The Stackdriver Trace library for Ruby makes it easy to integrate Stackdriver
|
51
|
-
Trace into popular Rack-based Ruby web frameworks such as Ruby on Rails and
|
52
|
-
Sinatra. When the library integration is enabled, it automatically traces
|
53
|
-
incoming requests in the application.
|
54
|
-
|
55
|
-
### With Ruby on Rails
|
56
|
-
|
57
|
-
You can load the Railtie that comes with the library into your Ruby
|
58
|
-
on Rails application by explicitly requiring it during the application startup:
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
# In config/application.rb
|
62
|
-
require "google/cloud/trace/rails"
|
63
|
-
```
|
64
|
-
|
65
|
-
If you're using the `stackdriver` gem, it automatically loads the Railtie into
|
66
|
-
your application when it starts.
|
67
|
-
|
68
|
-
### With other Rack-based frameworks
|
69
|
-
|
70
|
-
Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
|
71
|
-
provided by the library:
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
require "google/cloud/trace"
|
75
|
-
use Google::Cloud::Trace::Middleware
|
76
|
-
```
|
77
|
-
|
78
|
-
### Adding Custom Trace Spans
|
79
|
-
|
80
|
-
The Stackdriver Trace Rack Middleware automatically creates a trace record for
|
81
|
-
incoming requests. You can add additional custom trace spans within each
|
82
|
-
request:
|
83
|
-
|
84
|
-
```ruby
|
85
|
-
Google::Cloud::Trace.in_span "my_task" do |span|
|
86
|
-
# Do stuff...
|
87
|
-
|
88
|
-
Google::Cloud::Trace.in_span "my_subtask" do |subspan|
|
89
|
-
# Do other stuff
|
90
|
-
end
|
91
|
-
end
|
92
|
-
```
|
93
|
-
|
94
|
-
### Configuring the library
|
95
|
-
|
96
|
-
You can customize the behavior of the Stackdriver Trace library for Ruby. See
|
97
|
-
the [configuration guide](../stackdriver/CONFIGURATION.md) for a list of
|
98
|
-
possible configuration options.
|
99
|
-
|
100
|
-
## Running on Google Cloud Platform
|
101
|
-
|
102
|
-
The Stackdriver Trace library for Ruby should work without you manually
|
103
|
-
providing authentication credentials for instances running on Google Cloud
|
104
|
-
Platform, as long as the Stackdriver Trace API access scope is enabled on that
|
105
|
-
instance.
|
106
|
-
|
107
|
-
### App Engine
|
108
|
-
|
109
|
-
On Google App Engine, the Stackdriver Trace API access scope is enabled by
|
110
|
-
default, and the Stackdriver Trace library for Ruby can be used without
|
111
|
-
providing credentials or a project ID
|
112
|
-
|
113
|
-
### Container Engine
|
114
|
-
|
115
|
-
On Google Container Engine, you must explicitly add the `trace.append` OAuth
|
116
|
-
scope when creating the cluster:
|
117
|
-
|
118
|
-
```sh
|
119
|
-
$ gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/trace.append
|
120
|
-
```
|
121
|
-
|
122
|
-
### Compute Engine
|
123
|
-
|
124
|
-
For Google Compute Engine instances, you need to explicitly enable the
|
125
|
-
`trace.append` Stackdriver Trace API access scope for each instance. When
|
126
|
-
creating a new instance through the Google Cloud Platform Console, you can do
|
127
|
-
this under Identity and API access: Use the Compute Engine default service
|
128
|
-
account and select "Allow full access to all Cloud APIs" under Access scopes.
|
129
|
-
|
130
|
-
To use something other than the Compute Engine default service account see the
|
131
|
-
docs for Creating and Enabling Service Accounts for Instances and the Running
|
132
|
-
elsewhere section below. The important thing is that the service account you use
|
133
|
-
has the Cloud Trace Agent role.
|
134
|
-
|
135
|
-
## Running locally and elsewhere
|
136
|
-
|
137
|
-
To run the Stackdriver Trace outside of Google Cloud Platform, you must supply
|
138
|
-
your GCP project ID and appropriate service account credentials directly to the
|
139
|
-
Stackdriver Trace. This applies to running the library on your own workstation,
|
140
|
-
on your datacenter's computers, or on the VM instances of another cloud
|
141
|
-
provider. See the [Authentication section](#authentication) for instructions on
|
142
|
-
how to do so.
|
143
|
-
|
144
|
-
## Authentication
|
145
|
-
|
146
|
-
The Instrumentation client and API use Service Account credentials to connect
|
147
|
-
to Google Cloud services. When running on Google Cloud Platform environments,
|
148
|
-
the credentials will be discovered automatically. When running on other
|
149
|
-
environments the Service Account credentials can be specified by providing in
|
150
|
-
several ways.
|
151
|
-
|
152
|
-
The best way to provide authentication information if you're using Ruby on Rails
|
153
|
-
is through the Rails configuration interface:
|
154
|
-
|
155
|
-
```ruby
|
156
|
-
# in config/environments/*.rb
|
157
|
-
Rails.application.configure do |config|
|
158
|
-
# Shared parameters
|
159
|
-
config.google_cloud.project_id = "your-project-id"
|
160
|
-
config.google_cloud.keyfile = "/path/to/key.json"
|
161
|
-
# Or Stackdriver Trace specific parameters
|
162
|
-
config.google_cloud.trace.project_id = "your-project-id"
|
163
|
-
config.google_cloud.trace.keyfile = "/path/to/key.json"
|
164
|
-
end
|
165
|
-
```
|
166
|
-
|
167
|
-
Other Rack-based applications that are loading the Rack Middleware directly can use
|
168
|
-
the configration interface:
|
169
|
-
|
170
|
-
```ruby
|
171
|
-
require "google/cloud/trace"
|
172
|
-
Google::Cloud.configure do |config|
|
173
|
-
# Shared parameters
|
174
|
-
config.project_id = "your-project-id"
|
175
|
-
config.keyfile = "/path/to/key.json"
|
176
|
-
# Or Stackdriver Trace specific parameters
|
177
|
-
config.trace.project_id = "your-project-id"
|
178
|
-
config.trace.keyfile = "/path/to/key.json"
|
179
|
-
end
|
180
|
-
```
|
181
|
-
|
182
|
-
This library also supports the other authentication methods provided by the
|
183
|
-
`google-cloud-ruby` suite. Instructions and configuration options are covered
|
184
|
-
in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-trace/latest/file.AUTHENTICATION).
|
185
|
-
|
186
|
-
## Enabling Logging
|
187
|
-
|
188
|
-
To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
|
189
|
-
|
190
|
-
Configuring a Ruby stdlib logger:
|
191
|
-
|
192
|
-
```ruby
|
193
|
-
require "logger"
|
194
|
-
|
195
|
-
module MyLogger
|
196
|
-
LOGGER = Logger.new $stderr, level: Logger::WARN
|
197
|
-
def logger
|
198
|
-
LOGGER
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
|
203
|
-
module GRPC
|
204
|
-
extend MyLogger
|
205
|
-
end
|
206
|
-
```
|
207
|
-
|
208
|
-
## Supported Ruby Versions
|
209
|
-
|
210
|
-
This library is supported on Ruby 2.3+.
|
211
|
-
|
212
|
-
Google provides official support for Ruby versions that are actively supported
|
213
|
-
by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
|
214
|
-
security maintenance, and not end of life. Currently, this means Ruby 2.3 and
|
215
|
-
later. Older versions of Ruby _may_ still work, but are unsupported and not
|
216
|
-
recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
|
217
|
-
about the Ruby support schedule.
|
218
|
-
|
219
|
-
## Versioning
|
220
|
-
|
221
|
-
This library follows [Semantic Versioning](http://semver.org/).
|
222
|
-
|
223
|
-
It is currently in major version zero (0.y.z), which means that anything may
|
224
|
-
change at any time and the public API should not be considered stable.
|
225
|
-
|
226
|
-
## Contributing
|
227
|
-
|
228
|
-
Contributions to this library are always welcome and highly encouraged.
|
229
|
-
|
230
|
-
See the [Contributing
|
231
|
-
Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-trace/latest/file.CONTRIBUTING)
|
232
|
-
for more information on how to get started.
|
233
|
-
|
234
|
-
Please note that this project is released with a Contributor Code of Conduct. By
|
235
|
-
participating in this project you agree to abide by its terms. See [Code of
|
236
|
-
Conduct](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-trace/latest/file.CODE_OF_CONDUCT)
|
237
|
-
for more information.
|
238
|
-
|
239
|
-
## License
|
240
|
-
|
241
|
-
This library is licensed under Apache 2.0. Full license text is available in
|
242
|
-
[LICENSE](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-trace/latest/file.LICENSE).
|
243
|
-
|
244
|
-
## Support
|
245
|
-
|
246
|
-
Please [report bugs at the project on
|
247
|
-
Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues). Don't
|
248
|
-
hesitate to [ask
|
249
|
-
questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
|
250
|
-
about the client or APIs on [StackOverflow](http://stackoverflow.com).
|