Skip to content

Commit

Permalink
Merge branch 'main' into loggingBasicConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored May 1, 2024
2 parents 7242297 + 5116305 commit 2d1e863
Show file tree
Hide file tree
Showing 17 changed files with 728 additions and 149 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Lint tests

on:
push:
branches-ignore:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: 955c92e91b5cd4bcfb43c39efcef086b040471d2

jobs:
lint-3_11:
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
package:
- "distro"
- "exporter-prometheus-remote-write"
- "exporter-richconsole"
- "instrumentation-aio-pika"
- "instrumentation-aiohttp-client"
- "instrumentation-aiohttp-server"
- "instrumentation-aiopg"
- "instrumentation-asgi"
- "instrumentation-asyncio"
- "instrumentation-asyncpg"
- "instrumentation-aws-lambda"
- "instrumentation-boto"
- "instrumentation-boto3sqs"
- "instrumentation-botocore"
- "instrumentation-cassandra"
- "instrumentation-celery"
- "instrumentation-confluent-kafka"
- "instrumentation-dbapi"
- "instrumentation-django"
- "instrumentation-elasticsearch"
- "instrumentation-falcon"
- "instrumentation-fastapi"
- "instrumentation-flask"
- "instrumentation-grpc"
- "instrumentation-httpx"
- "instrumentation-jinja2"
- "instrumentation-kafka-python"
- "instrumentation-logging"
- "instrumentation-mysql"
- "instrumentation-mysqlclient"
- "instrumentation-psycopg"
- "instrumentation-psycopg2"
- "instrumentation-pymemcache"
- "instrumentation-pymongo"
- "instrumentation-pymysql"
- "instrumentation-pyramid"
- "instrumentation-redis"
- "instrumentation-remoulade"
- "instrumentation-requests"
- "instrumentation-sio-pika"
- "instrumentation-sqlalchemy"
- "instrumentation-sqlite3"
- "instrumentation-starlette"
- "instrumentation-system-metrics"
- "instrumentation-threading"
- "instrumentation-tornado"
- "instrumentation-tortoiseorm"
- "instrumentation-urllib"
- "instrumentation-urllib3"
- "instrumentation-wsgi"
- "opentelemetry-instrumentation"
- "processor-baggage"
- "propagator-aws-xray"
- "propagator-ot-trace"
- "resource-detector-container"
- "sdk-extension-aws"
os: [ubuntu-20.04]
runs-on: ubuntu-20.04
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install tox
run: pip install tox
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v4
with:
path: |
.tox
~/.cache/pip
key: v7-build-tox-cache-${{ matrix.package }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
- name: run tox
run: tox -e lint-${{ matrix.package }}

lint-3_8:
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
package:
- "instrumentation-sklearn"
os: [ubuntu-20.04]
runs-on: ubuntu-20.04
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install tox
run: pip install tox
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v4
with:
path: |
.tox
~/.cache/pip
key: v7-build-tox-cache-${{ matrix.package }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
- name: run tox
run: tox -e lint-${{ matrix.package }}
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
tox-environment: [ "docker-tests", "spellcheck", "lint", "docs", "generate" ]
tox-environment: [ "docker-tests", "spellcheck", "docs", "generate" ]
name: ${{ matrix.tox-environment }}
runs-on: ubuntu-20.04
steps:
Expand All @@ -25,9 +25,6 @@ jobs:
python-version: "3.10"
- name: Install tox
run: pip install tox
- name: Install libsnappy-dev
if: ${{ matrix.tox-environment == 'lint' }}
run: sudo apt-get install -y libsnappy-dev
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v4
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ You can run `tox` with the following arguments:
- `tox -e py311-test-instrumentation-aiopg` to e.g. run the aiopg instrumentation unit tests under a specific
Python version
- `tox -e spellcheck` to run a spellcheck on all the code
- `tox -e lint` to run lint checks on all code
- `tox -e lint-some-package` to run lint checks on `some-package`

`black` and `isort` are executed when `tox -e lint` is run. The reported errors can be tedious to fix manually.
An easier way to do so is:

1. Run `.tox/lint/bin/black .`
2. Run `.tox/lint/bin/isort .`
1. Run `.tox/lint-some-package/bin/black .`
2. Run `.tox/lint-some-package/bin/isort .`

See
[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/tox.ini)
Expand Down
2 changes: 1 addition & 1 deletion gen-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-c dev-requirements.txt
astor==0.8.1
jinja2~=2.7
jinja2==3.1.3
markupsafe==2.0.1
isort
black
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
from typing import Any, Callable, Dict
from unittest import mock

from tests.mocks.api_gateway_http_api_event import (
MOCK_LAMBDA_API_GATEWAY_HTTP_API_EVENT,
)
from tests.mocks.api_gateway_proxy_event import (
MOCK_LAMBDA_API_GATEWAY_PROXY_EVENT,
)

from opentelemetry.environment_variables import OTEL_PROPAGATORS
from opentelemetry.instrumentation.aws_lambda import (
_HANDLER,
Expand All @@ -45,6 +38,11 @@
TraceContextTextMapPropagator,
)

from .mocks.api_gateway_http_api_event import (
MOCK_LAMBDA_API_GATEWAY_HTTP_API_EVENT,
)
from .mocks.api_gateway_proxy_event import MOCK_LAMBDA_API_GATEWAY_PROXY_EVENT


class MockLambdaContext:
def __init__(self, aws_request_id, invoked_function_arn):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
# pylint:disable=cyclic-import

import grpc
from tests.protobuf import ( # pylint: disable=no-name-in-module
test_server_pb2_grpc,
)

import opentelemetry.instrumentation.grpc
from opentelemetry import trace
Expand All @@ -41,6 +38,7 @@
simple_method_future,
)
from ._server import create_test_server
from .protobuf import test_server_pb2_grpc
from .protobuf.test_server_pb2 import Request


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
from unittest import mock

import grpc
from tests.protobuf import ( # pylint: disable=no-name-in-module
test_server_pb2_grpc,
)

import opentelemetry.instrumentation.grpc
from opentelemetry import trace
Expand All @@ -44,6 +41,7 @@
simple_method_future,
)
from ._server import create_test_server
from .protobuf import test_server_pb2_grpc
from .protobuf.test_server_pb2 import Request


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
# limitations under the License.

