-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New directory for OpenTelemetry QuickStart #4016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
leahecole
merged 38 commits into
GoogleCloudPlatform:master
from
aravinsiva:porting_to_opentelemetry
Aug 27, 2020
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
f586771
creating new directory for opentelemetry version of quickstart
aravinsiva e1e0a3a
slight modification to README
aravinsiva d24cf8d
updating requirements.txt
aravinsiva 5878bdb
Merge branch 'master' into porting_to_opentelemetry
aravinsiva 2e7fea8
Making modifications suggested by Shawn
aravinsiva 5b80ad4
Merge branch 'porting_to_opentelemetry' of https://github.com/aravins…
aravinsiva 2b78b62
Merge branch 'master' into porting_to_opentelemetry
aravinsiva c8f6b81
Merge branch 'master' into porting_to_opentelemetry
aravinsiva 10dc3fb
adding Shawn suggested documentation changes
aravinsiva 66b6007
Merge branch 'master' into porting_to_opentelemetry
aravinsiva 4fcaddb
making suggested edits
aravinsiva c81c293
Merge branch 'porting_to_opentelemetry' of https://github.com/aravins…
aravinsiva 9c5cfb3
Merge branch 'master' into porting_to_opentelemetry
aravinsiva c62cf97
Merge branch 'master' into porting_to_opentelemetry
aravinsiva 83b1628
making more suggested changes to README.md
aravinsiva ab5483b
Merge branch 'master' into porting_to_opentelemetry
aravinsiva e90e001
adding production PyPi librarires
aravinsiva ad9f0c7
Merge branch 'porting_to_opentelemetry' of https://github.com/aravins…
aravinsiva 181e5d4
Merge branch 'master' into porting_to_opentelemetry
aravinsiva a79c2c9
Merge branch 'master' into porting_to_opentelemetry
aravinsiva d1b188f
fixing undefined issues
aravinsiva 99e8999
fixing test issues and simplyfying example
aravinsiva 06189f2
fixing mismatched region tag issue
aravinsiva 283ca73
Merge branch 'master' into porting_to_opentelemetry
leahecole c94cff9
reworking service for GKE
aravinsiva 58469aa
Merge branch 'porting_to_opentelemetry' of https://github.com/aravins…
aravinsiva f5be627
linting and adding more descriptive README.md
aravinsiva dc722c9
fixing test issues
aravinsiva 2c66f96
Merge branch 'master' into porting_to_opentelemetry
leahecole e5b280f
Merge branch 'master' into porting_to_opentelemetry
leahecole 634986e
linting
aravinsiva 7dd263e
Merge branch 'porting_to_opentelemetry' of https://github.com/aravins…
aravinsiva 288d302
adding suggested changes by Shawn
aravinsiva 4b3681e
Merge branch 'master' into porting_to_opentelemetry
aravinsiva 37f6f3f
Merge branch 'master' into porting_to_opentelemetry
leahecole c76a120
linting and adding Shawn suggested changes
aravinsiva ef779bf
Merge branch 'porting_to_opentelemetry' of https://github.com/aravins…
aravinsiva 8e1c97a
Merge branch 'master' into porting_to_opentelemetry
aravinsiva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# cloud-trace-demo-app-opentelemetry | ||
|
||
Open this demo app in [Google Cloud Shell](https://cloud.google.com/shell/docs/). This includes necessary tools. | ||
|
||
|
||
[](https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=trace/cloud-trace-demo-app/README.md&cloudshell_tutorial=trace/cloud-trace-demo-app/README.md) | ||
|
||
#### Demo Requirements | ||
If you are using Cloud Shell, skip to the next section. | ||
|
||
1. Install gcloud <https://cloud.google.com/sdk/install> | ||
2. Install kubectl <https://kubernetes.io/docs/tasks/tools/install-kubectl/> | ||
3. Install docker <https://docs.docker.com/install/> | ||
|
||
|
||
#### Create a GKE cluster | ||
|
||
4. Enable Google Cloud and set up region and zone. | ||
|
||
`gcloud init` | ||
5. Enable the GKE API & billing: | ||
|
||
`gcloud services enable container.googleapis.com` | ||
6. Create a GKE cluster named "cloud-trace-demo", replacing `your-gcp-zone` below | ||
with the | ||
[GCP Zone](https://cloud.google.com/compute/docs/regions-zones) closest in proximity to you: | ||
|
||
``` | ||
gcloud container clusters create cloud-trace-demo\` | ||
--num-nodes 1 \ | ||
--enable-basic-auth \ | ||
--issue-client-certificate \ | ||
--zone your-gcp-zone | ||
``` | ||
7. Verify that you have access to the cluster: | ||
|
||
`kubectl get nodes` | ||
|
||
#### Deploy The Cloud Trace Demo App | ||
|
||
8. Build and tag the docker image for demo app: | ||
|
||
`docker build -t gcr.io/${PROJECT_ID}/cloud-trace-demo:v1 .` | ||
9. Deploy resource to the cluster: | ||
|
||
`kubectl apply -f deployment.yaml` | ||
10. Track the status of the deployment: | ||
|
||
`kubectl get deployments` | ||
|
||
Deployment is complete when all of the available deployments are ready. | ||
11. Run the following command to see the pods the deployment created: | ||
|
||
`kubectl get pods` | ||
|
||
#### Deploy The Cloud Trace Demo Service | ||
|
||
12. Create the cloud trace demo service: | ||
|
||
`kubectl apply -f service.yaml` | ||
13. Get the services IP address by running the following command: | ||
|
||
`kubectl get services` | ||
14. Send a curl request to the EXTERNAL_IP, replacing `EXTERNAL_IP` with the external IP address found | ||
in step 13: | ||
|
||
`curl EXTERNAL_IP` | ||
15. Visit [Trace List](https://console.cloud.google.com/traces/list) to check traces generated. | ||
Click on any trace in the graph to see the Waterfall View. | ||
|
||
 | ||
16. Clean up GKE cluster/pods/services: | ||
|
||
`gcloud container clusters delete cloud-trace-demo` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Use the official lightweight Python image. | ||
# https://hub.docker.com/_/python | ||
FROM python:3.7-slim | ||
|
||
# Copy local code to the container image. | ||
ENV APP_HOME /app | ||
WORKDIR $APP_HOME | ||
COPY . ./ | ||
COPY requirements.txt /app/ | ||
RUN pip install Flask gunicorn | ||
RUN pip install -r requirements.txt | ||
|
||
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
A sample app demonstrating CloudTraceSpanExporter | ||
""" | ||
import random | ||
import time | ||
|
||
# [START trace_demo_imports] | ||
import flask | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor | ||
|
||
# [END trace_demo_imports] | ||
|
||
app = flask.Flask(__name__) | ||
|
||
|
||
def configure_exporter(exporter): | ||
trace.set_tracer_provider(TracerProvider()) | ||
|
||
trace.get_tracer_provider().add_span_processor(SimpleExportSpanProcessor(exporter)) | ||
|
||
|
||
tracer = trace.get_tracer(__name__) | ||
|
||
|
||
@app.route("/") | ||
def template_test(): | ||
# Sleep for a random time to imitate a random processing time | ||
time.sleep(random.uniform(0, 0.5)) | ||
|
||
with tracer.start_as_current_span("span1"): | ||
with tracer.start_as_current_span("span2"): | ||
with tracer.start_as_current_span("span3"): | ||
print("Hello world from Cloud Trace Exporter!") | ||
|
||
return "Hello World" | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, host="0.0.0.0", port=8080) | ||
configure_exporter(CloudTraceSpanExporter()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
A sample app demonstrating Stackdriver Trace | ||
""" | ||
import mock | ||
|
||
import app | ||
|
||
|
||
def test_traces(): | ||
exporter = mock.Mock() | ||
app.configure_exporter(exporter) | ||
client = app.app.test_client() | ||
resp = client.get("/") | ||
assert resp.status_code == 200 |
25 changes: 25 additions & 0 deletions
25
trace/cloud-trace-demo-app-opentelemetry/app/deployment.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This file configures the hello-world app which serves public web traffic. | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: cloud-trace-demo | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: trace-demo | ||
template: | ||
metadata: | ||
labels: | ||
app: trace-demo | ||
spec: | ||
containers: | ||
- name: trace-demo-app | ||
# Replace $GCLOUD_PROJECT with your project ID | ||
image: gcr.io/$GCLOUD_PROJECT/cloud-trace-demo:latest | ||
# This app listens on port 8080 for web traffic by default. | ||
ports: | ||
- containerPort: 8080 | ||
env: | ||
- name: PORT | ||
value: "8080" |
2 changes: 2 additions & 0 deletions
2
trace/cloud-trace-demo-app-opentelemetry/app/requirements-test.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest==5.3.2 | ||
mock==3.0.5 |
15 changes: 15 additions & 0 deletions
15
trace/cloud-trace-demo-app-opentelemetry/app/requirements.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Flask==1.1.2 | ||
opentelemetry-api==0.9b0 | ||
opentelemetry-auto-instrumentation==0.8b0 | ||
opentelemetry-exporter-cloud-trace==0.9b0 | ||
opentelemetry-ext-flask==0.8b0 | ||
opentelemetry-ext-grpc==0.9b0 | ||
opentelemetry-ext-jaeger==0.8b0 | ||
opentelemetry-ext-requests==0.8b0 | ||
opentelemetry-ext-wsgi==0.8b0 | ||
opentelemetry-sdk==0.9b0 | ||
grpcio==1.29.0 | ||
httpretty==1.0.2 | ||
google-cloud-monitoring==1.0.0 | ||
google-cloud-trace==0.23.0 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# The hello service provides a load-balancing proxy over the hello-app | ||
# pods. By specifying the type as a 'LoadBalancer', Kubernetes Engine will | ||
# create an external HTTP load balancer. | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: trace-demo | ||
spec: | ||
type: LoadBalancer | ||
selector: | ||
app: trace-demo | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
################## Set up service a ########################### | ||
|
||
echo "Creating service a" | ||
kubectl apply -f app/demo-service-a.yaml | ||
|
||
################## Set up service b ########################### | ||
echo "Fetching the external IP of service a" | ||
endpoint="" | ||
for run in {1..20} | ||
do | ||
echo "Attempt #${run} to fetch the external IP of service a..." | ||
sleep 5 | ||
endpoint=`kubectl get svc cloud-trace-demo-a -ojsonpath='{.status.loadBalancer.ingress[0].ip}'` | ||
if [[ "$endpoint" != "" ]]; then | ||
break | ||
fi | ||
done | ||
|
||
if [[ "$endpoint" == "" ]]; then | ||
echo "Unable to get external IP for service cloud-trace-demo-a" | ||
exit 1 | ||
fi | ||
|
||
echo "Passing external IP for the first service ${endpoint} to the second service template" | ||
sed "s/{{ endpoint }}/${endpoint}/g" app/demo-service-b.yaml.template > app/demo-service-b.yaml | ||
kubectl apply -f app/demo-service-b.yaml | ||
rm app/demo-service-b.yaml | ||
|
||
################## Set up service c ########################### | ||
echo "Fetching the external IP of service b" | ||
endpoint="" | ||
for run in {1..20} | ||
do | ||
echo "Attempt #${run} to fetch the external IP of service b..." | ||
sleep 5 | ||
endpoint=`kubectl get svc cloud-trace-demo-b -ojsonpath='{.status.loadBalancer.ingress[0].ip}'` | ||
if [[ "$endpoint" != "" ]]; then | ||
break | ||
fi | ||
done | ||
|
||
if [[ "$endpoint" == "" ]]; then | ||
echo "Unable to get external IP for service cloud-trace-demo-a" | ||
exit 1 | ||
fi | ||
|
||
echo "Passing external IP for the service b ${endpoint} to the service c" | ||
sed "s/{{ endpoint }}/${endpoint}/g" app/demo-service-c.yaml.template > app/demo-service-c.yaml | ||
kubectl apply -f app/demo-service-c.yaml | ||
rm app/demo-service-c.yaml | ||
|
||
echo "Successfully deployed all services" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.