Skip to content

POtel implementation base branch #3152

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

Draft
wants to merge 363 commits into
base: master
Choose a base branch
from
Draft

POtel implementation base branch #3152

wants to merge 363 commits into from

Conversation

sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Jun 10, 2024

Full state of CI: #3744

Contains:

Simple test

import sentry_sdk
from time import sleep

sentry_sdk.init(
    debug=True,
    traces_sample_rate=1.0,
    _experiments={"otel_powered_performance": True},
)

with sentry_sdk.start_span(description="sentry request"):
    sleep(0.1)
    with sentry_sdk.start_span(description="sentry db"):
        sleep(0.5)
        with sentry_sdk.start_span(description="sentry redis"):
            sleep(0.2)
    with sentry_sdk.start_span(description="sentry http"):
        sleep(1)

References

Misc

In OTel, this:

with tracer.start_as_current_span("parent") as parent:
    with tracer.start_span("child1"):
        pass
    with tracer.start_span("child2"):
        pass

is equivalent to

from opentelemetry import trace, context

parent = tracer.start_span("parent")

# Creates a Context object with parent set as current span
ctx = trace.set_span_in_context(parent)

# Set as the implicit current context
token = context.attach(ctx)

# Child will automatically be a child of parent
child1 = tracer.start_span("child1")
child1.end()

# Child will automatically be a child of parent
child2 = tracer.start_span("child2")
child2.end()

# Don't forget to detach or parent will remain the parent above this call stack
context.detach(token)
parent.end()

@sl0thentr0py sl0thentr0py requested a review from sentrivana June 10, 2024 19:00
@sl0thentr0py sl0thentr0py force-pushed the potel-base branch 2 times, most recently from f7f153c to 28effd6 Compare June 11, 2024 11:43
@sl0thentr0py sl0thentr0py force-pushed the potel-base branch 2 times, most recently from 16f9341 to 951477f Compare June 25, 2024 15:16
Copy link

codecov bot commented Jun 26, 2024

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
20648 2 20646 4359
View the top 2 failed test(s) by shortest run time
::tests.integrations.redis.test_redis
Stack Traces | 0s run time
ImportError while importing test module '.../integrations/redis/test_redis.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
.../hostedtoolcache/Python/3.8.18.../x64/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
    ???
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
.tox/py3.8-redis-v3/lib/python3.8.../_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
.../integrations/redis/test_redis.py:4: in <module>
    from fakeredis import FakeStrictRedis
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/__init__.py:3: in <module>
    from ._connection import (
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/_connection.py:10: in <module>
    from fakeredis._fakesocket import FakeSocket
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/_fakesocket.py:3: in <module>
    from fakeredis.commands_mixins import (
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/commands_mixins/__init__.py:3: in <module>
    from .acl_mixin import AclCommandsMixin
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/commands_mixins/acl_mixin.py:7: in <module>
    from fakeredis.model import AccessControlList
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/model/__init__.py:1: in <module>
    from ._expiring_members_set import ExpiringMembersSet
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/model/_expiring_members_set.py:5: in <module>
    from fakeredis.typing import Self
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/typing.py:7: in <module>
    from async_timeout import timeout as async_timeout
E   ModuleNotFoundError: No module named 'async_timeout'
::tests.integrations.redis.test_redis_cache_module
Stack Traces | 0s run time
ImportError while importing test module '.../integrations/redis/test_redis_cache_module.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
.../hostedtoolcache/Python/3.8.18.../x64/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
    ???
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
.tox/py3.8-redis-v3/lib/python3.8.../_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
.../integrations/redis/test_redis_cache_module.py:5: in <module>
    import fakeredis
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/__init__.py:3: in <module>
    from ._connection import (
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/_connection.py:10: in <module>
    from fakeredis._fakesocket import FakeSocket
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/_fakesocket.py:3: in <module>
    from fakeredis.commands_mixins import (
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/commands_mixins/__init__.py:3: in <module>
    from .acl_mixin import AclCommandsMixin
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/commands_mixins/acl_mixin.py:7: in <module>
    from fakeredis.model import AccessControlList
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/model/__init__.py:1: in <module>
    from ._expiring_members_set import ExpiringMembersSet
.tox/py3.8-redis-v3/lib/python3.8.../fakeredis/model/_expiring_members_set.py:5: in <module>
    from fakeredis.typing import Self
.tox/py3.8-redis-v3/lib/python3.8.../site-packages/fakeredis/typing.py:7: in <module>
    from async_timeout import timeout as async_timeout
E   ModuleNotFoundError: No module named 'async_timeout'

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@sl0thentr0py sl0thentr0py changed the title Skeletons for new POTEL components New POTEL base branch Jul 9, 2024
@sl0thentr0py sl0thentr0py changed the title New POTEL base branch potel implementation base branch Jul 9, 2024
@antonpirker antonpirker changed the title potel implementation base branch POtel implementation base branch Aug 5, 2024
@sentrivana sentrivana removed their request for review August 28, 2024 09:12
antonpirker and others added 18 commits November 5, 2024 13:53
* Don't default to OK span status for UNSET, this breaks older behavior
* Set transaction name manually on scope after isolation (we should
  generally do this everywhere)
…3748)

If this option is on, we will only create a new underlying otel span if
there's an active valid parent, otherwise we will just return an invalid
`NonRecordingSpan` (`INVALID_SPAN`).

All internal integration child `start_span` calls have been modified so that
now we will only create spans if there is an active root span
(transaction) active.
mainly some middleware span reordering
* Fix transaction name setting and forked some tests to make them work in potel

* Transactions in transactins is undefined behavior, so remove this.
- Add support for the sampled flag for start_span and respect it when making sampling decisions.
- Rework sampling_context in traces_sampler to work with span attributes instead. Make sure we still have the same data accessible as now.

We could go one step further and change the format of sampling_context to just be the actual span attributes without any postprocessing into the current format. I kept the format in line with what we have now to make it easier to update.

See #3746
Closes #3739

This is a breaking change since we're removing custom_sampling_context. It'll break multiple integrations until we fix them (see #3746).
Remove explicit trace_id passing
sentrivana and others added 30 commits May 7, 2025 09:49
Not using plain strings, but always use `SPANDATA`. Follow up to this
PR: #4373
…correct in context manager regardless of source of span (#4439)

closes #3509
We don't use the `client` parameter in the `Scope`'s constructor,
perhaps we can remove it and simplify the API. It is still possible to
set the client with `Scope.set_client`.

BREAKING CHANGE: `sentry_sdk.Scope` no longer has a `client` parameter.

<!-- Describe your PR here -->

---

Thank you for contributing to `sentry-python`! Please add tests to
validate your changes, and lint your code using `tox -e linters`.

Running the test suite on your PR might require maintainer approval.
Currently, this test only asserts that the `traces_sampler` is called at
least once with the given arguments. However, we would expect it to be
called exactly once.

This PR changes the assertion to assert that the `traces_sampler` was
called exactly one time, and that that call included the given
arguments.

<!-- Describe your PR here -->

---

Thank you for contributing to `sentry-python`! Please add tests to
validate your changes, and lint your code using `tox -e linters`.

Running the test suite on your PR might require maintainer approval.
If a `TracerProvider` already exists, patch it. `TracerProvider` is a
singleton, so if we aren't the first ones setting it up, we need to use
the existing one.

In tests, reset `TracerProvider` after each test so that we start with a
clean slate and it gets set up anew on init.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants