Skip to content

Commit

Permalink
Add sample app and local build instruction. (#10)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zzhlogin authored Jan 10, 2024
1 parent a6c6061 commit c2e603c
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ disable=missing-docstring,
missing-module-docstring, # temp-pylint-upgrade
import-error, # needed as a workaround as reported here: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/290
cyclic-import,
E0611,
E0611, # disabled since pylint use wrong path because of project folder structure divergence

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,44 @@ documentation, we greatly value feedback and contributions from our community.
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
information to effectively respond to your bug report or contribution.

## Build a Wheel file locally
**First time setup**
```sh
pip install --upgrade pip setuptools wheel packaging build
mkdir -p ./dist
```
**Updating the wheel file**
```sh
rm -rf ./dist/*
cd ./aws-opentelemetry-distro
python3 -m build --outdir ../dist
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
cd ..
```

## 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 requests boto3 opentelemetry-instrumentation-flask opentelemetry-instrumentation-botocore opentelemetry-instrumentation
```
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 ./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 ./sample-applications/simple-client-server/client.py testing
```
The span content will be output into terminal console

## Reporting Bugs/Feature Requests

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,12 +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


class AwsTracerProvider(TracerProvider):
def __init__(self):
pass
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
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
15 changes: 15 additions & 0 deletions sample-applications/simple-client-server/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from sys import argv

import requests

try:
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)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ setenv =
CONTRIB_REPO="git+https://github.com/open-telemetry/opentelemetry-python-contrib.git@main"

changedir =
test-aws-opentelemetry-distro: opentelemetry-distro/tests
test-aws-opentelemetry-distro: aws-opentelemetry-distro/tests

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

aws-opentelemetry-distro: pip install {toxinidir}/opentelemetry-distro
aws-opentelemetry-distro: pip install {toxinidir}/aws-opentelemetry-distro

commands =
test: pytest {posargs}
Expand Down

0 comments on commit c2e603c

Please sign in to comment.