Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
cd92e4cf
Unverified
Commit
cd92e4cf
authored
Mar 20, 2023
by
Tina
Committed by
GitHub
Mar 20, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Revert "feat: trace jsonrpc (#6159)" (#6190)
Revert "feat: trace jsonrpc (#6159)" This reverts commit
6fee37c4
.
parent
089fba5d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
81 deletions
+9
-81
index.ts
src/tracing/index.ts
+0
-1
jsonrpc.ts
src/tracing/jsonrpc.ts
+0
-26
trace.test.ts
src/tracing/trace.test.ts
+9
-40
trace.ts
src/tracing/trace.ts
+0
-14
No files found.
src/tracing/index.ts
View file @
cd92e4cf
import
'
components/analytics
'
import
'
components/analytics
'
import
'
./jsonrpc
'
import
*
as
Sentry
from
'
@sentry/react
'
import
*
as
Sentry
from
'
@sentry/react
'
import
{
BrowserTracing
}
from
'
@sentry/tracing
'
import
{
BrowserTracing
}
from
'
@sentry/tracing
'
...
...
src/tracing/jsonrpc.ts
deleted
100644 → 0
View file @
089fba5d
/**
* Traces all JsonRpc requests as spans, reporting them if there is an active transaction.
* This is analagous to import("@sentry/tracing").BrowserTracingOptions.shouldCreateSpanForRequest.
*
* This is able to collect all requests because there is only one copy of @ethersproject/providers, and web3-react wraps
* any external (EIP-1193) provider in that prototype - overriding the prototype will override send for all instances.
*/
import
{
JsonRpcProvider
}
from
'
@ethersproject/providers
'
import
{
maybeTrace
}
from
'
./trace
'
const
jsonRpcProviderSend
=
JsonRpcProvider
.
prototype
.
send
JsonRpcProvider
.
prototype
.
send
=
async
function
LoggingAwareSend
(
this
,
method
,
params
)
{
maybeTrace
(
'
json_rpc
'
,
async
({
setTraceData
})
=>
{
setTraceData
(
'
method
'
,
method
)
if
(
method
===
'
eth_call
'
)
{
// Trim the calldata to the method hash (10 chars) to avoid recording large payloads and sensitive information.
const
methodHash
=
(
params
[
0
].
data
as
string
).
substring
(
0
,
10
)
// Override the calldata with the method hash, which is part of the first param.
setTraceData
(
'
params
'
,
{
...
params
,
[
0
]:
{
...
params
[
0
],
data
:
methodHash
}
})
}
else
{
setTraceData
(
'
params
'
,
params
)
}
return
jsonRpcProviderSend
.
call
(
this
,
method
,
params
)
})
}
src/tracing/trace.test.ts
View file @
cd92e4cf
import
'
@sentry/tracing
'
// required to populate Sentry.startTransaction, which is not included in the core module
import
'
@sentry/tracing
'
// required to populate Sentry.startTransaction, which is not included in the core module
import
*
as
Sentry
from
'
@sentry/react
'
import
*
as
Sentry
from
'
@sentry/react
'
import
{
Hub
}
from
'
@sentry/react
'
import
{
Transaction
}
from
'
@sentry/tracing
'
import
{
Transaction
}
from
'
@sentry/tracing
'
import
assert
from
'
assert
'
import
assert
from
'
assert
'
import
{
maybeTrace
,
trace
}
from
'
./trace
'
import
{
trace
}
from
'
./trace
'
jest
.
mock
(
'
@sentry/react
'
,
()
=>
{
jest
.
mock
(
'
@sentry/react
'
,
()
=>
{
return
{
return
{
getCurrentHub
:
jest
.
fn
(),
startTransaction
:
jest
.
fn
(),
startTransaction
:
jest
.
fn
(),
}
}
})
})
...
@@ -23,16 +21,16 @@ function getTransaction(index = 0): Transaction {
...
@@ -23,16 +21,16 @@ function getTransaction(index = 0): Transaction {
return
transaction
return
transaction
}
}
beforeEach
(()
=>
{
describe
(
'
trace
'
,
()
=>
{
const
Sentry
=
jest
.
requireActual
(
'
@sentry/react
'
)
beforeEach
(()
=>
{
startTransaction
.
mockReset
().
mockImplementation
((
context
)
=>
{
const
Sentry
=
jest
.
requireActual
(
'
@sentry/react
'
)
const
transaction
:
Transaction
=
Sentry
.
startTransaction
(
context
)
startTransaction
.
mockReset
().
mockImplementation
((
context
)
=>
{
transaction
.
initSpanRecorder
()
const
transaction
:
Transaction
=
Sentry
.
startTransaction
(
context
)
return
transaction
transaction
.
initSpanRecorder
()
return
transaction
})
})
})
})
describe
(
'
trace
'
,
()
=>
{
it
(
'
propagates callback
'
,
async
()
=>
{
it
(
'
propagates callback
'
,
async
()
=>
{
await
expect
(
trace
(
'
test
'
,
()
=>
Promise
.
resolve
(
'
resolved
'
))).
resolves
.
toBe
(
'
resolved
'
)
await
expect
(
trace
(
'
test
'
,
()
=>
Promise
.
resolve
(
'
resolved
'
))).
resolves
.
toBe
(
'
resolved
'
)
await
expect
(
trace
(
'
test
'
,
()
=>
Promise
.
reject
(
'
rejected
'
))).
rejects
.
toBe
(
'
rejected
'
)
await
expect
(
trace
(
'
test
'
,
()
=>
Promise
.
reject
(
'
rejected
'
))).
rejects
.
toBe
(
'
rejected
'
)
...
@@ -144,32 +142,3 @@ describe('trace', () => {
...
@@ -144,32 +142,3 @@ describe('trace', () => {
})
})
})
})
})
})
describe
(
'
maybeTrace
'
,
()
=>
{
const
getScope
=
jest
.
fn
()
beforeEach
(()
=>
{
getScope
.
mockReset
()
const
hub
=
{
getScope
}
as
unknown
as
Hub
jest
.
spyOn
(
Sentry
,
'
getCurrentHub
'
).
mockReturnValue
(
hub
)
})
it
(
'
propagates callback
'
,
async
()
=>
{
await
expect
(
maybeTrace
(
'
test
'
,
()
=>
Promise
.
resolve
(
'
resolved
'
))).
resolves
.
toBe
(
'
resolved
'
)
await
expect
(
maybeTrace
(
'
test
'
,
()
=>
Promise
.
reject
(
'
rejected
'
))).
rejects
.
toBe
(
'
rejected
'
)
})
it
(
'
creates a span under the active transaction
'
,
async
()
=>
{
getScope
.
mockReturnValue
({
getTransaction
})
await
trace
(
'
test
'
,
()
=>
{
maybeTrace
(
'
child
'
,
()
=>
Promise
.
resolve
(),
{
data
:
{
e
:
'
e
'
},
tags
:
{
is_widget
:
true
}
})
return
Promise
.
resolve
()
})
const
transaction
=
getTransaction
()
const
span
=
transaction
.
spanRecorder
?.
spans
[
1
]
assert
(
span
)
expect
(
span
.
op
).
toBe
(
'
child
'
)
expect
(
span
.
data
).
toEqual
({
e
:
'
e
'
})
expect
(
span
.
tags
).
toEqual
({
is_widget
:
true
})
})
})
src/tracing/trace.ts
View file @
cd92e4cf
...
@@ -87,17 +87,3 @@ export async function trace<T>(name: string, callback: TraceCallback<T>, metadat
...
@@ -87,17 +87,3 @@ export async function trace<T>(name: string, callback: TraceCallback<T>, metadat
const
transaction
=
Sentry
.
startTransaction
({
name
,
data
:
metadata
?.
data
,
tags
:
metadata
?.
tags
})
const
transaction
=
Sentry
.
startTransaction
({
name
,
data
:
metadata
?.
data
,
tags
:
metadata
?.
tags
})
return
traceSpan
(
transaction
)(
callback
)
return
traceSpan
(
transaction
)(
callback
)
}
}
/**
* Traces the callback as part of an already active trace if an active trace exists.
* @param name - The name of your trace.
* @param callback - The callback to trace. The trace will run for the duration of the callback.
* @param metadata - Any data or tags to include in the trace.
*/
export
async
function
maybeTrace
<
T
>
(
name
:
string
,
callback
:
TraceCallback
<
T
>
,
metadata
?:
TraceMetadata
):
Promise
<
T
>
{
const
span
=
Sentry
.
getCurrentHub
()
.
getScope
()
?.
getTransaction
()
?.
startChild
({
op
:
name
,
data
:
metadata
?.
data
,
tags
:
metadata
?.
tags
})
return
traceSpan
(
span
)(
callback
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment