Skip to content

Commit c7788ba

Browse files
author
Frank Natividad
committed
Adding base sample files for stackdriver
1 parent 964bfe7 commit c7788ba

13 files changed

+250
-0
lines changed

stackdriver/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source "https://rubygems.org"
2+
3+
gem "sinatra", "~> 1.4"
4+
5+
# [START stackdriver_gem]
6+
gem "stackdriver"
7+
# [END stackdriver_gem]

stackdriver/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Stackdriver Samples
2+
3+
Samples used by Stackdriver documentation. The samples don't work out-of-the-box
4+
and require some modification. The samples are provided as reference guides
5+
when using Rails, Sinatra, other-rack frameworks, and non-rack apps.
6+
7+
## Rails
8+
9+
The `rails_configuration.rb` provides a configuration example that can be used
10+
in your `config/environments/*.rb` files.
11+
12+
## Sinatra
13+
14+
Sinatra exmple apps load middleware using a rack configuration file. For example
15+
`rackup rack_debugger.ru` is an example of starting a Sinatra app with
16+
Stackdriver Debugger.
17+
18+
The following list provides samples used per Stackdriver product.
19+
20+
### Debugger
21+
22+
- `debugger.ru`
23+
- `sinatra_debugger.rb`
24+
25+
### Trace
26+
27+
- `trace.ru`
28+
- `sinatra_trace.rb`
29+
30+
### Logging
31+
32+
- `logging.ru`
33+
- `sinatra_logging.rb`
34+
35+
### Error Reporting
36+
37+
- `error_reporting.ru`
38+
- `sinatra_error_reporting.rb`
39+
40+
### Shared Configuration
41+
42+
Stackdriver gems can be configured using shared configuration which is shown in
43+
`shared_config.ru`
44+
45+
## Non-rack apps
46+
47+
An additional example shows that Debugger doesn't require a Rack
48+
based app.
49+
50+
- `non_rack_debugger.rb`

stackdriver/debugger.ru

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require_relative "sinatra_debugger"
2+
3+
# [START debugger_middleware]
4+
require "google/cloud/debugger"
5+
6+
use Google::Cloud::Debugger::Middleware
7+
# [END debugger_middleware]
8+
9+
# [START debugger_configure]
10+
require "google/cloud/debugger"
11+
12+
Google::Cloud.configure do |config|
13+
# Stackdriver Debugger specific parameters
14+
config.debugger.project_id = "YOUR-PROJECT-ID"
15+
config.debugger.keyfile = "/path/to/service-account.json"
16+
end
17+
# [END debugger_configure]
18+
19+
run Sinatra::Application
20+

stackdriver/error_reporting.ru

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require_relative "sinatra_error_reporting"
2+
3+
# [START error_reporting_middleware]
4+
require "google/cloud/error_reporting"
5+
6+
use Google::Cloud::ErrorReporting::Middleware
7+
# [END error_reporting_middleware]
8+
9+
# [START error_reporting_configure]
10+
require "google/cloud/error_reporting"
11+
12+
Google::Cloud.configure do |config|
13+
# Stackdriver Error Reporting specific parameters
14+
config.error_reporting.project_id = "YOUR-PROJECT-ID"
15+
config.error_reporting.keyfile = "/path/to/service-account.json"
16+
end
17+
# [END error_reporting_configure]
18+
19+
run Sinatra::Application

stackdriver/logging.ru

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require_relative "sinatra_logging"
2+
3+
# [START logging_middleware]
4+
require "google/cloud/logging"
5+
6+
use Google::Cloud::Logging::Middleware
7+
# [END logging_middleware]
8+
9+
# [START logging_configure]
10+
require "google/cloud/logging"
11+
12+
Google::Cloud.configure do |config|
13+
# Stackdriver Logging specific parameters
14+
config.logging.project_id = "YOUR-PROJECT-ID"
15+
config.logging.keyfile = "/path/to/service-account.json"
16+
end
17+
# [END logging_configure]
18+
19+
run Sinatra::Application
20+

stackdriver/non_rack_debugger.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# [START explicit_debugger_norack]
2+
require "google/cloud/debugger"
3+
4+
Google::Cloud::Debugger.new(project_id: "YOUR-PROJECT-ID",
5+
keyfile: "/path/to/service-account.json").start
6+
# [END explicit_debugger_norack]
7+
8+
# [START implicit_debugger_norack]
9+
require "google/cloud/debugger"
10+
11+
Google::Cloud::Debugger.new.start
12+
# [END implicit_debugger_norack]
13+

stackdriver/rails_configuration.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# [START shared_configure]
2+
# Add this to config/environments/*.rb
3+
Rails.application.configure do |config|
4+
# Stackdriver Shared parameters
5+
config.google_cloud.project_id = "YOUR-PROJECT-ID"
6+
config.google_cloud.keyfile = "/path/to/service-account.json"
7+
end
8+
# [END shared_configure]
9+
10+
# [START debugger_configure]
11+
# Add this to config/environments/*.rb
12+
Rails.application.configure do |config|
13+
# Stackdriver Debugger specific parameters
14+
config.google_cloud.debugger.project_id = "YOUR-PROJECT-ID"
15+
config.google_cloud.debugger.keyfile = "/path/to/service-account.json"
16+
end
17+
# [END debugger_configure]
18+
19+
# [START trace_configure]
20+
# Add this to config/environments/*.rb
21+
Rails.application.configure do |config|
22+
# Stackdriver Trace specific parameters
23+
config.google_cloud.trace.project_id = "YOUR-PROJECT-ID"
24+
config.google_cloud.trace.keyfile = "/path/to/service-account.json"
25+
end
26+
# [END trace_configure]
27+
28+
# [START error_reporting_configure]
29+
# Add this to config/environments/*.rb
30+
Rails.application.configure do |config|
31+
# Stackdriver Error Reporting specific parameters
32+
config.google_cloud.error_reporting.project_id = "YOUR-PROJECT-ID"
33+
config.google_cloud.error_reporting.keyfile = "/path/to/service-account.json"
34+
end
35+
# [END error_reporting_configure]
36+
37+
# [START logging_configure]
38+
# Add this to config/environments/*.rb
39+
Rails.application.configure do |config|
40+
# Stackdriver Logging specific parameters
41+
config.google_cloud.logging.project_id = "YOUR-PROJECT-ID"
42+
config.google_cloud.logging.keyfile = "/path/to/service-account.json"
43+
end
44+
# [END logging_configure]

stackdriver/shared_config.ru

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# [START shared_configure]
2+
require "stackdriver"
3+
4+
Google::Cloud.configure do |config|
5+
# Stackdriver Shared parameters
6+
config.project_id = "YOUR-PROJECT-ID"
7+
config.keyfile = "/path/to/service-account.json"
8+
end
9+
# [END shared_configure]
10+

stackdriver/sinatra_debugger.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "sinatra"
2+
3+
get "/" do
4+
"hello world!"
5+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require "sinatra"
2+
3+
get "/" do
4+
5+
end
6+
7+
get "/raise" do
8+
# [START error_reporting_exception]
9+
require "google/cloud/error_reporting"
10+
11+
begin
12+
fail "Raise an exception for Error Reporting."
13+
rescue => exception
14+
Google::Cloud::ErrorReporting.report exception
15+
end
16+
# [END error_reporting_exception]
17+
end
18+

0 commit comments

Comments
 (0)