Skip to content

Commit

Permalink
Add ownership (#5)
Browse files Browse the repository at this point in the history
Add AWS Distro with to create a basic file structure. 
Add unit tests workflow.
  • Loading branch information
zzhlogin authored Jan 9, 2024
1 parent b03e260 commit f4bb1dd
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 3 deletions.
39 changes: 37 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
# This workflow check the code style for the repo
# TODO: add unit test check after adding AWS Distro project
# This workflow check the code style and run unit tests for the repo
name: AWS Distro Tests

on:
push:
pull_request:

jobs:
build:
env:
# We use these variables to convert between tox and GHA version literals
py37: 3.7
py38: 3.8
py39: 3.9
py310: "3.10"
py311: "3.11"
pypy3: "pypy3.7"
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
python-version: [ py37, py38, py39, py310, py311, pypy3 ]
package: [ "aws-opentelemetry-distro" ]
os: [ ubuntu-20.04 ]
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2
- name: Set up Python ${{ env[matrix.python-version] }}
uses: actions/setup-python@v4
with:
python-version: ${{ env[matrix.python-version] }}
- name: Install tox
run: pip install tox==3.27.1 tox-factor
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v1
with:
path: |
.tox
~/.cache/pip
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
misc:
strategy:
fail-fast: false
Expand Down
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +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,

# 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ This project provide AWS Distro base on [OpenTelemetry Python Contrib](https://g
preconfigured for use with AWS services. Please check out that project too to get a better
understanding of the underlying internals.

## Python Version Support
This project ensures compatibility with the following supported Python versions: 3.7, 3.8, 3.9, 3.10, 3.11

## Code Style Check

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:
1. Install related packages:
```sh
pip install isort pylint black flake8 codespell
pip install isort pylint black flake8 codespell readme_renderer
```
2. Check code style errors using codespell and lint:
```sh
Expand Down
18 changes: 18 additions & 0 deletions opentelemetry-distro/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
AWS OpenTelemetry Distro
========================================

Installation
------------

::

pip install aws-opentelemetry-distro


This package provides AWS OpenTelemetry Python Distro, which allows for auto-instrumentation of Python applications.

References
----------

* `OpenTelemetry Project <https://opentelemetry.io/>`_
* `Example using opentelemetry-distro <https://opentelemetry.io/docs/instrumentation/python/distro/>`_
42 changes: 42 additions & 0 deletions opentelemetry-distro/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "aws-opentelemetry-distro"
dynamic = ["version"]
description = "AWS OpenTelemetry Python Distro"
readme = "README.rst"
license = "Apache-2.0"
requires-python = ">=3.7"

dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.43b0",
"opentelemetry-sdk ~= 1.13",
"opentelemetry-sdk-extension-aws ~= 2.0.1"
]

[project.optional-dependencies]
test = []

[project.entry-points.opentelemetry_configurator]
aws_configurator = "opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenTelemetryConfigurator"

[project.entry-points.opentelemetry_distro]
aws_distro = "opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"

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

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

[tool.hatch.build.targets.sdist]
include = [
"/src",
"/tests",
]

[tool.hatch.build.targets.wheel]
packages = ["src/amazon/opentelemetry"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from opentelemetry.sdk._configuration import _BaseConfigurator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace import set_tracer_provider


class AwsTracerProvider(TracerProvider):
def __init__(
self
):
pass
# TODO:
# 1. Add SpanMetricsProcessor to generate AppSignal metrics from spans and exports them
# 2. Add AttributePropagatingSpanProcessor to propagate span attributes from parent to child
# 3. Add AwsMetricAttributesSpanExporter to add more attributes to all spans.
# 4. Add AlwaysRecordSampler to record all spans.


class AwsOpenTelemetryConfigurator(_BaseConfigurator):
def __init__(self):
self.trace_provider = None

def _configure(self, **kwargs):
self.trace_provider = AwsTracerProvider()
set_tracer_provider(self.trace_provider)

def get_trace_provider(self):
return self.trace_provider
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from logging import getLogger

from opentelemetry.instrumentation.distro import BaseDistro

logger = getLogger(__name__)


class AwsOpenTelemetryDistro(BaseDistro):
def _configure(self, **kwargs):
super(AwsOpenTelemetryDistro, self)._configure()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

__version__ = "0.0.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase

from opentelemetry.distro.aws_opentelemetry_configurator import (
AwsOpenTelemetryConfigurator,
AwsTracerProvider,
)


class TestAwsOpenTelemetryConfigurator(TestCase):
# pylint: disable=no-self-use
def test_default_configuration(self):
configurator = AwsOpenTelemetryConfigurator()
configurator.configure()
trace_provider = configurator.get_trace_provider()
assert isinstance(trace_provider, AwsTracerProvider)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase

from pkg_resources import DistributionNotFound, require


class TestAwsOpenTelemetryDistro(TestCase):
def test_package_available(self):
try:
require(["aws-opentelemetry-distro"])
except DistributionNotFound:
self.fail("aws-opentelemetry-distro not installed")
19 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ isolated_build = True
skipsdist = True
skip_missing_interpreters = True
envlist =
; aws-opentelemetry-distro
py3{7,8,9,10,11}-test-aws-opentelemetry-distro
pypy3-test-aws-opentelemetry-distro

lint
spellcheck

Expand All @@ -12,9 +16,24 @@ deps =
test: pytest
test: pytest-benchmark

setenv =
; TODO: The two repos branches need manual updated over time, need to figure out a more sustainable solution.
CORE_REPO="git+https://github.com/open-telemetry/opentelemetry-python.git@release/v1.22.x-0.43bx"
CONTRIB_REPO="git+https://github.com/open-telemetry/opentelemetry-python-contrib.git@main"

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

commands_pre =
; Install without -e to test the actual installation
py3{7,8,9,10,11}: python -m pip install -U pip setuptools wheel
; Install common packages for all the tests. These are not needed in all the
; cases but it saves a lot of boilerplate in this file.
test: pip install "opentelemetry-api[test] @ {env:CORE_REPO}#egg=opentelemetry-api&subdirectory=opentelemetry-api"
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

commands =
test: pytest {posargs}
Expand Down

0 comments on commit f4bb1dd

Please sign in to comment.