Skip to content

Merge main 2 #2199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 13 additions & 41 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ env:
# Otherwise, set variable to the commit of your branch on
# opentelemetry-python-contrib which is compatible with these Core repo
# changes.
CONTRIB_REPO_SHA: 36275f3cbf00c2021caa1d922bd98215c50b9af3
CONTRIB_REPO_SHA: 4a4d889b1876323d7f70507b5e4d079f454fe0d6
# This is needed because we do not clone the core repo in contrib builds anymore.
# When running contrib builds as part of core builds, we use actions/checkout@v2 which
# does not set an environment variable (simply just runs tox), which is different when
# contrib builds are run directly from contrib (since test.yml is executed, which sets CORE_REPO_SHA)
# The solution is to include CORE_REPO_SHA as part of THIS environment so it can be accessed
# from within the contrib build.
CORE_REPO_SHA: ${{ github.sha }}

jobs:
build:
Expand Down Expand Up @@ -104,19 +111,19 @@ jobs:
key: v2-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core
- name: run tox
run: tox -e ${{ matrix.tox-environment }}

# Contrib unit test suite in order to ensure changes in core do not break anything in contrib.
# We only run contrib unit tests on the oldest supported Python version (3.6) as running the same tests
# on all versions is somewhat redundant.
contrib-build:
env:
# We use these variables to convert between tox and GHA version literals
py36: 3.6
py37: 3.7
py38: 3.8
py39: 3.9
pypy3: pypy3
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
python-version: [ py36, py37, py38, py39, pypy3 ]
python-version: [ py36 ]
package: ["instrumentation", "exporter"]
os: [ ubuntu-20.04]
steps:
Expand Down Expand Up @@ -147,38 +154,3 @@ jobs:
key: v2-tox-cache-${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }}
contrib-misc:
strategy:
fail-fast: false
matrix:
tox-environment: [ "docker-tests"]
name: ${{ matrix.tox-environment }}
runs-on: ubuntu-20.04
steps:
- name: Checkout Contrib Repo @ SHA - ${{ env.CONTRIB_REPO_SHA }}
uses: actions/checkout@v2
with:
repository: open-telemetry/opentelemetry-python-contrib
ref: ${{ env.CONTRIB_REPO_SHA }}
- name: Checkout Core Repo @ SHA ${{ github.sha }}
uses: actions/checkout@v2
with:
repository: open-telemetry/opentelemetry-python
path: opentelemetry-python-core
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
architecture: 'x64'
- name: Install tox
run: pip install -U tox
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: |
.tox
~/.cache/pip
key: v2-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.5.0-0.24b0...HEAD)
<<<<<<< HEAD
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.6.0-0.25b0...HEAD)

