Skip to content

Commit f4bb1dd

Browse files
authored
Add ownership (aws-observability#5)
Add AWS Distro with to create a basic file structure. Add unit tests workflow.
1 parent b03e260 commit f4bb1dd

File tree

11 files changed

+200
-3
lines changed

11 files changed

+200
-3
lines changed

.github/workflows/test.yml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
1-
# This workflow check the code style for the repo
2-
# TODO: add unit test check after adding AWS Distro project
1+
# This workflow check the code style and run unit tests for the repo
32
name: AWS Distro Tests
43

54
on:
65
push:
76
pull_request:
87

98
jobs:
9+
build:
10+
env:
11+
# We use these variables to convert between tox and GHA version literals
12+
py37: 3.7
13+
py38: 3.8
14+
py39: 3.9
15+
py310: "3.10"
16+
py311: "3.11"
17+
pypy3: "pypy3.7"
18+
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
22+
matrix:
23+
python-version: [ py37, py38, py39, py310, py311, pypy3 ]
24+
package: [ "aws-opentelemetry-distro" ]
25+
os: [ ubuntu-20.04 ]
26+
steps:
27+
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
28+
uses: actions/checkout@v2
29+
- name: Set up Python ${{ env[matrix.python-version] }}
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: ${{ env[matrix.python-version] }}
33+
- name: Install tox
34+
run: pip install tox==3.27.1 tox-factor
35+
- name: Cache tox environment
36+
# Preserves .tox directory between runs for faster installs
37+
uses: actions/cache@v1
38+
with:
39+
path: |
40+
.tox
41+
~/.cache/pip
42+
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
43+
- name: run tox
44+
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
1045
misc:
1146
strategy:
1247
fail-fast: false

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +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,
8485

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

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ This project provide AWS Distro base on [OpenTelemetry Python Contrib](https://g
66
preconfigured for use with AWS services. Please check out that project too to get a better
77
understanding of the underlying internals.
88

9+
## Python Version Support
10+
This project ensures compatibility with the following supported Python versions: 3.7, 3.8, 3.9, 3.10, 3.11
11+
912
## Code Style Check
1013

1114
This package applies code style check automatically when created a push/pull request to the project repository. You can apply style check locally before submitting the PR by following:
1215
1. Install related packages:
1316
```sh
14-
pip install isort pylint black flake8 codespell
17+
pip install isort pylint black flake8 codespell readme_renderer
1518
```
1619
2. Check code style errors using codespell and lint:
1720
```sh

opentelemetry-distro/README.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
AWS OpenTelemetry Distro
2+
========================================
3+
4+
Installation
5+
------------
6+
7+
::
8+
9+
pip install aws-opentelemetry-distro
10+
11+
12+
This package provides AWS OpenTelemetry Python Distro, which allows for auto-instrumentation of Python applications.
13+
14+
References
15+
----------
16+
17+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
18+
* `Example using opentelemetry-distro <https://opentelemetry.io/docs/instrumentation/python/distro/>`_

opentelemetry-distro/pyproject.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "aws-opentelemetry-distro"
7+
dynamic = ["version"]
8+
description = "AWS OpenTelemetry Python Distro"
9+
readme = "README.rst"
10+
license = "Apache-2.0"
11+
requires-python = ">=3.7"
12+
13+
dependencies = [
14+
"opentelemetry-api ~= 1.12",
15+
"opentelemetry-instrumentation == 0.43b0",
16+
"opentelemetry-sdk ~= 1.13",
17+
"opentelemetry-sdk-extension-aws ~= 2.0.1"
18+
]
19+
20+
[project.optional-dependencies]
21+
test = []
22+
23+
[project.entry-points.opentelemetry_configurator]
24+
aws_configurator = "opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenTelemetryConfigurator"
25+
26+
[project.entry-points.opentelemetry_distro]
27+
aws_distro = "opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"
28+
29+
[project.urls]
30+
Homepage = "https://github.com/aws-observability/aws-otel-python-instrumentation/tree/main/opentelemetry-distro"
31+
32+
[tool.hatch.version]
33+
path = "src/amazon/opentelemetry/distro/version.py"
34+
35+
[tool.hatch.build.targets.sdist]
36+
include = [
37+
"/src",
38+
"/tests",
39+
]
40+
41+
[tool.hatch.build.targets.wheel]
42+
packages = ["src/amazon/opentelemetry"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from opentelemetry.sdk._configuration import _BaseConfigurator
5+
from opentelemetry.sdk.trace import TracerProvider
6+
from opentelemetry.trace import set_tracer_provider
7+
8+
9+
class AwsTracerProvider(TracerProvider):
10+
def __init__(
11+
self
12+
):
13+
pass
14+
# TODO:
15+
# 1. Add SpanMetricsProcessor to generate AppSignal metrics from spans and exports them
16+
# 2. Add AttributePropagatingSpanProcessor to propagate span attributes from parent to child
17+
# 3. Add AwsMetricAttributesSpanExporter to add more attributes to all spans.
18+
# 4. Add AlwaysRecordSampler to record all spans.
19+
20+
21+
class AwsOpenTelemetryConfigurator(_BaseConfigurator):
22+
def __init__(self):
23+
self.trace_provider = None
24+
25+
def _configure(self, **kwargs):
26+
self.trace_provider = AwsTracerProvider()
27+
set_tracer_provider(self.trace_provider)
28+
29+
def get_trace_provider(self):
30+
return self.trace_provider
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from logging import getLogger
5+
6+
from opentelemetry.instrumentation.distro import BaseDistro
7+
8+
logger = getLogger(__name__)
9+
10+
11+
class AwsOpenTelemetryDistro(BaseDistro):
12+
def _configure(self, **kwargs):
13+
super(AwsOpenTelemetryDistro, self)._configure()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
__version__ = "0.0.1"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from unittest import TestCase
5+
6+
from opentelemetry.distro.aws_opentelemetry_configurator import (
7+
AwsOpenTelemetryConfigurator,
8+
AwsTracerProvider,
9+
)
10+
11+
12+
class TestAwsOpenTelemetryConfigurator(TestCase):
13+
# pylint: disable=no-self-use
14+
def test_default_configuration(self):
15+
configurator = AwsOpenTelemetryConfigurator()
16+
configurator.configure()
17+
trace_provider = configurator.get_trace_provider()
18+
assert isinstance(trace_provider, AwsTracerProvider)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from unittest import TestCase
5+
6+
from pkg_resources import DistributionNotFound, require
7+
8+
9+
class TestAwsOpenTelemetryDistro(TestCase):
10+
def test_package_available(self):
11+
try:
12+
require(["aws-opentelemetry-distro"])
13+
except DistributionNotFound:
14+
self.fail("aws-opentelemetry-distro not installed")

tox.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ isolated_build = True
33
skipsdist = True
44
skip_missing_interpreters = True
55
envlist =
6+
; aws-opentelemetry-distro
7+
py3{7,8,9,10,11}-test-aws-opentelemetry-distro
8+
pypy3-test-aws-opentelemetry-distro
9+
610
lint
711
spellcheck
812

@@ -12,9 +16,24 @@ deps =
1216
test: pytest
1317
test: pytest-benchmark
1418

19+
setenv =
20+
; TODO: The two repos branches need manual updated over time, need to figure out a more sustainable solution.
21+
CORE_REPO="git+https://github.com/open-telemetry/opentelemetry-python.git@release/v1.22.x-0.43bx"
22+
CONTRIB_REPO="git+https://github.com/open-telemetry/opentelemetry-python-contrib.git@main"
23+
24+
changedir =
25+
test-aws-opentelemetry-distro: opentelemetry-distro/tests
26+
1527
commands_pre =
1628
; Install without -e to test the actual installation
1729
py3{7,8,9,10,11}: python -m pip install -U pip setuptools wheel
30+
; Install common packages for all the tests. These are not needed in all the
31+
; cases but it saves a lot of boilerplate in this file.
32+
test: pip install "opentelemetry-api[test] @ {env:CORE_REPO}#egg=opentelemetry-api&subdirectory=opentelemetry-api"
33+
test: pip install "opentelemetry-sdk[test] @ {env:CORE_REPO}#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk"
34+
test: pip install "opentelemetry-instrumentation[test] @ {env:CONTRIB_REPO}#egg=opentelemetry-instrumentation&subdirectory=opentelemetry-instrumentation"
35+
36+
aws-opentelemetry-distro: pip install {toxinidir}/opentelemetry-distro
1837

1938
commands =
2039
test: pytest {posargs}

0 commit comments

Comments
 (0)