import grpc
from tests.protobuf import ( # pylint: disable=no-name-in-module
test_server_pb2_grpc,
)

from opentelemetry import trace
from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient
from opentelemetry.test.test_base import TestBase

from ._client import simple_method
from ._server import create_test_server
from .protobuf import test_server_pb2_grpc


# User defined interceptor. Is used in the tests along with the opentelemetry client interceptor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
MemcacheUnknownError,
)

# pylint: disable=import-error,no-name-in-module
from tests.utils import MockSocket, _str

from opentelemetry import trace as trace_api
from opentelemetry.instrumentation.pymemcache import PymemcacheInstrumentor
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import get_tracer

from .utils import MockSocket, _str

TEST_HOST = "localhost"
TEST_PORT = 117711

Expand Down
12 changes: 11 additions & 1 deletion resource/opentelemetry-resource-detector-azure/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Ignore vm detector if already in other rps
([#2456](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2456))

## Version 0.1.4 (2024-04-05)

- Fix windows tests/suppress instrumentation for urllib call
([#2178](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2178))

## Version 0.1.3 (2024-01-25)

- Change meta data service timeout to 200ms
([#2387](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2387))

## Version 0.1.2 (2024-01-25)
## Version 0.1.1 (2024-01-10)

- Initial CHANGELOG.md entry
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

# pylint: disable=import-error

from .app_service import AzureAppServiceResourceDetector
from .version import __version__
from .vm import AzureVMResourceDetector

__all__ = [
"AzureAppServiceResourceDetector",
"AzureVMResourceDetector",
"__version__",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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 opentelemetry.semconv.resource import ResourceAttributes

# cSpell:disable

# Azure Kubernetes

_AKS_ARM_NAMESPACE_ID = "AKS_ARM_NAMESPACE_ID"

# AppService

_AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE = "azure.app.service.stamp"
_REGION_NAME = "REGION_NAME"
_WEBSITE_HOME_STAMPNAME = "WEBSITE_HOME_STAMPNAME"
_WEBSITE_HOSTNAME = "WEBSITE_HOSTNAME"
_WEBSITE_INSTANCE_ID = "WEBSITE_INSTANCE_ID"
_WEBSITE_OWNER_NAME = "WEBSITE_OWNER_NAME"
_WEBSITE_RESOURCE_GROUP = "WEBSITE_RESOURCE_GROUP"
_WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME"
_WEBSITE_SLOT_NAME = "WEBSITE_SLOT_NAME"

_APP_SERVICE_ATTRIBUTE_ENV_VARS = {
ResourceAttributes.CLOUD_REGION: _REGION_NAME,
ResourceAttributes.DEPLOYMENT_ENVIRONMENT: _WEBSITE_SLOT_NAME,
ResourceAttributes.HOST_ID: _WEBSITE_HOSTNAME,
ResourceAttributes.SERVICE_INSTANCE_ID: _WEBSITE_INSTANCE_ID,
_AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE: _WEBSITE_HOME_STAMPNAME,
}

# Functions

_FUNCTIONS_WORKER_RUNTIME = "FUNCTIONS_WORKER_RUNTIME"

# Vm

_AZURE_VM_METADATA_ENDPOINT = "http://169.254.169.254/metadata/instance/compute?api-version=2021-12-13&format=json"
_AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = "azure.vm.scaleset.name"
_AZURE_VM_SKU_ATTRIBUTE = "azure.vm.sku"

_EXPECTED_AZURE_AMS_ATTRIBUTES = [
_AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,
_AZURE_VM_SKU_ATTRIBUTE,
ResourceAttributes.CLOUD_PLATFORM,
ResourceAttributes.CLOUD_PROVIDER,
ResourceAttributes.CLOUD_REGION,
ResourceAttributes.CLOUD_RESOURCE_ID,
ResourceAttributes.HOST_ID,
ResourceAttributes.HOST_NAME,
ResourceAttributes.HOST_TYPE,
ResourceAttributes.OS_TYPE,
ResourceAttributes.OS_VERSION,
ResourceAttributes.SERVICE_INSTANCE_ID,
]

# cSpell:enable
Loading

0 comments on commit 2d1e863

Please sign in to comment.