Skip to content

Commit

Permalink
merge upstream changes to coralogix-python-dev (#6)
Browse files Browse the repository at this point in the history
* Add otelTraceSampled to instrumetation-logging (open-telemetry#1773)

* Add otelTraceSampled to instrumetation-logging

* Updated code with black

* Added to CHANGELOG.md

---------

Co-authored-by: Srikanth Chekuri <[email protected]>

* Expand sqlalchemy pool.name to follow the semantic conventions (open-telemetry#1778)

* Skip requests tests for pypy3 (open-telemetry#1806)

* Update version to 1.19.0.dev/0.40b0.dev (open-telemetry#1797)

Co-authored-by: Diego Hurtado <[email protected]>
Co-authored-by: Srikanth Chekuri <[email protected]>

* Resource detector for container properties (open-telemetry#1584)

Co-authored-by: Diego Hurtado <[email protected]>
Co-authored-by: Srikanth Chekuri <[email protected]>
Co-authored-by: Leighton Chen <[email protected]>

* botocore: always use x-ray for http header injection (open-telemetry#1741)

Co-authored-by: Diego Hurtado <[email protected]>

* Refactor CODEOWNERS file (open-telemetry#1804)

* Refactor CODEOWNERS file

Fixes open-telemetry#1803

* Remove CODEOWNERS

* Refactor component owners configuration

* Refactor CODEOWNERS to select any file but the ones in instrumentation

---------

Co-authored-by: Shalev Roda <[email protected]>

* Update maintainers list (open-telemetry#1817)

* skip urllib3 test on pypy3 (open-telemetry#1826)

* Fix celery docker tests (open-telemetry#1841)

* Use HTTP mock server for aiohttp tests (open-telemetry#1849)

Fixes open-telemetry#1842

* Use HTTP mock server for tornado tests (open-telemetry#1855)

* Use HTTP mock server for tornado tests

Fixes open-telemetry#1681

* Fix lint

* Remove use of httpbin (open-telemetry#1854)

* Use `request_ctx` to determine whether or not `_teardown_request` should end flask span (open-telemetry#1692)

Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Diego Hurtado <[email protected]>

* remove srikanthccv from maintainers (open-telemetry#1792)

Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Diego Hurtado <[email protected]>

* Sanitize redis db_statement by default (open-telemetry#1776)

Co-authored-by: Srikanth Chekuri <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>

* Relax httpx version to allow >= 0.18.0 (open-telemetry#1748)

* Issue open-telemetry#1757 - Update HTTP server/client instrumentation span names (open-telemetry#1759)

Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Srikanth Chekuri <[email protected]>

* Fix falcon usage of Span Status (open-telemetry#1840)

* Fix falcon usage of Span Status to only set the description if the status code is ERROR

* Update changelog

* Update CHANGELOG.md

Co-authored-by: Srikanth Chekuri <[email protected]>

* fix lint

* Use fewer variables to satisfy R0914 lint rule

---------

Co-authored-by: Srikanth Chekuri <[email protected]>

* Request Flask attributes passed to Sampler (open-telemetry#1784)

* Request Flask attributes passed to Sampler

* Update changelog

* Lint

* Fix botocore test keyerror

* Revert "Fix botocore test keyerror"

This reverts commit fd03c55.

* botocore test does get_queue_url

* Revert "botocore test does get_queue_url"

This reverts commit 9530cd2.

* Update changelog

---------

Co-authored-by: Srikanth Chekuri <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>

* Fixed urllib3 instrumentation example in instrumentation documentation (open-telemetry#1793)

* corrected instrumentation example in urllib3

* Remove changelog entry

---------

Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Diego Hurtado <[email protected]>

* Fix Invalid type NoneType for attribute X error | AWS-Lambda instrumentation (open-telemetry#1785)

* Add None checking to the aws-lambda logic

* Update changelog.

* Change .get() check to 'key' in dict check.

* Fix consistency issues.

* Update changelog.

---------

Co-authored-by: Srikanth Chekuri <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>

* Add metrics instrumentation celery (open-telemetry#1679)

Co-authored-by: Shalev Roda <[email protected]>

* Add support for confluent_kafka until 2.1.1 version (open-telemetry#1815)

* Add support for confulent_kafka until 2.1.1 version

* Include 2.1.1 version

* update CHANGELOG.md

* run: 'tox -e generate'

* resolve comments

* update top version to 2.2.0

---------

Co-authored-by: Ran Nozik <[email protected]>

* fix redis doc (open-telemetry#1808)

doc string rendered at
https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/redis/redis.html
refers to `opentelemetry-instrumentation` executable which appears to be a typo

Co-authored-by: Shalev Roda <[email protected]>

* Add http.server.response.size metric to ASGI implementation. (open-telemetry#1789)

* Add http.server.response.size metric to ASGI implementation.
Add new unit tests.

* Update changelog.

* Fix linting by disabling too-many-nested-blocks

* Put new logic in a new method

* Refactor the placement of new logic.

* Fixed the unit tests in FastAPI and Starlette

* Update changelog.

* FIx lint errors.

* Refactor getting content-length header

* Refactor getting content-length header

---------

Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Diego Hurtado <[email protected]>

* fix: Update falcon instrumentation to follow semantic conventions (open-telemetry#1824)

* fix: Update falcon instrumentation to follow semantic conventions

* docs: Update changelog

* fix linter errors

* Disable falcon.HTTP_200 pylint checck

---------

Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Srikanth Chekuri <[email protected]>

* Bump requests from 2.28.1 to 2.31.0 (open-telemetry#1818)

Bumps [requests](https://github.com/psf/requests) from 2.28.1 to 2.31.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](psf/requests@v2.28.1...v2.31.0)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Shalev Roda <[email protected]>

* fix(grpc): Allow gRPC connections via Unix socket (open-telemetry#1833)

* fix(grpc): Allow gRPC connections via Unix socket

This commit addresses issue open-telemetry#1832.

The way `NET_PEER_IP` and `NET_PEER_PORT` are retrieved raises a `ValueError`
when gRPC connections are handled via Unix sockets.

```py
ip, port = (
    context.peer().split(",")[0].split(":", 1)[1].rsplit(":", 1)
)
```

When using an address like `unix:///tmp/grpc.sock` the value of `context.peer()` is `"unix:"`.
Substituting that in the function above...

```py
ip, port = "unix:".split(",")[0].split(":", 1)[1].rsplit(":", 1)
ip, port = ["unix:"][0].split(":", 1)[1].rsplit(":", 1)
ip, port = "unix:".split(":", 1)[1].rsplit(":", 1)
ip, port = ["unix", ""][1].rsplit(":", 1)
ip, port = "".rsplit(":", 1)
ip, port = [""]  # ValueError
```

I "addressed" the issue by guarding the retrieval of `net.peer.*` values under
an `if` statement that checks if we are using a Unix socket.

I extended the `server_interceptor` tests to run against TCP and Unix socket configurations.

---

**Open Questions**

- [ ] The socket tests will fail on Windows. Is there a way to annotate that?
- [ ] Are there other span values we should be setting for the unix socket?

* Update CHANGELOG

* Add placeholder attributes for linter

* fix lint

---------

Co-authored-by: Matt Oberle <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>

* Add http.server.request.size for ASGI metric implementation (open-telemetry#1867)

* Update changelog file.

* Update changelog file.

* Add new request.size metric for ASGI middleware.

* Clean-up.

* Refactor try except section.

---------

Co-authored-by: Shalev Roda <[email protected]>

* Fix elastic-search sanitization for bulk queries (open-telemetry#1870)

* support sanitization for str body response

* add CHANGELOG entry

---------

Co-authored-by: Shalev Roda <[email protected]>

* Add conditional elastic_transport import (open-telemetry#1810)

* Add conditional elastic_transport import

* Update changelog

* Add future es8 tests

* Update CHANGELOG.md

Co-authored-by: Diego Hurtado <[email protected]>

* Add license, rm pylint disable

* Consistent elastic version check

* lint import

* Update CHANGELOG.md

---------

Co-authored-by: Diego Hurtado <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>

* Fix async redis clients tracing (open-telemetry#1830)

* Fix async redis clients tracing

* Update changelog

* Add functional integration tests and fix linting issues

---------

Co-authored-by: Shalev Roda <[email protected]>

* Update maintainers list (open-telemetry#1874)

* Use a weak reference to sqlalchemy Engine to avoid memory leak (open-telemetry#1771)

* Use a weak reference to sqlalchemy Engine to avoid memory leak

Closes open-telemetry#1761

By using a weak reference to the `Engine` object, we can avoid the memory leak as disposed `Engines` get properly deallocated. Whenever `SQLAlchemy` is uninstrumented, we only trigger a removal for those event listeners which are listening for objects that haven't been garbage-collected yet.

* Made a mistake in resolving the weak reference

* Fixed formatting issues

* Updated changelog

* Added unit test to check that engine was garbage collected

* Do not save engine in EngineTracer to avoid memory leak

* Add an empty line to satisfy black formatter

* Fix isort complaints

* Fixed the issue when pool name is not set and =None

* Fix formatting issue

* Rebased after changes in a recent commit

* Updated PR number in changelog

---------

Co-authored-by: Shalev Roda <[email protected]>

* sqlalchemy wrap_create_engine now accepts sqlcommenter options (open-telemetry#1873)

* sqlalchemy wrap_create_engine accepts sqlcommenter options

* Changelog

* Lint

* Fix default val

* Add sqlalchemy tests

* Change a default in _instrument get

* Lint

* More lint

* Update default

Co-authored-by: Shalev Roda <[email protected]>

* Update args doc

* lintttt

---------

Co-authored-by: Shalev Roda <[email protected]>

* Add statement of maintainership (open-telemetry#1859)

Co-authored-by: Shalev Roda <[email protected]>

* urllib3: Add instrumentation support for version 2 (open-telemetry#1879)

* urllib3: Add instrumentation support for version 2

* changelog

* Distro selection (open-telemetry#1823)

* fix(django): avoid empty span name on empty path (open-telemetry#1788)

Co-authored-by: Srikanth Chekuri <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Diego Hurtado <[email protected]>

* Instrument mysqlclient library (open-telemetry#1744)

Co-authored-by: Diego Hurtado <[email protected]>

* Update version to 1.20.0.dev/0.41b0.dev (open-telemetry#1885)

Co-authored-by: Diego Hurtado <[email protected]>

* Fix pyyaml version (open-telemetry#1892)

* update awslambda to use _X_AMZN_TRACE_ID as a Span Link (open-telemetry#1657)

Co-authored-by: Ron Yishai <[email protected]>
Co-authored-by: Srikanth Chekuri <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: Diego Hurtado <[email protected]>

* Fix UnboundLocalError local variable 'start' referenced before assignment (open-telemetry#1889)

Co-authored-by: Pablo Collins <[email protected]>

* Merge pull request from GHSA-5rv5-6h4r-h22v

* Fix unbound cardinality for label http_method in wsgi based middlewares

* cr: rename file

* cr: change label UNKNOWN to NONSTANDARD

* Update instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py

---------

Co-authored-by: Diego Hurtado <[email protected]>

* Fix errors introduced in regression (open-telemetry#1913)

* Azure resource detectors (open-telemetry#1901)

* Revert "update awslambda to use _X_AMZN_TRACE_ID as a Span Link" (open-telemetry#1911)

Co-authored-by: Diego Hurtado <[email protected]>

* feat(confluent-kafka): Add instrumentation to consume method (open-telemetry#1786)

Co-authored-by: Diego Hurtado <[email protected]>

* Add Cassandra instrumentation (open-telemetry#1902)

* Unwrap Celery's `ExceptionInfo` (open-telemetry#1863)

* Unwrap `ExceptionInfo` and `ExceptionWithTraceback`

Instead of reporting the `ExceptionInfo` and `ExceptionWithTraceback`
wrappers raised by Celery, report the exceptions that they wrap.

This ensures that the exception in the OpenTelemetry span has a type
and traceback that are meaningful and relevant to the developer.

* Fix typo

The exception is expected, not excepted. Well, I guess it is also
excepted, because it's an exception, but you get what I mean.

* Reformat file with `black`

Reformat the `__init__.py` file in the Celery instrumentation using
`black`, fixing a CI linter error.

* Address review feedback

Use the VERSION attribute exposed by Billiard to decide whether to
import ExceptionWithTraceback.

Add a test for a failing task and check that the exceptions' type
and message are preserved.

* Amend ExceptionWithTraceback import

* doc: fix `commenter_options` type (open-telemetry#1926)

Co-authored-by: Shalev Roda <[email protected]>

* Update version to 1.21.0.dev/0.42b0.dev (open-telemetry#1930)

Co-authored-by: Diego Hurtado <[email protected]>

* Modify eachdist and build script for container packages (open-telemetry#1949)

* Update pyproject.toml (open-telemetry#1950)

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Nahian-Al Hasan <[email protected]>
Co-authored-by: Srikanth Chekuri <[email protected]>
Co-authored-by: Shalev Roda <[email protected]>
Co-authored-by: OpenTelemetry Bot <[email protected]>
Co-authored-by: Diego Hurtado <[email protected]>
Co-authored-by: Sanket Mehta <[email protected]>
Co-authored-by: Leighton Chen <[email protected]>
Co-authored-by: Tristan Sloughter <[email protected]>
Co-authored-by: Matthew Grossman <[email protected]>
Co-authored-by: Nimrod Shlagman <[email protected]>
Co-authored-by: Phillip Verheyden <[email protected]>
Co-authored-by: Maciej Nachtygal <[email protected]>
Co-authored-by: Filip Nikolovski <[email protected]>
Co-authored-by: Tammy Baylis <[email protected]>
Co-authored-by: Yashaswi Makula <[email protected]>
Co-authored-by: Iman Shafiei <[email protected]>
Co-authored-by: Akochavi <[email protected]>
Co-authored-by: David Gonoradsky <[email protected]>
Co-authored-by: Ran Nozik <[email protected]>
Co-authored-by: Pablo Collins <[email protected]>
Co-authored-by: Iman Shafiei <[email protected]>
Co-authored-by: Michael <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matt Oberle <[email protected]>
Co-authored-by: Matt Oberle <[email protected]>
Co-authored-by: Vivanov98 <[email protected]>
Co-authored-by: Rytis Bagdziunas <[email protected]>
Co-authored-by: Mario Jonke <[email protected]>
Co-authored-by: Jeremy Voss <[email protected]>
Co-authored-by: Marc Dougherty <[email protected]>
Co-authored-by: Alexandre Papin <[email protected]>
Co-authored-by: Ron Yishai <[email protected]>
Co-authored-by: Thomas LÉVEIL <[email protected]>
Co-authored-by: Jakub Warczarek <[email protected]>
Co-authored-by: Raphael Philipe Mendes da Silva <[email protected]>
Co-authored-by: Javier Fernández Rodríguez <[email protected]>
Co-authored-by: mattcontinisio <[email protected]>
Co-authored-by: Noemi <[email protected]>
Co-authored-by: João Thallis <[email protected]>
  • Loading branch information
Show file tree
Hide file tree
Showing 13 changed files with 1,613 additions and 2 deletions.
85 changes: 84 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,89 @@ env:
CORE_REPO_SHA: 955c92e91b5cd4bcfb43c39efcef086b040471d2

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: ["instrumentation", "distro", "exporter", "sdkextension", "propagator", "resource"]
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', 'gen-requirements.txt', 'dev-requirements.txt') }}
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
# - name: Find and merge ${{ matrix.package }} benchmarks
# # TODO: Add at least one benchmark to every package type to remove this (#249)
# if: matrix.package == 'sdkextension' || matrix.package == 'propagator'
# run: >-
# mkdir -p benchmarks;
# jq -s '.[0].benchmarks = ([.[].benchmarks] | add)
# | if .[0].benchmarks == null then null else .[0] end'
# **/**/tests/*${{ matrix.package }}*-benchmark.json > benchmarks/output_${{ matrix.package }}.json
# - name: Upload all benchmarks under same key as an artifact
# if: ${{ success() }}
# uses: actions/upload-artifact@v2
# with:
# name: benchmarks
# path: benchmarks/output_${{ matrix.package }}.json
# combine-benchmarks:
# runs-on: ubuntu-latest
# needs: build
# if: ${{ always() }}
# name: Combine benchmarks from previous build job
# steps:
# - name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
# uses: actions/checkout@v2
# - name: Download all benchmarks as artifact using key
# uses: actions/download-artifact@v2
# with:
# name: benchmarks
# path: benchmarks
# - name: Find and merge all benchmarks
# run: >-
# jq -s '.[0].benchmarks = ([.[].benchmarks] | add)
# | if .[0].benchmarks == null then null else .[0] end'
# benchmarks/output_*.json > output.json;
# - name: Report on benchmark results
# uses: benchmark-action/github-action-benchmark@v1
# with:
# name: OpenTelemetry Python Benchmarks - Python ${{ env[matrix.python-version ]}} - ${{ matrix.package }}
# tool: pytest
# output-file-path: output.json
# github-token: ${{ secrets.GITHUB_TOKEN }}
# max-items-in-chart: 100
# # Alert with a commit comment on possible performance regression
# alert-threshold: 200%
# fail-on-alert: true
# # Make a commit on `gh-pages` with benchmarks from previous step
# auto-push: ${{ github.ref == 'refs/heads/main' }}
# gh-pages-branch: gh-pages
# benchmark-data-dir-path: benchmarks
misc:
strategy:
fail-fast: false
Expand All @@ -24,7 +107,7 @@ jobs:
with:
python-version: "3.10"
- name: Install tox
run: pip install tox
run: pip install tox==3.27.1
- name: Install libsnappy-dev
if: ${{ matrix.tox-environment == 'lint' }}
run: sudo apt-get install -y libsnappy-dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,16 @@ def __init__(
unit="By",
description="Measures the size of HTTP request messages (compressed).",
)
self.server_response_size_histogram = self.meter.create_histogram(
name=MetricInstruments.HTTP_SERVER_RESPONSE_SIZE,
unit="By",
description="measures the size of HTTP response messages (compressed).",
)
self.server_request_size_histogram = self.meter.create_histogram(
name=MetricInstruments.HTTP_SERVER_REQUEST_SIZE,
unit="By",
description="Measures the size of HTTP request messages (compressed).",
)
self.active_requests_counter = self.meter.create_up_down_counter(
name=MetricInstruments.HTTP_SERVER_ACTIVE_REQUESTS,
unit="requests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
attributes["rpc.request.payload"] = limit_string_size(self.payload_size_limit,json.dumps(body, default=str))
elif call_context.service == "events" and call_context.operation == "PutEvents":
call_context.span_kind = SpanKind.PRODUCER
attributes["rpc.request.payload"] = limit_string_size(self.payload_size_limit, json.dumps(call_context.params, default=str))
else:
attributes["rpc.request.payload"] = limit_string_size(self.payload_size_limit, json.dumps(call_context.params, default=str))
except Exception as ex:
Expand Down Expand Up @@ -483,7 +484,7 @@ def set(
val = {"DataType": "String", "StringValue": value}
carrier[key] = val

def limit_string_size(s: str, max_size: int) -> str:
def limit_string_size(max_size: int, s: str) -> str:
if len(s) > max_size:
return s[:max_size]
else:
Expand Down
Loading

0 comments on commit 73c5a8b

Please sign in to comment.