81 Commits

Author SHA1 Message Date
3c2599c761 opentelemetry-docker-tests: bump grpcio to 1.63.2 (#3290)
To match the baseline added to opencensus exporter.
2025-02-24 11:16:57 +01:00
8e3cd65f28 build(deps): bump certifi in /tests/opentelemetry-docker-tests/tests (#3262)
Bumps [certifi](https://github.com/certifi/python-certifi) from 2024.2.2 to 2024.7.4.
- [Commits](https://github.com/certifi/python-certifi/compare/2024.02.02...2024.07.04)

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
2025-02-19 15:45:40 +00:00
1623dc0e71 fixed: asyncpg connection params are a namedtuple (#3253)
Follow-up on the apparently abbandonned https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2114.

The asyncpg instrumentation attempts to fall back on using the database
name as the span name in case the first argument to the instrumented
method is falsey.

This has probably never worked since asyncpg defines the `_params`
attribute as an instance of `ConnectionParams`
(https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connection.py#L62)
which is a NamedTuple instance and thus don't define `get`. The proper
way of safely accessing properties on a NamedTuple is using `getattr`.

The only case that I've actually found which triggers this branch is if
the supplied query is an empty string. This is something that causes an
`AttributeError` for `Connection.execute` but is fine for `fetch()`,
`fetchval()`, `fetchrow()` and `executemany()`.

The tests have been expanded to check these cases. Also, more status
code validation has been added where it was missing.

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
2025-02-14 08:59:21 +00:00
bf3c0be507 build(deps): bump cryptography (#3259)
Bumps [cryptography](https://github.com/pyca/cryptography) from 42.0.5 to 44.0.1.
- [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pyca/cryptography/compare/42.0.5...44.0.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
2025-02-12 12:28:50 +01:00
59ecd4d608 infra: improve tox for local development (#2999)
* move pip install from command to deps

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* add docker-test-requirements.txt

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* fix celery and docs

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* fix

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* fix tox.ini

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* update docs

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* Update tox.ini

---------

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
2024-12-17 14:24:50 +01:00
0adc58b4bf Introducing ruff as linter and formatter (basic setup) (#2921) 2024-10-23 10:54:14 -07:00
d7d7e96ce5 fix: shellcheck and docker-tests in CI (#2905) 2024-10-15 12:38:03 -07:00
6bb6d3896d Add additional attributes for redis.search methods create_index, search (#2635) 2024-10-02 15:42:33 -07:00
6fcfbd67b8 tests: fix docker-tests mssql (#2878)
* try new image

* try new image with new pyodbc verrsion
2024-09-23 09:44:07 +02:00
6f3aead436 Unwrap Celery's ExceptionInfo (#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
2023-09-03 13:56:33 +03:00
cd6b024327 Fix async redis clients tracing (#1830)
* Fix async redis clients tracing

* Update changelog

* Add functional integration tests and fix linting issues

---------

Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
2023-06-25 15:03:54 +03:00
37d85f0745 Sanitize redis db_statement by default (#1776)
Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
2023-06-13 12:37:55 +00:00
776f9d4643 Fix celery docker tests (#1841) 2023-06-13 10:07:45 +02:00
1a1163e919 Expand sqlalchemy pool.name to follow the semantic conventions (#1778) 2023-05-06 23:09:52 +05:30
3bcc043e9d Add connection attributes to sqlalchemy connect span (#1608)
* Add connection attributes to sqlalchemy connect span

* Fix formatting

* Move changelog entry to unreleased section

---------

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
2023-02-20 17:17:18 +00:00
2b6f913790 Add Redis instrumentation query sanitization (#1572)
* Add Redis instrumentation query sanitization

Add a query sanitizer to the Redis instrumentation. This can be disabled
with the `sanitize_query = False` config option.

Given the query `SET key value`, the sanitized query becomes `SET ? ?`.
Both the keys and values are sanitized, as both can contain PII data.

The Redis queries are sanitized by default. This changes the default
behavior of this instrumentation. Previously it reported unsanitized
Redis queries.

This was previously discussed in the previous implementation of this PR
in PR #1571

Closes #1548

* Update Redis sanitize_query option documentation

Changes suggested in
https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1572#discussion_r1066069584

* Remove uninstrument & instrument from test setup

The Redis test that performs the tests with the default options, doesn't
need to uninstrument and then instrument the instrumentor. This commit
removes the unnecessary setup code. The setup code is already present at
the top of the file.

* Fix code style formatting

* Update Redis functional tests

- Update the sanitizer to also account for a max `db.statement`
  attribute value length. No longer than 1000 characters.
- Update the functional tests to assume the queries are sanitized by
  default.
- Add new tests that test the behavior with sanitization turned off.
  Only for the tests in the first test class. I don't think it's needed
  to duplicate this test for the clustered and async setup combinations.

* Test Redis unsanitized queries by default

Change the Redis functional tests so that they test the unsanitized
query by default, and test the sanitized query results in the separate
test functions.

This is a partial revert of the previous commit
8d56c2f72e12c7d7dc4ef25a9fe6a69ea685a6d8

* Fix formatting issue in Redis utils

* Disable Redis query sanitization by default

Update the Redis instrumentation library to not change the default
behavior for the Redis instrumentation. This can be enabled at a later
time when the spec discussion about this topic has concluded.

https://github.com/open-telemetry/opentelemetry-specification/issues/3104

* Fix pylint issue

Remove else statement.

* Update changelog about Redis query sanitization default

[ci skip]

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>

* Fix potential error on Redis args being 0

Check the length of the args array and return an empty string if there
are no args.

That way it won't cause an IndexError if the args array is empty and it
tries to fetch the first element, which should be the Redis command.

---------

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2023-02-04 14:22:23 +00:00
673e4aadb4 Record exception in Celery instrumentation (#1573)
* Add tests for errors in Celery tasks

I noticed there were no tests for the error scenario in the Celery
package. This commit adds a basic test, based on the previous test and
how I see other packages test the error status on the span.

Part of #987

* Record exception in Celery instrumentation

In addition to setting the status on the span, also record the exception
on the span. This adds an event to the span with more details about the
error, following the format other instrumentations also use.

* Update CHANGELOG with Celery record exception

* Fix lint code formatting issues

* Move Celery error tests to the functional tests

The celery tests failed on Python 3.11. This is most likely due to this
issue in billiard, a celery dependency, about it not working on Python
3.11 because of the error reported in the CI:
https://github.com/celery/billiard/issues/377

It's been fixed in billiard 4.1.0, but celery is locked on billiard
version lower than 4, so it cannot use this version with the fix.

This issue does not arise on the Docker tests, because they use Python
3.9.16.

I've moved the error test span event assertions to the error test that
is available in the functional tests, and removed the unit test. That
way, the build will run successfully.

* Remove duplicate entry in changelog

This was added in a recent merge commit on this PR branch.

* Remove unused test code

With the move of the tests for tasks with errors to the functional
tests, remove the unit test's error task and unused imports.

---------

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2023-02-03 04:30:57 +00:00
78874df5c2 Fix install of Python 3.10 on GitHub Actions (#1609)
* Fix install of Python 3.10 on GitHub Actions

In PR #1604 the Python version was upgraded to Python 3.10 to fix a
local issue on M1 MacBooks.

The GitHub Action workflows now exit with the following message for the
docker-tests, spellcheck and lint checks, skipping these checks.

```
lint create: /home/runner/work/opentelemetry-python-contrib/opentelemetry-python-contrib/.tox/lint
SKIPPED: InterpreterNotFound: python3.10
___________________________________ summary ____________________________________
SKIPPED:  lint: InterpreterNotFound: python3.10
  congratulations :)
```

Upgrade the Python version in the GitHub Actions workflow to fix this.

* Fix YAML interpretation of Python 3.10

* Upgrade Docker tests dependencies

Upgrade the asyncpg and psycopg2 packages, they don't work on Python
3.10.

This also fixes running these tests no M1 MacBooks.

* Fix linter issues merged into main

They went unnoticed while the CI didn't fail on the lint task not
working.

---------

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2023-02-03 08:37:24 +05:30
810d9825cd mongo db - fix db statement capturing (#1512) 2023-01-24 03:15:28 +00:00
70187ff3a3 Pymongo capture collection name (#1555) 2023-01-11 12:47:54 +00:00
be4ceec08c Strip leading comments from SQL queries when generating the span name. (#1434)
Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
2022-11-18 14:01:07 +01:00
5f85a5bd74 Remove db.name attribute from Redis instrumentation (#1427) 2022-11-10 19:21:44 +00:00
40e4e2e598 Fix dbapi connection instrument wrapper has no _sock member (#1424)
Fixes https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1353

Also:

Fix the check for the connection already being instrumented in instrument_connection()
Add tests for commit() and rollback()
Add a couple missing docstring items.
Add basepython to docker-tests to fix running the tests on macOS.
2022-11-07 16:00:28 +00:00
f349e380a2 asyncpg: Use only the first word from query as a span name (#1324) 2022-09-30 16:24:31 +05:30
fbac424515 Add psycopg2 native tags to sqlcommenter (#1203) 2022-07-30 05:14:47 +05:30
7c75b3867b SQLCommenter semicolon bug fix (#1200) 2022-07-22 07:52:40 +05:30
d75194aed7 Sync with sdk setup from setUpClass to setUp (#1193) 2022-07-19 02:02:13 +05:30
2ce69a668f Add span for connection phase (#1134) 2022-07-17 21:09:15 +05:30
8823655b1c Instrument RedisCluster clients (#1177)
* Instrument RedisCluster clients

* reformat files

* update changelogs

* refactor _traced_execute_pipeline

* handle AttributeError

* handle IndexError

* refactor _traced_execute_pipeline

* move hasattr check to _set_connection_attributes function

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2022-07-07 15:00:09 +02:00
fa56c6c09f Instrument redis.asyncio clients (#1076) 2022-05-05 06:39:29 +05:30
e861b93362 Extending SQLCommenter support of dbapi into psycopg2 (#940)
* Added configuration for sqlcommenter

* Fixed linting errors

* Updated CHANGELOG.md

* Unit test case for sqlcommenter in psycopg2

* Merge conflict resolved

* Update CHANGELOG.md

* psycopg2 sqlcommenter integration test

* linting changes

* linting changes

* linting changes

* linting changes

* linting changes

* version compatability issue fix

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
2022-03-17 19:19:30 -06:00
3137c1fa41 Upgrade black (#802) 2021-11-10 20:57:01 +00:00
07c52aad38 Refactor code using pyupgrade for Python 3.6 (#770)
* Refactor code using pyupgrade for Python 3.6

This diff is the result of applying the following command to the
project:

```shell
find . -type f -name "*.py" -exec pyupgrade --py36-plus '{}' +
```

* Simplify yield from
2021-10-24 07:04:06 +05:30
b41a91713e Fix mssql docker tests v4 (#727)
* Remove unneded CI steps

These were not really needed and got in by mistake.

* Fix broken mssql integration tests

We were giving mssql server 10 seconds to start before creating the test
database. It now takes Github CI more than 10 seconds to start the mssql
server. Instead of increasing the leeway with guesses, this commit moves
the creation of test database from docker compose to the python test suite.
This allows the docker image to come up first and then create the DB
inside the test suite with proper retry mechanism that is already in
place.
2021-10-12 17:19:13 +02:00
cc2e7d276b Fix mssql docker tests v2 (#723)
* Pin ubuntu to 20.04 in CI

* Fix mssql docker tests
2021-10-12 01:43:32 +05:30
c4639ee3f5 Fix flaky celery docker test (#652)
The test was actually generating 2 spans but on very fast systems we
only saw one as the test ran faster than the message would travel
through the broker, trigger a task and generate 2nd span.

Switched from .delay() to .apply() so only one span is generated which
is enough for the test in question.
2021-09-02 10:14:38 +02:00
b6e49ba66d Remove unused imports (#646)
* Remove unused imports

Fixes #645

* Fix lint

* Import trace_tween_factory

* Fix lint

* Fix lint

* Fix pylint

* Try without using the symbol

* Fix isort

* Revert "Fix isort"

This reverts commit 4dbd91450b4ee099fd09ab1ca0fb8ae9c10bdcfa.

* Revert "Try without using the symbol"

This reverts commit d94f95564671a3155edf44bf71bf58f22ca309f0.
2021-09-01 19:38:02 +02:00
c279ee59a8 Rerun a flaky test (#639)
* Rerun a flaky test
2021-08-31 03:47:58 +05:30
c6976fc51f Potential fix for flaky celery test (#629)
It seems the same in memory span exporter was being reused by multiple
tests. This change _should_ create a new instance of memeory exporter
per test/function.

Fixes #2067
2021-08-26 03:30:26 +05:30
c8b6de6c1c Add support for SQLAlchemy 1.4 (#568) 2021-08-04 15:00:10 -07:00
b2dd4b8205 Fix pyodbc cursor error in SQLA instrumentation (#469) 2021-06-07 09:11:37 -07:00
a3ecbc1f41 Add SQLAlchemy multithreading test (#468) 2021-06-03 08:33:06 -07:00
8d0c150b31 Sync with auto generated semantic convention constants (#428) 2021-04-19 23:37:10 -07:00
08682f6f1d redis: fix default port KeyError, wrong attr name (#265)
* redis: fix default port KeyError, wrong attr name
* fix docker tests and another ip/port issue in asyncpg

Co-authored-by: Alex Boten <aboten@lightstep.com>
2021-04-14 08:45:36 -07:00
634c2ac0ae Update redis instrumentation to follow semantic conventions (#403) 2021-04-05 11:19:16 -07:00
12da395364 fix instrumentation of connection when pool.acquire was called multiple times (#381) 2021-04-02 16:45:12 -07:00
9315eb0fb2 use StatusCode from trace instead of trace.status (#366) 2021-03-09 14:33:13 -08:00
6720930cdb rename simple/batch span processors (#352) 2021-03-01 13:40:25 -08:00
c265e2f035 Remove metrics from main branch (#312) 2021-02-05 16:41:03 -08:00
b53b9a012f Fix failing aiopg tests (#317) 2021-02-04 17:39:24 -08:00