Skip to content

Commit 1554f77

Browse files
authored
Merge branch 'potel-base' into antonpirker/potel/continuous_profiling
2 parents 8edf2ee + fc8fa9f commit 1554f77

34 files changed

+739
-424
lines changed

.github/workflows/test-integrations-aws.yml

Lines changed: 0 additions & 116 deletions
This file was deleted.

.github/workflows/test-integrations-web-2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
strategy:
3030
fail-fast: false
3131
matrix:
32-
python-version: ["3.8","3.9","3.11","3.12","3.13"]
32+
python-version: ["3.8","3.9","3.12","3.13"]
3333
os: [ubuntu-22.04]
3434
steps:
3535
- uses: actions/[email protected]

MIGRATION_GUIDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
134134
- Spans no longer have a `description`. Use `name` instead.
135135
- Dropped support for Python 3.6.
136136
- The `enable_tracing` `init` option has been removed. Configure `traces_sample_rate` directly.
137+
- The `propagate_traces` `init` option has been removed. Use `trace_propagation_targets` instead.
137138
- The `custom_sampling_context` parameter of `start_transaction` has been removed. Use `attributes` instead to set key-value pairs of data that should be accessible in the traces sampler. Note that span attributes need to conform to the [OpenTelemetry specification](https://opentelemetry.io/docs/concepts/signals/traces/#attributes), meaning only certain types can be set as values.
138139
- The PyMongo integration no longer sets tags. The data is still accessible via span attributes.
139140
- The PyMongo integration doesn't set `operation_ids` anymore. The individual IDs (`operation_id`, `request_id`, `session_id`) are now accessible as separate span attributes.
@@ -156,6 +157,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
156157
- `profiles_sample_rate` and `profiler_mode` were removed from options available via `_experiments`. Use the top-level `profiles_sample_rate` and `profiler_mode` options instead.
157158
- `Transport.capture_event` has been removed. Use `Transport.capture_envelope` instead.
158159
- Function transports are no longer supported. Subclass the `Transport` instead.
160+
- `start_transaction` (`start_span`) no longer takes a `baggage` argument. Use the `continue_trace()` context manager instead to propagate baggage.
159161

160162
### Deprecated
161163

scripts/populate_tox/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@
6969
"launchdarkly": {
7070
"package": "launchdarkly-server-sdk",
7171
},
72+
"litestar": {
73+
"package": "litestar",
74+
"deps": {
75+
"*": ["pytest-asyncio", "python-multipart", "requests", "cryptography"],
76+
"<2.7": ["httpx<0.28"],
77+
},
78+
},
7279
"loguru": {
7380
"package": "loguru",
7481
},
@@ -157,7 +164,7 @@
157164
"package": "trytond",
158165
"deps": {
159166
"*": ["werkzeug"],
160-
"<=5.0": ["werkzeug<1.0"],
167+
"<5.1": ["werkzeug<1.0"],
161168
},
162169
},
163170
"typer": {

scripts/populate_tox/populate_tox.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,26 @@
4949
# suites over to this script. Some entries will probably stay forever
5050
# as they don't fit the mold (e.g. common, asgi, which don't have a 3rd party
5151
# pypi package to install in different versions).
52+
#
53+
# Test suites that will have to remain hardcoded since they don't fit the
54+
# toxgen usecase
55+
"asgi",
56+
"aws_lambda",
57+
"cloud_resource_context",
5258
"common",
5359
"gevent",
5460
"opentelemetry",
5561
"potel",
62+
# Integrations that can be migrated -- we should eventually remove all
63+
# of these from the IGNORE list
5664
"aiohttp",
5765
"anthropic",
5866
"arq",
59-
"asgi",
6067
"asyncpg",
61-
"aws_lambda",
6268
"beam",
6369
"boto3",
6470
"chalice",
6571
"cohere",
66-
"cloud_resource_context",
67-
"cohere",
6872
"django",
6973
"fastapi",
7074
"gcp",
@@ -73,7 +77,6 @@
7377
"huggingface_hub",
7478
"langchain",
7579
"langchain_notiktoken",
76-
"litestar",
7780
"openai",
7881
"openai_notiktoken",
7982
"pure_eval",

scripts/populate_tox/tox.jinja

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ envlist =
115115
{py3.9,py3.11,py3.12}-langchain-latest
116116
{py3.9,py3.11,py3.12}-langchain-notiktoken
117117

118-
# Litestar
119-
{py3.8,py3.11}-litestar-v{2.0}
120-
{py3.8,py3.11,py3.12}-litestar-v{2.6}
121-
{py3.8,py3.11,py3.12}-litestar-v{2.12}
122-
{py3.8,py3.11,py3.12}-litestar-latest
123-
124118
# OpenAI
125119
{py3.9,py3.11,py3.12}-openai-v1.0
126120
{py3.9,py3.11,py3.12}-openai-v1.22
@@ -346,17 +340,6 @@ deps =
346340
langchain-{latest,notiktoken}: openai>=1.6.1
347341
langchain-latest: tiktoken~=0.6.0
348342
349-
# Litestar
350-
litestar: pytest-asyncio
351-
litestar: python-multipart
352-
litestar: requests
353-
litestar: cryptography
354-
litestar-v{2.0,2.6}: httpx<0.28
355-
litestar-v2.0: litestar~=2.0.0
356-
litestar-v2.6: litestar~=2.6.0
357-
litestar-v2.12: litestar~=2.12.0
358-
litestar-latest: litestar
359-
360343
# OpenAI
361344
openai: pytest-asyncio
362345
openai-v1.0: openai~=1.0.0

sentry_sdk/_experimental_logger.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: this is the logger sentry exposes to users, not some generic logger.
22
import functools
3+
import time
34
from typing import Any
45

56
from sentry_sdk import get_client, get_current_scope
@@ -9,7 +10,27 @@ def _capture_log(severity_text, severity_number, template, **kwargs):
910
# type: (str, int, str, **Any) -> None
1011
client = get_client()
1112
scope = get_current_scope()
12-
client.capture_log(scope, severity_text, severity_number, template, **kwargs)
13+
14+
attrs = {
15+
"sentry.message.template": template,
16+
} # type: dict[str, str | bool | float | int]
17+
if "attributes" in kwargs:
18+
attrs.update(kwargs.pop("attributes"))
19+
for k, v in kwargs.items():
20+
attrs[f"sentry.message.parameters.{k}"] = v
21+
22+
# noinspection PyProtectedMember
23+
client._capture_experimental_log(
24+
scope,
25+
{
26+
"severity_text": severity_text,
27+
"severity_number": severity_number,
28+
"attributes": attrs,
29+
"body": template.format(**kwargs),
30+
"time_unix_nano": time.time_ns(),
31+
"trace_id": None,
32+
},
33+
)
1334

1435

1536
trace = functools.partial(_capture_log, "trace", 1)

sentry_sdk/client.py

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import time
43
import uuid
54
import random
65
import socket
@@ -184,8 +183,8 @@ def capture_event(self, *args, **kwargs):
184183
# type: (*Any, **Any) -> Optional[str]
185184
return None
186185

187-
def capture_log(self, scope, severity_text, severity_number, template, **kwargs):
188-
# type: (Scope, str, int, str, **Any) -> None
186+
def _capture_experimental_log(self, scope, log):
187+
# type: (Scope, Log) -> None
189188
pass
190189

191190
def capture_session(self, *args, **kwargs):
@@ -805,47 +804,36 @@ def capture_event(
805804

806805
return return_value
807806

808-
def capture_log(self, scope, severity_text, severity_number, template, **kwargs):
809-
# type: (Scope, str, int, str, **Any) -> None
807+
def _capture_experimental_log(self, current_scope, log):
808+
# type: (Scope, Log) -> None
810809
logs_enabled = self.options["_experiments"].get("enable_sentry_logs", False)
811810
if not logs_enabled:
812811
return
812+
isolation_scope = current_scope.get_isolation_scope()
813813

814814
headers = {
815815
"sent_at": format_timestamp(datetime.now(timezone.utc)),
816816
} # type: dict[str, object]
817817

818-
attrs = {
819-
"sentry.message.template": template,
820-
} # type: dict[str, str | bool | float | int]
821-
822-
kwargs_attributes = kwargs.get("attributes")
823-
if kwargs_attributes is not None:
824-
attrs.update(kwargs_attributes)
825-
826818
environment = self.options.get("environment")
827-
if environment is not None:
828-
attrs["sentry.environment"] = environment
819+
if environment is not None and "sentry.environment" not in log["attributes"]:
820+
log["attributes"]["sentry.environment"] = environment
829821

830822
release = self.options.get("release")
831-
if release is not None:
832-
attrs["sentry.release"] = release
823+
if release is not None and "sentry.release" not in log["attributes"]:
824+
log["attributes"]["sentry.release"] = release
833825

834-
span = scope.span
835-
if span is not None:
836-
attrs["sentry.trace.parent_span_id"] = span.span_id
826+
span = current_scope.span
827+
if span is not None and "sentry.trace.parent_span_id" not in log["attributes"]:
828+
log["attributes"]["sentry.trace.parent_span_id"] = span.span_id
837829

838-
for k, v in kwargs.items():
839-
attrs[f"sentry.message.parameters.{k}"] = v
840-
841-
log = {
842-
"severity_text": severity_text,
843-
"severity_number": severity_number,
844-
"body": template.format(**kwargs),
845-
"attributes": attrs,
846-
"time_unix_nano": time.time_ns(),
847-
"trace_id": None,
848-
} # type: Log
830+
if log.get("trace_id") is None:
831+
transaction = current_scope.transaction
832+
propagation_context = isolation_scope.get_active_propagation_context()
833+
if transaction is not None:
834+
log["trace_id"] = transaction.trace_id
835+
elif propagation_context is not None:
836+
log["trace_id"] = propagation_context.trace_id
849837

850838
# If debug is enabled, log the log to the console
851839
debug = self.options.get("debug", False)
@@ -859,15 +847,10 @@ def capture_log(self, scope, severity_text, severity_number, template, **kwargs)
859847
"fatal": logging.CRITICAL,
860848
}
861849
logger.log(
862-
severity_text_to_logging_level.get(severity_text, logging.DEBUG),
850+
severity_text_to_logging_level.get(log["severity_text"], logging.DEBUG),
863851
f'[Sentry Logs] {log["body"]}',
864852
)
865853

866-
propagation_context = scope.get_active_propagation_context()
867-
if propagation_context is not None:
868-
headers["trace_id"] = propagation_context.trace_id
869-
log["trace_id"] = propagation_context.trace_id
870-
871854
envelope = Envelope(headers=headers)
872855

873856
before_emit_log = self.options["_experiments"].get("before_emit_log")

sentry_sdk/consts.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class CompressionAlgo(Enum):
7070
"transport_compression_algo": Optional[CompressionAlgo],
7171
"transport_num_pools": Optional[int],
7272
"transport_http2": Optional[bool],
73+
"enable_sentry_logs": Optional[bool],
7374
},
7475
total=False,
7576
)
@@ -510,7 +511,6 @@ def __init__(
510511
debug=None, # type: Optional[bool]
511512
attach_stacktrace=False, # type: bool
512513
ca_certs=None, # type: Optional[str]
513-
propagate_traces=True, # type: bool
514514
traces_sample_rate=None, # type: Optional[float]
515515
traces_sampler=None, # type: Optional[TracesSampler]
516516
profiles_sample_rate=None, # type: Optional[float]
@@ -914,8 +914,6 @@ def __init__(
914914
915915
:param profile_session_sample_rate:
916916
917-
:param propagate_traces:
918-
919917
:param auto_session_tracking:
920918
921919
:param spotlight:

0 commit comments

Comments
 (0)