Skip to content

Commit

Permalink
ref(tracing): Move TRANSACTION_SOURCE_* constants to Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaligniana committed Dec 23, 2024
1 parent f6281f5 commit 3082f96
Show file tree
Hide file tree
Showing 45 changed files with 140 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- name: Get auth token
id: token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
with:
app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }}
private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-ai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-integrations-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-integrations-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-dbs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-web-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-integrations-web-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down Expand Up @@ -192,7 +192,7 @@ jobs:
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ By: @mgaligniana (#1773)

import sentry_sdk
from sentry_sdk.integrations.arq import ArqIntegration
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT
from sentry_sdk.tracing import TransactionSource

sentry_sdk.init(
dsn="...",
Expand All @@ -2246,7 +2246,7 @@ By: @mgaligniana (#1773)
await ctx['session'].aclose()

async def main():
with sentry_sdk.start_transaction(name="testing_arq_tasks", source=TRANSACTION_SOURCE_COMPONENT):
with sentry_sdk.start_transaction(name="testing_arq_tasks", source=TransactionSource.COMPONENT):
redis = await create_pool(RedisSettings())
for url in ('https://facebook.com', 'https://microsoft.com', 'https://github.com', "asdf"
):
Expand Down Expand Up @@ -2320,7 +2320,7 @@ By: @mgaligniana (#1773)

import sentry_sdk
from sentry_sdk.integrations.huey import HueyIntegration
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT, Transaction
from sentry_sdk.tracing import TransactionSource, Transaction


def main():
Expand All @@ -2332,7 +2332,7 @@ By: @mgaligniana (#1773)
traces_sample_rate=1.0,
)

with sentry_sdk.start_transaction(name="testing_huey_tasks", source=TRANSACTION_SOURCE_COMPONENT):
with sentry_sdk.start_transaction(name="testing_huey_tasks", source=TransactionSource.COMPONENT):
r = add_numbers(1, 2)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/split_tox_gh_actions/templates/test_group.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

- name: Upload coverage to Codecov
if: {% raw %}${{ !cancelled() }}{% endraw %}
uses: codecov/[email protected].1
uses: codecov/[email protected].2
with:
token: {% raw %}${{ secrets.CODECOV_TOKEN }}{% endraw %}
files: coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
LogLevelStr,
SamplingContext,
)
from sentry_sdk.tracing import Span, TransactionKwargs
from sentry_sdk.tracing import Span, TransactionKwargs, TransactionSource

T = TypeVar("T")
F = TypeVar("F", bound=Callable[..., Any])
Expand Down Expand Up @@ -424,7 +424,7 @@ def get_baggage():
def continue_trace(
environ_or_headers, op=None, name=None, source=None, origin="manual"
):
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], str) -> Transaction
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[TransactionSource], str) -> Transaction
"""
Sets the propagation context from environment or headers and returns a transaction.
"""
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def _prepare_event(

for key in "release", "environment", "server_name", "dist":
if event.get(key) is None and self.options[key] is not None:
event[key] = str(self.options[key]).strip() # type: ignore[literal-required]
event[key] = str(self.options[key]).strip()
if event.get("sdk") is None:
sdk_info = dict(SDK_INFO)
sdk_info["integrations"] = sorted(self.integrations.keys())
Expand Down Expand Up @@ -581,7 +581,7 @@ def _prepare_event(
self.transport.record_lost_event(
"before_send", data_category="error"
)
event = new_event # type: ignore
event = new_event

before_send_transaction = self.options["before_send_transaction"]
if (
Expand Down Expand Up @@ -611,7 +611,7 @@ def _prepare_event(
reason="before_send", data_category="span", quantity=spans_delta
)

event = new_event # type: ignore
event = new_event

return event

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
LogLevelStr,
SamplingContext,
)
from sentry_sdk.tracing import TransactionKwargs
from sentry_sdk.tracing import TransactionKwargs, TransactionSource

T = TypeVar("T")

Expand Down Expand Up @@ -473,7 +473,7 @@ def start_transaction(
)

def continue_trace(self, environ_or_headers, op=None, name=None, source=None):
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str]) -> Transaction
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[TransactionSource]) -> Transaction
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from sentry_sdk.tracing import (
BAGGAGE_HEADER_NAME,
SOURCE_FOR_STYLE,
TRANSACTION_SOURCE_ROUTE,
TransactionSource,
)
from sentry_sdk.tracing_utils import should_propagate_trace
from sentry_sdk.utils import (
Expand Down Expand Up @@ -133,7 +133,7 @@ async def sentry_app_handle(self, request, *args, **kwargs):
# If this transaction name makes it to the UI, AIOHTTP's
# URL resolver did not find a route or died trying.
name="generic AIOHTTP request",
source=TRANSACTION_SOURCE_ROUTE,
source=TransactionSource.ROUTE.value,
origin=AioHttpIntegration.origin,
)
with sentry_sdk.start_transaction(
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_TASK
from sentry_sdk.tracing import Transaction, TransactionSource
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down Expand Up @@ -104,7 +104,7 @@ async def _sentry_run_job(self, job_id, score):
name="unknown arq task",
status="ok",
op=OP.QUEUE_TASK_ARQ,
source=TRANSACTION_SOURCE_TASK,
source=TransactionSource.TASK.value,
origin=ArqIntegration.origin,
)

