-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into DominikB2014/add-view-to-analytic-event-name
- Loading branch information
Showing
13 changed files
with
428 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {EventFixture} from 'sentry-fixture/event'; | ||
|
||
import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import ContextCard from 'sentry/components/events/contexts/contextCard'; | ||
import { | ||
type CultureContext, | ||
getCultureContextData, | ||
} from 'sentry/components/events/contexts/culture'; | ||
|
||
const MOCK_CULTURE_CONTEXT: CultureContext = { | ||
calendar: 'GregorianCalendar', | ||
display_name: 'English (United States)', | ||
locale: 'en-US', | ||
is_24_hour_format: true, | ||
timezone: 'Europe/Vienna', | ||
// Extra data is still valid and preserved | ||
extra_data: 'something', | ||
unknown_key: 123, | ||
}; | ||
|
||
const MOCK_REDACTION = { | ||
['timezone']: { | ||
'': { | ||
chunks: [ | ||
{ | ||
remark: 'x', | ||
rule_id: 'project:0', | ||
text: '', | ||
type: 'redaction', | ||
}, | ||
], | ||
len: 13, | ||
rem: [['project:0', 'x', 0, 0]], | ||
}, | ||
}, | ||
}; | ||
|
||
describe('CultureContext', function () { | ||
it('returns formatted data correctly', function () { | ||
expect(getCultureContextData({data: MOCK_CULTURE_CONTEXT})).toEqual([ | ||
{key: 'calendar', subject: 'Calendar', value: 'GregorianCalendar'}, | ||
{ | ||
key: 'display_name', | ||
subject: 'Display Name', | ||
value: 'English (United States)', | ||
}, | ||
{key: 'locale', subject: 'Locale', value: 'en-US'}, | ||
{key: 'is_24_hour_format', subject: 'Uses 24h Format', value: true}, | ||
{key: 'timezone', subject: 'Timezone', value: 'Europe/Vienna'}, | ||
{ | ||
key: 'extra_data', | ||
subject: 'extra_data', | ||
value: 'something', | ||
}, | ||
{ | ||
key: 'unknown_key', | ||
subject: 'unknown_key', | ||
value: 123, | ||
}, | ||
]); | ||
}); | ||
|
||
it('renders with meta annotations correctly', function () { | ||
const event = EventFixture({ | ||
_meta: {contexts: {culture: MOCK_REDACTION}}, | ||
}); | ||
|
||
render( | ||
<ContextCard | ||
event={event} | ||
type={'culture'} | ||
alias={'culture'} | ||
value={{...MOCK_CULTURE_CONTEXT, timezone: ''}} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Culture')).toBeInTheDocument(); | ||
expect(screen.getByText('Uses 24h Format')).toBeInTheDocument(); | ||
expect(screen.getByText('true')).toBeInTheDocument(); | ||
expect(screen.getByText('Timezone')).toBeInTheDocument(); | ||
expect(screen.getByText(/redacted/)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {t} from 'sentry/locale'; | ||
import type {KeyValueListData} from 'sentry/types/group'; | ||
|
||
// https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/#culture-context | ||
const enum CultureContextKeys { | ||
CALENDAR = 'calendar', | ||
DISPLAY_NAME = 'display_name', | ||
LOCALE = 'locale', | ||
IS_24_HOUR = 'is_24_hour_format', | ||
TIMEZONE = 'timezone', | ||
} | ||
|
||
export interface CultureContext { | ||
// Any custom keys users may set | ||
[key: string]: any; | ||
[CultureContextKeys.CALENDAR]?: string; | ||
[CultureContextKeys.DISPLAY_NAME]?: string; | ||
[CultureContextKeys.LOCALE]?: string; | ||
[CultureContextKeys.IS_24_HOUR]?: boolean; | ||
[CultureContextKeys.TIMEZONE]?: string; | ||
} | ||
|
||
export function getCultureContextData({ | ||
data = {}, | ||
meta, | ||
}: { | ||
data: CultureContext; | ||
meta?: Record<keyof CultureContext, any>; | ||
}): KeyValueListData { | ||
return Object.keys(data).map(ctxKey => { | ||
switch (ctxKey) { | ||
case CultureContextKeys.CALENDAR: | ||
return { | ||
key: ctxKey, | ||
subject: t('Calendar'), | ||
value: data[CultureContextKeys.CALENDAR], | ||
}; | ||
case CultureContextKeys.DISPLAY_NAME: | ||
return { | ||
key: ctxKey, | ||
subject: t('Display Name'), | ||
value: data[CultureContextKeys.DISPLAY_NAME], | ||
}; | ||
case CultureContextKeys.LOCALE: | ||
return { | ||
key: ctxKey, | ||
subject: t('Locale'), | ||
value: data[CultureContextKeys.LOCALE], | ||
}; | ||
case CultureContextKeys.IS_24_HOUR: | ||
return { | ||
key: ctxKey, | ||
subject: t('Uses 24h Format'), | ||
value: data[CultureContextKeys.IS_24_HOUR], | ||
}; | ||
case CultureContextKeys.TIMEZONE: | ||
return { | ||
key: ctxKey, | ||
subject: t('Timezone'), | ||
value: data[CultureContextKeys.TIMEZONE], | ||
}; | ||
default: | ||
return { | ||
key: ctxKey, | ||
subject: ctxKey, | ||
value: data[ctxKey], | ||
meta: meta?.[ctxKey]?.[''], | ||
}; | ||
} | ||
}); | ||
} |
86 changes: 86 additions & 0 deletions
86
static/app/components/events/contexts/missingInstrumentation.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {EventFixture} from 'sentry-fixture/event'; | ||
|
||
import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import ContextCard from 'sentry/components/events/contexts/contextCard'; | ||
import { | ||
getMissingInstrumentationContextData, | ||
type MissingInstrumentationContext, | ||
} from 'sentry/components/events/contexts/missingInstrumentation'; | ||
|
||
const MOCK_MISSING_INSTRUMENTATION_CONTEXT: MissingInstrumentationContext = { | ||
package: 'express', | ||
'javascript.is_cjs': true, | ||
// Extra data is still valid and preserved | ||
extra_data: 'something', | ||
unknown_key: 123, | ||
}; | ||
|
||
const MOCK_REDACTION = { | ||
['package']: { | ||
'': { | ||
chunks: [ | ||
{ | ||
remark: 'x', | ||
rule_id: 'project:0', | ||
text: '', | ||
type: 'redaction', | ||
}, | ||
], | ||
len: 7, | ||
rem: [['project:0', 'x', 0, 0]], | ||
}, | ||
}, | ||
}; | ||
|
||
describe('MissingInstrumentationContext', function () { | ||
it('returns formatted data correctly', function () { | ||
expect( | ||
getMissingInstrumentationContextData({data: MOCK_MISSING_INSTRUMENTATION_CONTEXT}) | ||
).toEqual([ | ||
{ | ||
key: 'package', | ||
subject: 'Package w/o Instrumentation', | ||
value: 'express', | ||
}, | ||
{ | ||
key: 'javascript.is_cjs', | ||
subject: 'From CommonJS Module?', | ||
value: true, | ||
}, | ||
{ | ||
key: 'extra_data', | ||
subject: 'extra_data', | ||
value: 'something', | ||
meta: undefined, | ||
}, | ||
{ | ||
key: 'unknown_key', | ||
subject: 'unknown_key', | ||
value: 123, | ||
meta: undefined, | ||
}, | ||
]); | ||
}); | ||
|
||
it('renders with meta annotations correctly', function () { | ||
const event = EventFixture({ | ||
_meta: {contexts: {missing_instrumentation: MOCK_REDACTION}}, | ||
}); | ||
|
||
render( | ||
<ContextCard | ||
event={event} | ||
type={'missing_instrumentation'} | ||
alias={'missing_instrumentation'} | ||
value={{...MOCK_MISSING_INSTRUMENTATION_CONTEXT, package: ''}} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Missing OTEL Instrumentation')).toBeInTheDocument(); | ||
expect(screen.getByText('From CommonJS Module?')).toBeInTheDocument(); | ||
expect(screen.getByText('true')).toBeInTheDocument(); | ||
expect(screen.getByText('Package w/o Instrumentation')).toBeInTheDocument(); | ||
expect(screen.getByText(/redacted/)).toBeInTheDocument(); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
static/app/components/events/contexts/missingInstrumentation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {t} from 'sentry/locale'; | ||
import type {KeyValueListData} from 'sentry/types/group'; | ||
|
||
// https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/#missing-instrumentation-context | ||
const enum MissingInstrumentationContextKeys { | ||
PACKAGE = 'package', | ||
FROM_COMMONJS = 'javascript.is_cjs', | ||
} | ||
|
||
export interface MissingInstrumentationContext { | ||
// Any custom keys users may set | ||
[key: string]: any; | ||
[MissingInstrumentationContextKeys.PACKAGE]?: string; | ||
[MissingInstrumentationContextKeys.FROM_COMMONJS]?: boolean; | ||
} | ||
|
||
export function getMissingInstrumentationContextData({ | ||
data = {}, | ||
meta, | ||
}: { | ||
data: MissingInstrumentationContext; | ||
meta?: Record<keyof MissingInstrumentationContext, any>; | ||
}): KeyValueListData { | ||
return Object.keys(data).map(ctxKey => { | ||
switch (ctxKey) { | ||
case MissingInstrumentationContextKeys.PACKAGE: | ||
return { | ||
key: ctxKey, | ||
subject: t('Package w/o Instrumentation'), | ||
value: data[MissingInstrumentationContextKeys.PACKAGE], | ||
}; | ||
case MissingInstrumentationContextKeys.FROM_COMMONJS: | ||
return { | ||
key: ctxKey, | ||
subject: t('From CommonJS Module?'), | ||
value: data[MissingInstrumentationContextKeys.FROM_COMMONJS], | ||
}; | ||
default: | ||
return { | ||
key: ctxKey, | ||
subject: ctxKey, | ||
value: data[ctxKey], | ||
meta: meta?.[ctxKey]?.[''], | ||
}; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.