Skip to content

Commit c2e603c

Browse files
authored
Add sample app and local build instruction. (aws-observability#10)
Add sample app python files which can be used for local tests. Add "Build a Wheel file locally" and "Test a sample App" in `CONTRIBUTING.md` By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent a6c6061 commit c2e603c

17 files changed

+83
-7
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ disable=missing-docstring,
8181
missing-module-docstring, # temp-pylint-upgrade
8282
import-error, # needed as a workaround as reported here: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/290
8383
cyclic-import,
84-
E0611,
84+
E0611, # disabled since pylint use wrong path because of project folder structure divergence
8585

8686
# Enable the message, report, category or checker with the given id(s). You can
8787
# either give multiple identifier separated by comma (,) or put this option

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@ documentation, we greatly value feedback and contributions from our community.
66
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
77
information to effectively respond to your bug report or contribution.
88

9+
## Build a Wheel file locally
10+
**First time setup**
11+
```sh
12+
pip install --upgrade pip setuptools wheel packaging build
13+
mkdir -p ./dist
14+
```
15+
**Updating the wheel file**
16+
```sh
17+
rm -rf ./dist/*
18+
cd ./aws-opentelemetry-distro
19+
python3 -m build --outdir ../dist
20+
cd ../dist
21+
pkg_version=$(grep '__version__' ../aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | awk -F '"' '{print $2}')
22+
pip wheel --no-deps aws_opentelemetry_distro-${pkg_version}.tar.gz
23+
pip install aws_opentelemetry_distro-${pkg_version}-py3-none-any.whl --force-reinstall
24+
cd ..
25+
```
26+
27+
## Test a sample App
28+
1. Setup env and install project dependencies
29+
```sh
30+
mkdir auto_instrumentation
31+
virtualenv auto_instrumentation
32+
source auto_instrumentation/bin/activate
33+
pip install flask requests boto3 opentelemetry-instrumentation-flask opentelemetry-instrumentation-botocore opentelemetry-instrumentation
34+
```
35+
2. Install the project pkg by following "Build a Wheel file locally" step above. Please make sure to install “aws-opentelemetry-distro” by following steps instead of install "opentelemetry-distro” directly.
36+
3. Add AWS test account credential into the terminal, setup environment variable and run sample server:
37+
```sh
38+
export OTEL_PYTHON_DISTRO="aws_distro"
39+
export OTEL_PYTHON_CONFIGURATOR="aws_configurator"
40+
opentelemetry-instrument python ./sample-applications/simple-client-server/server_automatic_s3client.py
41+
```
42+
4. Prepare a client.py, an example is `./tests/client.py`, open a new terminal and run sample client:
43+
```sh
44+
python ./sample-applications/simple-client-server/client.py testing
45+
```
46+
The span content will be output into terminal console
947

1048
## Reporting Bugs/Feature Requests
1149

File renamed without changes.

opentelemetry-distro/pyproject.toml renamed to aws-opentelemetry-distro/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ aws_configurator = "opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenT
2727
aws_distro = "opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"
2828

2929
[project.urls]
30-
Homepage = "https://github.com/aws-observability/aws-otel-python-instrumentation/tree/main/opentelemetry-distro"
30+
Homepage = "https://github.com/aws-observability/aws-otel-python-instrumentation/tree/main/aws-opentelemetry-distro"
3131

3232
[tool.hatch.version]
3333
path = "src/amazon/opentelemetry/distro/version.py"

opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py renamed to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
from opentelemetry.sdk._configuration import _BaseConfigurator
55
from opentelemetry.sdk.trace import TracerProvider
6+
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
67
from opentelemetry.trace import set_tracer_provider
78

89

910
class AwsTracerProvider(TracerProvider):
1011
def __init__(self):
11-
pass
12+
super(AwsTracerProvider, self).__init__()
13+
self.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
1214
# TODO:
1315
# 1. Add SpanMetricsProcessor to generate AppSignal metrics from spans and exports them
1416
# 2. Add AttributePropagatingSpanProcessor to propagate span attributes from parent to child

eachdist.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
[DEFAULT]
44

55
[lintroots]
6-
extraroots=scripts/
7-
subglob=*.py,tests/,test/,src/*
6+
extraroots=scripts/, sample-applications/
7+
subglob=*.py,tests/,test/,src/*, simple-client-server
88

99
[testroots]
1010
extraroots=tests/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
from sys import argv
4+
5+
import requests
6+
7+
try:
8+
requested = requests.get("http://localhost:8082/server_request", params={"param": argv[0]}, timeout=120)
9+
assert requested.status_code == 200
10+
except requests.exceptions.HTTPError as http_err:
11+
print(f"HTTP error occurred: {http_err}")
12+
except requests.exceptions.Timeout as timeout_err:
13+
print(f"Timeout error occurred: {timeout_err}")
14+
except requests.exceptions.RequestException as req_err:
15+
print(f"Request error occurred: {req_err}")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
import boto3
4+
from flask import Flask, request
5+
6+
# Let's use Amazon S3
7+
s3 = boto3.resource("s3")
8+
9+
app = Flask(__name__)
10+
11+
12+
@app.route("/server_request")
13+
def server_request():
14+
print(request.args.get("param"))
15+
for bucket in s3.buckets.all():
16+
print(bucket.name)
17+
return "served"
18+
19+
20+
if __name__ == "__main__":
21+
app.run(port=8082)

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ setenv =
2222
CONTRIB_REPO="git+https://github.com/open-telemetry/opentelemetry-python-contrib.git@main"
2323

2424
changedir =
25-
test-aws-opentelemetry-distro: opentelemetry-distro/tests
25+
test-aws-opentelemetry-distro: aws-opentelemetry-distro/tests
2626

2727
commands_pre =
2828
; Install without -e to test the actual installation
@@ -33,7 +33,7 @@ commands_pre =
3333
test: pip install "opentelemetry-sdk[test] @ {env:CORE_REPO}#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk"
3434
test: pip install "opentelemetry-instrumentation[test] @ {env:CONTRIB_REPO}#egg=opentelemetry-instrumentation&subdirectory=opentelemetry-instrumentation"
3535

36-
aws-opentelemetry-distro: pip install {toxinidir}/opentelemetry-distro
36+
aws-opentelemetry-distro: pip install {toxinidir}/aws-opentelemetry-distro
3737

3838
commands =
3939
test: pytest {posargs}

0 commit comments

Comments
 (0)