Expand Down
19 changes: 8 additions & 11 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
from sentry_sdk.sessions import track_session
from sentry_sdk.tracing import (
SOURCE_FOR_STYLE,
TRANSACTION_SOURCE_ROUTE,
TRANSACTION_SOURCE_URL,
TRANSACTION_SOURCE_COMPONENT,
TRANSACTION_SOURCE_CUSTOM,
TransactionSource,
)
from sentry_sdk.utils import (
ContextVar,
Expand Down Expand Up @@ -273,9 +270,9 @@ def event_processor(self, event, hint, asgi_scope):
already_set = event["transaction"] != _DEFAULT_TRANSACTION_NAME and event[
"transaction_info"
].get("source") in [
TRANSACTION_SOURCE_COMPONENT,
TRANSACTION_SOURCE_ROUTE,
TRANSACTION_SOURCE_CUSTOM,
TransactionSource.COMPONENT.value,
TransactionSource.ROUTE.value,
TransactionSource.CUSTOM.value,
]
if not already_set:
name, source = self._get_transaction_name_and_source(
Expand All @@ -299,7 +296,7 @@ def event_processor(self, event, hint, asgi_scope):
# for that.

def _get_transaction_name_and_source(self, transaction_style, asgi_scope):
# type: (SentryAsgiMiddleware, str, Any) -> Tuple[str, str]
# type: (SentryAsgiMiddleware, str, Any) -> Tuple[str, TransactionSource]
name = None
source = SOURCE_FOR_STYLE[transaction_style]
ty = asgi_scope.get("type")
Expand All @@ -313,7 +310,7 @@ def _get_transaction_name_and_source(self, transaction_style, asgi_scope):
name = transaction_from_function(endpoint) or ""
else:
name = _get_url(asgi_scope, "http" if ty == "http" else "ws", host=None)
source = TRANSACTION_SOURCE_URL
source = TransactionSource.URL.value

elif transaction_style == "url":
# FastAPI includes the route object in the scope to let Sentry extract the
Expand All @@ -325,11 +322,11 @@ def _get_transaction_name_and_source(self, transaction_style, asgi_scope):
name = path
else:
name = _get_url(asgi_scope, "http" if ty == "http" else "ws", host=None)
source = TRANSACTION_SOURCE_URL
source = TransactionSource.URL.value

if name is None:
name = _DEFAULT_TRANSACTION_NAME
source = TRANSACTION_SOURCE_ROUTE
source = TransactionSource.ROUTE.value
return name, source

return name, source
Loading

0 comments on commit 3082f96

Please sign in to comment.