diff --git a/fastapi_jsonrpc/contrib/sentry/jrpc.py b/fastapi_jsonrpc/contrib/sentry/jrpc.py index 8b1c5ad..7699aad 100644 --- a/fastapi_jsonrpc/contrib/sentry/jrpc.py +++ b/fastapi_jsonrpc/contrib/sentry/jrpc.py @@ -17,6 +17,13 @@ _DEFAULT_TRANSACTION_NAME = "generic JRPC request" TransactionNameGenerator = Callable[[JsonRpcContext], str] +if hasattr(sentry_sdk.tracing, 'TransactionSource'): + # sentry_sdk ^2.23 + TRANSACTION_SOURCE_CUSTOM = sentry_sdk.tracing.TransactionSource.CUSTOM +else: + # sentry_sdk ^2.0 + TRANSACTION_SOURCE_CUSTOM = sentry_sdk.tracing.TRANSACTION_SOURCE_CUSTOM + @asynccontextmanager async def jrpc_transaction_middleware(ctx: JsonRpcContext): @@ -30,7 +37,7 @@ async def jrpc_transaction_middleware(ctx: JsonRpcContext): # this name is replaced by event processor name=_DEFAULT_TRANSACTION_NAME, op=OP.HTTP_SERVER, - source=sentry_sdk.tracing.TRANSACTION_SOURCE_CUSTOM, + source=TRANSACTION_SOURCE_CUSTOM, origin="manual", ) with sentry_sdk.isolation_scope() as jrpc_request_scope: @@ -98,7 +105,7 @@ def _set_initial_sampling_decision(self, sampling_context): def make_transaction_info_event_processor(ctx: JsonRpcContext, name_generator: TransactionNameGenerator) -> Callable: def _event_processor(event, _): - event["transaction_info"]["source"] = sentry_sdk.tracing.TRANSACTION_SOURCE_CUSTOM + event["transaction_info"]["source"] = TRANSACTION_SOURCE_CUSTOM if ctx.method_route is not None: event["transaction"] = name_generator(ctx) diff --git a/tests/test_openapi.py b/tests/test_openapi.py index 40ca5ed..dd4e73e 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -126,7 +126,7 @@ def probe( 'properties': { 'ctx': { 'title': 'Ctx', - 'anyOf': [{'type': 'object'}, {'type': 'null'}], + 'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}], }, 'loc': { 'items': {'anyOf': [ @@ -360,6 +360,7 @@ def probe( 'type': 'string', }, 'params': { + 'additionalProperties': True, 'title': 'Params', 'type': 'object', }, @@ -427,6 +428,7 @@ def probe( 'type': 'string', }, 'result': { + 'additionalProperties': True, 'title': 'Result', 'type': 'object', }, diff --git a/tests/test_openapi_dependencies.py b/tests/test_openapi_dependencies.py index 4f81238..d825a51 100644 --- a/tests/test_openapi_dependencies.py +++ b/tests/test_openapi_dependencies.py @@ -158,7 +158,7 @@ def test_basic(app_client, openapi_compatible): 'properties': { 'ctx': { 'title': 'Ctx', - 'anyOf': [{'type': 'object'}, {'type': 'null'}], + 'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}], }, 'loc': { 'items': {'anyOf': [ @@ -502,6 +502,7 @@ def test_basic(app_client, openapi_compatible): 'type': 'string', }, 'result': { + 'additionalProperties': True, 'title': 'Result', 'type': 'object', }, diff --git a/tests/test_params.py b/tests/test_params.py index 52a9083..9667b0f 100644 --- a/tests/test_params.py +++ b/tests/test_params.py @@ -157,7 +157,7 @@ def test_openapi(app_client, openapi_compatible): 'properties': { 'ctx': { 'title': 'Ctx', - 'anyOf': [{'type': 'object'}, {'type': 'null'}], + 'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}], }, 'loc': { 'items': {'anyOf': [ @@ -371,6 +371,7 @@ def test_openapi(app_client, openapi_compatible): 'type': 'string', }, 'params': { + 'additionalProperties': True, 'title': 'Params', 'type': 'object', }, @@ -438,6 +439,7 @@ def test_openapi(app_client, openapi_compatible): 'type': 'string', }, 'result': { + 'additionalProperties': True, 'title': 'Result', 'type': 'object', }, diff --git a/tests/test_shared_model.py b/tests/test_shared_model.py index 2753db5..596130e 100644 --- a/tests/test_shared_model.py +++ b/tests/test_shared_model.py @@ -181,7 +181,7 @@ def test_openapi(app_client, openapi_compatible): 'properties': { 'ctx': { 'title': 'Ctx', - 'anyOf': [{'type': 'object'}, {'type': 'null'}], + 'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}], }, 'loc': { 'items': {'anyOf': [ @@ -418,6 +418,7 @@ def test_openapi(app_client, openapi_compatible): 'type': 'string', }, 'params': { + 'additionalProperties': True, 'title': 'Params', 'type': 'object', }, @@ -521,6 +522,7 @@ def test_openapi(app_client, openapi_compatible): 'type': 'string', }, 'result': { + 'additionalProperties': True, 'title': 'Result', 'type': 'object', },