diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d21271e33..736473afb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,30 +7,21 @@ 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 @@ -38,23 +29,18 @@ The `*.whl` can be found under `dist` folder, and the pkg can be built by `pip i 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 diff --git a/opentelemetry-distro/README.rst b/aws-opentelemetry-distro/README.rst similarity index 100% rename from opentelemetry-distro/README.rst rename to aws-opentelemetry-distro/README.rst diff --git a/opentelemetry-distro/pyproject.toml b/aws-opentelemetry-distro/pyproject.toml similarity index 95% rename from opentelemetry-distro/pyproject.toml rename to aws-opentelemetry-distro/pyproject.toml index 487bdb0d5..3d337e154 100644 --- a/opentelemetry-distro/pyproject.toml +++ b/aws-opentelemetry-distro/pyproject.toml @@ -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" diff --git a/opentelemetry-distro/src/amazon/opentelemetry/distro/aws_metric_attribute_generator.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_metric_attribute_generator.py similarity index 100% rename from opentelemetry-distro/src/amazon/opentelemetry/distro/aws_metric_attribute_generator.py rename to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_metric_attribute_generator.py diff --git a/opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py similarity index 87% rename from opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py rename to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py index dd04588fd..4515cd9a9 100644 --- a/opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py @@ -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 diff --git a/opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py similarity index 100% rename from opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py rename to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py diff --git a/opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py similarity index 100% rename from opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py rename to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py diff --git a/opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py similarity index 100% rename from opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py rename to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py diff --git a/opentelemetry-distro/src/amazon/opentelemetry/distro/metric_attribute_generator.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/metric_attribute_generator.py similarity index 100% rename from opentelemetry-distro/src/amazon/opentelemetry/distro/metric_attribute_generator.py rename to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/metric_attribute_generator.py diff --git a/opentelemetry-distro/src/amazon/opentelemetry/distro/version.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py similarity index 100% rename from opentelemetry-distro/src/amazon/opentelemetry/distro/version.py rename to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py diff --git a/opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelementry_configurator.py b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelementry_configurator.py similarity index 100% rename from opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelementry_configurator.py rename to aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelementry_configurator.py diff --git a/opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py similarity index 72% rename from opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py rename to aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py index 859ade167..0e1829a4a 100644 --- a/opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py +++ b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py @@ -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") diff --git a/eachdist.ini b/eachdist.ini index 9fa0ae9a7..34914f0ae 100644 --- a/eachdist.ini +++ b/eachdist.ini @@ -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/ diff --git a/sample-applications/simple-client-server/client.py b/sample-applications/simple-client-server/client.py new file mode 100644 index 000000000..75b593f47 --- /dev/null +++ b/sample-applications/simple-client-server/client.py @@ -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}") diff --git a/sample-applications/simple-client-server/server_automatic_s3client.py b/sample-applications/simple-client-server/server_automatic_s3client.py new file mode 100644 index 000000000..c6ec7c4a5 --- /dev/null +++ b/sample-applications/simple-client-server/server_automatic_s3client.py @@ -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) diff --git a/tests/client.py b/tests/client.py deleted file mode 100644 index 3f0777cb1..000000000 --- a/tests/client.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# 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 -# -# http://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. - -from sys import argv - -from requests import get - -from opentelemetry import trace -from opentelemetry.distro.aws_opentelemetry_configurator import AwsTracerProvider -from opentelemetry.propagate import inject -from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter - -trace.set_tracer_provider(AwsTracerProvider()) -tracer = trace.get_tracer_provider().get_tracer(__name__) - -trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(ConsoleSpanExporter())) - - -assert len(argv) == 2 - -with tracer.start_as_current_span("client"): - - with tracer.start_as_current_span("client-server"): - headers = {} - inject(headers) - requested = get( - "http://localhost:8082/server_request", - params={"param": argv[1]}, - headers=headers, - ) - - assert requested.status_code == 200 diff --git a/tests/server_automatic_s3client.py b/tests/server_automatic_s3client.py deleted file mode 100644 index f369c4eca..000000000 --- a/tests/server_automatic_s3client.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# 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 -# -# http://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. - -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)