Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit 734c100

Browse files
committed
move to @sentry/types default lib
1 parent 92016e4 commit 734c100

File tree

5 files changed

+68
-73
lines changed

5 files changed

+68
-73
lines changed

playground-ts/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import ReactDOM from 'react-dom'
33
import './index.css'
44
import App from './App'
55
import reportWebVitals from './reportWebVitals'
6-
import { SentryProvider, SentryConfigType } from './component-lib'
6+
import { SentryProvider } from './component-lib'
77

8-
const sentryConfig: SentryConfigType = {
8+
const sentryConfig = {
99
dsn: process.env.REACT_APP_SENTRY_DSN ?? '',
1010
debug: true,
1111
environment: 'development',

src/SentryProvider.tsx

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { createContext, useContext, useLayoutEffect, useState } from 'react'
2-
import { noop } from './helpers'
3-
import type {
4-
SentryType,
5-
Level,
6-
SentryConfigType,
7-
TracingOptions
8-
} from './types'
2+
import type { EventHint, Scope, Options } from '@sentry/types'
3+
import { SentryType, TracingOptions, SeverityLevels } from './types'
94

105
declare global {
116
interface Window {
@@ -17,22 +12,28 @@ declare global {
1712
}
1813

1914
const SentryContext = createContext<SentryType>({
20-
onLoad: noop,
21-
init: noop,
22-
captureMessage: noop,
23-
captureException: noop,
24-
configureScope: noop,
25-
Severity: {},
26-
withScope: noop,
15+
captureMessage: window?.Sentry?.captureMessage,
16+
captureException: window?.Sentry?.captureException,
17+
configureScope: window?.Sentry?.configureScope,
18+
Severity: {
19+
Critical: 'critical',
20+
Debug: 'debug',
21+
Error: 'error',
22+
Fatal: 'fatal',
23+
Info: 'info',
24+
Log: 'log',
25+
Warning: 'warning'
26+
},
27+
withScope: window?.Sentry?.withScope,
2728
Integrations: {},
28-
setContext: noop,
29+
setContext: window?.Sentry?.setContext,
2930
Scope: undefined
3031
})
3132

3233
interface ContextProps {
3334
children: JSX.Element
3435
url: string
35-
config: SentryConfigType
36+
config: Options
3637
integrity?: string
3738
performance?: boolean
3839
tracingOptions?: TracingOptions
@@ -48,12 +49,15 @@ export function SentryProvider({
4849
tracingOptions
4950
}: ContextProps): JSX.Element {
5051
const [Sentry, setSentry] = useState<SentryType>({
51-
onLoad: (callback) => window?.Sentry?.onLoad(callback),
52-
init: (options) => window?.Sentry?.init(options),
53-
captureMessage: (msg, lv?: Level) =>
54-
window?.Sentry?.captureMessage(msg, lv ?? 'warning'),
55-
captureException: (err, lv?: Level) =>
56-
window?.Sentry?.captureException(err, lv ?? 'warning'),
52+
captureMessage: (
53+
message: string,
54+
level?: SeverityLevels,
55+
hint?: EventHint,
56+
scope?: Scope
57+
) => window?.Sentry?.captureMessage(message, level, hint, scope),
58+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59+
captureException: (exception: any, hint?: EventHint, scope?: Scope) =>
60+
window?.Sentry?.captureException(exception, hint, scope),
5761
configureScope: (callback) => window?.Sentry?.configureScope(callback),
5862
withScope: (callback) => window?.Sentry?.withScope(callback),
5963
Severity: {
@@ -105,7 +109,10 @@ export function SentryProvider({
105109
}
106110
}
107111
done = true
108-
Sentry.onLoad(() => Sentry.init(config))
112+
if (window?.Sentry?.onLoad)
113+
window.Sentry.onLoad(
114+
() => window?.Sentry?.init && window.Sentry.init(config)
115+
)
109116
if (window.Sentry.Scope) {
110117
setSentry({
111118
...Sentry,

src/helpers.ts

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

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import { SentryProvider, useSentry } from './SentryProvider'
2-
import type { SentryConfigType } from './types'
32

4-
export { SentryProvider, useSentry, SentryConfigType }
3+
export { SentryProvider, useSentry }

src/types.ts

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import type { Scope } from '@sentry/types'
2-
// TODO: check all "any" types
3-
export type Level =
1+
import type {
2+
Scope,
3+
EventHint,
4+
Options,
5+
TransactionContext,
6+
Transaction
7+
} from '@sentry/types'
8+
9+
export type SeverityLevels =
410
| 'debug'
511
| 'info'
612
| 'warning'
@@ -11,57 +17,43 @@ export type Level =
1117

1218
export interface TracingOptions {
1319
tracingOrigins?: string[]
14-
// TODO: Check the exact types beforeNavigate()
15-
beforeNavigate?: () => void
20+
beforeNavigate?: (
21+
context: TransactionContext
22+
) => TransactionContext | undefined
23+
_metricOptions?: Partial<{ _reportAllChanges: boolean }>
1624
shouldCreateSpanForRequest?: () => void
1725
idleTimeout?: number
1826
startTransactionOnLocationChange?: boolean
1927
startTransactionOnPageLoad?: boolean
20-
maxTransactionDuration?: boolean
28+
maxTransactionDuration?: number
2129
markBackgroundTransactions?: boolean
22-
}
23-
24-
interface ScopeObject extends Scope {
25-
prototype: any
30+
routingInstrumentation<T extends Transaction>(
31+
customStartTransaction: (context: TransactionContext) => T | undefined,
32+
startTransactionOnPageLoad?: boolean,
33+
startTransactionOnLocationChange?: boolean
34+
): void
2635
}
2736

2837
export interface SentryType {
29-
onLoad: (callback: () => void) => void
30-
init: (options: SentryConfigType) => void
31-
captureMessage: (msg: string, lv?: any) => void
32-
// TODO: Set the correct parameters for captureException
33-
captureException: (err: any, lv?: any) => void
38+
onLoad?: (callback: () => void) => void
39+
init?: (options: Options) => void
40+
captureMessage: (
41+
message: string,
42+
level?: SeverityLevels,
43+
hint?: EventHint,
44+
scope?: Scope
45+
) => string | undefined
46+
captureException: (
47+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
48+
exception: any,
49+
hint?: EventHint,
50+
scope?: Scope
51+
) => string | undefined
3452
configureScope: (callback: () => void) => void
35-
Severity: { [key: string]: Level }
53+
Severity: { [key: string]: SeverityLevels }
3654
withScope: (callback: () => void) => void
3755
Integrations: any
3856
// TODO: set the correct classes available
3957
setContext: (str: string, obj: { [k: string]: any }) => void
40-
Scope: ScopeObject | undefined
41-
}
42-
43-
export interface SentryConfigType {
44-
dsn: string
45-
debug: boolean
46-
release: string
47-
environment: string
48-
tunnel?: string
49-
sampleRate?: number
50-
maxBreadcrumbs?: number
51-
attachStacktrace?: string
52-
denyUrls?: string[]
53-
allowUrls?: string[]
54-
autoSessionTracking?: boolean
55-
initialScope?: { [key: string]: any }
56-
maxValueLength?: number
57-
normalizeDepth?: number
58-
// TODO: Integration configurations - https://docs.sentry.io/platforms/javascript/configuration/options/#integration-configuration
59-
integrations?: any
60-
defaultIntegrations?: boolean
61-
62-
// TODO: Hooks - https://docs.sentry.io/platforms/javascript/configuration/options/#hooks
63-
64-
// TODO: transport - https://docs.sentry.io/platforms/javascript/configuration/options/#transport-options
65-
tracesSampleRate?: number
66-
tracesSampler?: () => void
58+
Scope?: Scope & { prototype: any } & EventHint
6759
}

0 commit comments

Comments
 (0)