Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions fastapi_jsonrpc/contrib/sentry/jrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down Expand Up @@ -360,6 +360,7 @@ def probe(
'type': 'string',
},
'params': {
'additionalProperties': True,
'title': 'Params',
'type': 'object',
},
Expand Down Expand Up @@ -427,6 +428,7 @@ def probe(
'type': 'string',
},
'result': {
'additionalProperties': True,
'title': 'Result',
'type': 'object',
},
Expand Down
3 changes: 2 additions & 1 deletion tests/test_openapi_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down Expand Up @@ -502,6 +502,7 @@ def test_basic(app_client, openapi_compatible):
'type': 'string',
},
'result': {
'additionalProperties': True,
'title': 'Result',
'type': 'object',
},
Expand Down
4 changes: 3 additions & 1 deletion tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down Expand Up @@ -371,6 +371,7 @@ def test_openapi(app_client, openapi_compatible):
'type': 'string',
},
'params': {
'additionalProperties': True,
'title': 'Params',
'type': 'object',
},
Expand Down Expand Up @@ -438,6 +439,7 @@ def test_openapi(app_client, openapi_compatible):
'type': 'string',
},
'result': {
'additionalProperties': True,
'title': 'Result',
'type': 'object',
},
Expand Down
4 changes: 3 additions & 1 deletion tests/test_shared_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down Expand Up @@ -418,6 +418,7 @@ def test_openapi(app_client, openapi_compatible):
'type': 'string',
},
'params': {
'additionalProperties': True,
'title': 'Params',
'type': 'object',
},
Expand Down Expand Up @@ -521,6 +522,7 @@ def test_openapi(app_client, openapi_compatible):
'type': 'string',
},
'result': {
'additionalProperties': True,
'title': 'Result',
'type': 'object',
},
Expand Down