Skip to content

Commit

Permalink
Update sample app.
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhlogin committed Jan 10, 2024
1 parent c4c4790 commit e3bb47c
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 107 deletions.
36 changes: 11 additions & 25 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,40 @@ Please read through this document before submitting any issues or pull requests
information to effectively respond to your bug report or contribution.

## Build a Wheel file locally
1. Get the latest versions of packaging tools
```sh
pip install --upgrade pip setuptools wheel packaging
```
2. Create a dist directory to save build output
**First time setup**
```sh
pip install --upgrade pip setuptools wheel packaging build
mkdir -p ./dist
rm -rf ./dist/*
```
3. cd to project folder
```sh
cd ./opentelemetry-distro
```
4. Build the project, and save the output into dist folder
**Updating the wheel file**
```sh
rm -rf ./dist/*
cd ./aws-opentelemetry-distro
python3 -m build --outdir ../dist
```
5. Check the project `${pkg_version}` which can be found in `./opentelemetry-distro/src/amazon/opentelemetry/distro/version.py`
6. Build a wheel for the project distribution
```sh
cd ../dist
pkg_version=$(grep '__version__' ../aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | awk -F '"' '{print $2}')
pip wheel --no-deps aws_opentelemetry_distro-${pkg_version}.tar.gz
pip install aws_opentelemetry_distro-${pkg_version}-py3-none-any.whl --force-reinstall
```
The `*.whl` can be found under `dist` folder, and the pkg can be built by `pip install`

## Test a sample App
1. Setup env and install project dependencies
```sh
mkdir auto_instrumentation
virtualenv auto_instrumentation
source auto_instrumentation/bin/activate
pip install flask
pip install requests
pip install boto3
pip install opentelemetry-instrumentation-flask
pip install opentelemetry-instrumentation-botocore
pip install opentelemetry-instrumentation
pip install flask requests boto3 opentelemetry-instrumentation-flask opentelemetry-instrumentation-botocore opentelemetry-instrumentation
```
2. Install the project pkg by following "Build a Wheel file locally" step above.
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.
3. Add AWS test account credential into the terminal, setup environment variable and run sample server:
```sh
export OTEL_PYTHON_DISTRO="aws_distro"
export OTEL_PYTHON_CONFIGURATOR="aws_configurator"
opentelemetry-instrument python ./tests/server_automatic_s3client.py
opentelemetry-instrument python ./sample-applications/simple-client-server/server_automatic_s3client.py
```
4. Prepare a client.py, an example is `./tests/client.py`, open a new terminal and run sample client:
```sh
python client.py testing
python ./sample-applications/simple-client-server/client.py testing
```
The span content will be output into terminal console

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ aws_configurator = "opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenT
aws_distro = "opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"

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

[tool.hatch.version]
path = "src/amazon/opentelemetry/distro/version.py"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

from opentelemetry.sdk._configuration import _BaseConfigurator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
from opentelemetry.trace import set_tracer_provider


# pylint: disable=W0246
class AwsTracerProvider(TracerProvider):
def __init__(self):
super(AwsTracerProvider, self).__init__()
self.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
# TODO:
# 1. Add SpanMetricsProcessor to generate AppSignal metrics from spans and exports them
# 2. Add AttributePropagatingSpanProcessor to propagate span attributes from parent to child
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
class TestAwsOpenTelemetryDistro(TestCase):
def test_package_available(self):
try:
require(["aws-opentelemetry-distro"])
require(["aws-aws-opentelemetry-distro"])
except DistributionNotFound:
self.fail("aws-opentelemetry-distro not installed")
self.fail("aws-aws-opentelemetry-distro not installed")
4 changes: 2 additions & 2 deletions eachdist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[DEFAULT]

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

[testroots]
extraroots=tests/
Expand Down
16 changes: 16 additions & 0 deletions sample-applications/simple-client-server/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from sys import argv

import requests

try:
timeout_seconds = 10
requested = requests.get("http://localhost:8082/server_request", params={"param": argv[0]}, timeout=120)
assert requested.status_code == 200
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except requests.exceptions.Timeout as timeout_err:
print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
print(f"Request error occurred: {req_err}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import boto3
from flask import Flask, request

# Let's use Amazon S3
s3 = boto3.resource("s3")

app = Flask(__name__)


@app.route("/server_request")
def server_request():
print(request.args.get("param"))
for bucket in s3.buckets.all():
print(bucket.name)
return "served"


if __name__ == "__main__":
app.run(port=8082)
43 changes: 0 additions & 43 deletions tests/client.py

This file was deleted.

33 changes: 0 additions & 33 deletions tests/server_automatic_s3client.py

This file was deleted.

0 comments on commit e3bb47c

Please sign in to comment.