- Make Measurement a concrete class
([#2153](https://github.com/open-telemetry/opentelemetry-python/pull/2153))
- Add metrics API
([#1887](https://github.com/open-telemetry/opentelemetry-python/pull/1887))

## [1.6.0-0.25b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.6.0-0.25b0) - 2021-10-13

- Fix race in `set_tracer_provider()`
([#2182](https://github.com/open-telemetry/opentelemetry-python/pull/2182))
- Automatically load OTEL environment variables as options for `opentelemetry-instrument`
Expand Down Expand Up @@ -39,6 +41,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2145](https://github.com/open-telemetry/opentelemetry-python/pull/2145))
- Add `schema_url` to `TracerProvider.get_tracer`
([#2154](https://github.com/open-telemetry/opentelemetry-python/pull/2154))
- Make baggage implementation w3c spec complaint
([#2167](https://github.com/open-telemetry/opentelemetry-python/pull/2167))
- Add name to `BatchSpanProcessor` worker thread
([#2186](https://github.com/open-telemetry/opentelemetry-python/pull/2186))

## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26

Expand Down
4 changes: 2 additions & 2 deletions eachdist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sortfirst=
exporter/*

[stable]
version=1.5.0
version=1.6.0

packages=
opentelemetry-sdk
Expand All @@ -31,7 +31,7 @@ packages=
opentelemetry-api

[prerelease]
version=0.24b0
version=0.25b0

packages=
opentelemetry-opentracing-shim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
4 changes: 2 additions & 2 deletions exporter/opentelemetry-exporter-jaeger/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ python_requires = >=3.6

packages=find_namespace:
install_requires =
opentelemetry-exporter-jaeger-proto-grpc == 1.5.0
opentelemetry-exporter-jaeger-thrift == 1.5.0
opentelemetry-exporter-jaeger-proto-grpc == 1.6.0
opentelemetry-exporter-jaeger-thrift == 1.6.0

[options.extras_require]
test =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.24b0"
__version__ = "0.25b0"
2 changes: 1 addition & 1 deletion exporter/opentelemetry-exporter-otlp-proto-grpc/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install_requires =
googleapis-common-protos ~= 1.52
opentelemetry-api ~= 1.3
opentelemetry-sdk ~= 1.3
opentelemetry-proto == 1.5.0
opentelemetry-proto == 1.6.0
backoff ~= 1.10.0

[options.extras_require]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
2 changes: 1 addition & 1 deletion exporter/opentelemetry-exporter-otlp-proto-http/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install_requires =
googleapis-common-protos ~= 1.52
opentelemetry-api ~= 1.3
opentelemetry-sdk ~= 1.3
opentelemetry-proto == 1.5.0
opentelemetry-proto == 1.6.0
backoff ~= 1.10.0

[options.extras_require]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
4 changes: 2 additions & 2 deletions exporter/opentelemetry-exporter-otlp/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ classifiers =
python_requires = >=3.6
packages=find_namespace:
install_requires =
opentelemetry-exporter-otlp-proto-grpc == 1.5.0
opentelemetry-exporter-otlp-proto-http == 1.5.0
opentelemetry-exporter-otlp-proto-grpc == 1.6.0
opentelemetry-exporter-otlp-proto-http == 1.6.0

[options.entry_points]
opentelemetry_traces_exporter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ install_requires =
requests ~= 2.7
opentelemetry-api ~= 1.3
opentelemetry-sdk ~= 1.3
opentelemetry-exporter-zipkin-json == 1.5.0
opentelemetry-exporter-zipkin-json == 1.6.0

[options.packages.find]
where = src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
4 changes: 2 additions & 2 deletions exporter/opentelemetry-exporter-zipkin/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ classifiers =
python_requires = >=3.6
packages=find_namespace:
install_requires =
opentelemetry-exporter-zipkin-json == 1.5.0
opentelemetry-exporter-zipkin-proto-http == 1.5.0
opentelemetry-exporter-zipkin-json == 1.6.0
opentelemetry-exporter-zipkin-proto-http == 1.6.0

[options.extras_require]
test =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.5.0"
__version__ = "1.6.0"
60 changes: 49 additions & 11 deletions opentelemetry-api/src/opentelemetry/baggage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import typing
from logging import getLogger
from re import compile
from types import MappingProxyType
from typing import Mapping, Optional

from opentelemetry.context import create_key, get_value, set_value
from opentelemetry.context.context import Context
from opentelemetry.util.re import (
_BAGGAGE_PROPERTY_FORMAT,
_KEY_FORMAT,
_VALUE_FORMAT,
)

_BAGGAGE_KEY = create_key("baggage")
_logger = getLogger(__name__)

_KEY_PATTERN = compile(_KEY_FORMAT)
_VALUE_PATTERN = compile(_VALUE_FORMAT)
_PROPERT_PATTERN = compile(_BAGGAGE_PROPERTY_FORMAT)


def get_all(
context: typing.Optional[Context] = None,
) -> typing.Mapping[str, object]:
context: Optional[Context] = None,
) -> Mapping[str, object]:
"""Returns the name/value pairs in the Baggage

Args:
Expand All @@ -39,8 +51,8 @@ def get_all(


def get_baggage(
name: str, context: typing.Optional[Context] = None
) -> typing.Optional[object]:
name: str, context: Optional[Context] = None
) -> Optional[object]:
"""Provides access to the value for a name/value pair in the
Baggage

Expand All @@ -56,7 +68,7 @@ def get_baggage(


def set_baggage(
name: str, value: object, context: typing.Optional[Context] = None
name: str, value: object, context: Optional[Context] = None
) -> Context:
"""Sets a value in the Baggage

Expand All @@ -69,13 +81,20 @@ def set_baggage(
A Context with the value updated
"""
baggage = dict(get_all(context=context))
baggage[name] = value
if not _is_valid_key(name):
_logger.warning(
"Baggage key `%s` does not match format, ignoring", name
)
elif not _is_valid_value(str(value)):
_logger.warning(
"Baggage value `%s` does not match format, ignoring", value
)
else:
baggage[name] = value
return set_value(_BAGGAGE_KEY, baggage, context=context)


def remove_baggage(
name: str, context: typing.Optional[Context] = None
) -> Context:
def remove_baggage(name: str, context: Optional[Context] = None) -> Context:
"""Removes a value from the Baggage

Args:
Expand All @@ -91,7 +110,7 @@ def remove_baggage(
return set_value(_BAGGAGE_KEY, baggage, context=context)


def clear(context: typing.Optional[Context] = None) -> Context:
def clear(context: Optional[Context] = None) -> Context:
"""Removes all values from the Baggage

Args:
Expand All @@ -101,3 +120,22 @@ def clear(context: typing.Optional[Context] = None) -> Context:
A Context with all baggage entries removed
"""
return set_value(_BAGGAGE_KEY, {}, context=context)


def _is_valid_key(name: str) -> bool:
return _KEY_PATTERN.fullmatch(str(name)) is not None


def _is_valid_value(value: object) -> bool:
parts = str(value).split(";")
is_valid_value = _VALUE_PATTERN.fullmatch(parts[0]) is not None
if len(parts) > 1: # one or more properties metadata
for property in parts[1:]:
if _PROPERT_PATTERN.fullmatch(property) is None:
is_valid_value = False
break
return is_valid_value


def _is_valid_pair(key: str, value: str) -> bool:
return _is_valid_key(key) and _is_valid_value(value)
Loading