Skip to content

Commit 0c1e09c

Browse files
authored
fix: sentry-sdk ^2.23 support (#81)
1 parent 7672b10 commit 0c1e09c

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

fastapi_jsonrpc/contrib/sentry/jrpc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
_DEFAULT_TRANSACTION_NAME = "generic JRPC request"
1818
TransactionNameGenerator = Callable[[JsonRpcContext], str]
1919

20+
if hasattr(sentry_sdk.tracing, 'TransactionSource'):
21+
# sentry_sdk ^2.23
22+
TRANSACTION_SOURCE_CUSTOM = sentry_sdk.tracing.TransactionSource.CUSTOM
23+
else:
24+
# sentry_sdk ^2.0
25+
TRANSACTION_SOURCE_CUSTOM = sentry_sdk.tracing.TRANSACTION_SOURCE_CUSTOM
26+
2027

2128
@asynccontextmanager
2229
async def jrpc_transaction_middleware(ctx: JsonRpcContext):
@@ -30,7 +37,7 @@ async def jrpc_transaction_middleware(ctx: JsonRpcContext):
3037
# this name is replaced by event processor
3138
name=_DEFAULT_TRANSACTION_NAME,
3239
op=OP.HTTP_SERVER,
33-
source=sentry_sdk.tracing.TRANSACTION_SOURCE_CUSTOM,
40+
source=TRANSACTION_SOURCE_CUSTOM,
3441
origin="manual",
3542
)
3643
with sentry_sdk.isolation_scope() as jrpc_request_scope:
@@ -98,7 +105,7 @@ def _set_initial_sampling_decision(self, sampling_context):
98105

99106
def make_transaction_info_event_processor(ctx: JsonRpcContext, name_generator: TransactionNameGenerator) -> Callable:
100107
def _event_processor(event, _):
101-
event["transaction_info"]["source"] = sentry_sdk.tracing.TRANSACTION_SOURCE_CUSTOM
108+
event["transaction_info"]["source"] = TRANSACTION_SOURCE_CUSTOM
102109
if ctx.method_route is not None:
103110
event["transaction"] = name_generator(ctx)
104111

tests/test_openapi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def probe(
126126
'properties': {
127127
'ctx': {
128128
'title': 'Ctx',
129-
'anyOf': [{'type': 'object'}, {'type': 'null'}],
129+
'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}],
130130
},
131131
'loc': {
132132
'items': {'anyOf': [
@@ -360,6 +360,7 @@ def probe(
360360
'type': 'string',
361361
},
362362
'params': {
363+
'additionalProperties': True,
363364
'title': 'Params',
364365
'type': 'object',
365366
},
@@ -427,6 +428,7 @@ def probe(
427428
'type': 'string',
428429
},
429430
'result': {
431+
'additionalProperties': True,
430432
'title': 'Result',
431433
'type': 'object',
432434
},

tests/test_openapi_dependencies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_basic(app_client, openapi_compatible):
158158
'properties': {
159159
'ctx': {
160160
'title': 'Ctx',
161-
'anyOf': [{'type': 'object'}, {'type': 'null'}],
161+
'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}],
162162
},
163163
'loc': {
164164
'items': {'anyOf': [
@@ -502,6 +502,7 @@ def test_basic(app_client, openapi_compatible):
502502
'type': 'string',
503503
},
504504
'result': {
505+
'additionalProperties': True,
505506
'title': 'Result',
506507
'type': 'object',
507508
},

tests/test_params.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_openapi(app_client, openapi_compatible):
157157
'properties': {
158158
'ctx': {
159159
'title': 'Ctx',
160-
'anyOf': [{'type': 'object'}, {'type': 'null'}],
160+
'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}],
161161
},
162162
'loc': {
163163
'items': {'anyOf': [
@@ -371,6 +371,7 @@ def test_openapi(app_client, openapi_compatible):
371371
'type': 'string',
372372
},
373373
'params': {
374+
'additionalProperties': True,
374375
'title': 'Params',
375376
'type': 'object',
376377
},
@@ -438,6 +439,7 @@ def test_openapi(app_client, openapi_compatible):
438439
'type': 'string',
439440
},
440441
'result': {
442+
'additionalProperties': True,
441443
'title': 'Result',
442444
'type': 'object',
443445
},

tests/test_shared_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_openapi(app_client, openapi_compatible):
181181
'properties': {
182182
'ctx': {
183183
'title': 'Ctx',
184-
'anyOf': [{'type': 'object'}, {'type': 'null'}],
184+
'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}],
185185
},
186186
'loc': {
187187
'items': {'anyOf': [
@@ -418,6 +418,7 @@ def test_openapi(app_client, openapi_compatible):
418418
'type': 'string',
419419
},
420420
'params': {
421+
'additionalProperties': True,
421422
'title': 'Params',
422423
'type': 'object',
423424
},
@@ -521,6 +522,7 @@ def test_openapi(app_client, openapi_compatible):
521522
'type': 'string',
522523
},
523524
'result': {
525+
'additionalProperties': True,
524526
'title': 'Result',
525527
'type': 'object',
526528
},

0 commit comments

Comments
 (0)