Skip to content

Commit

Permalink
Fix imports & Tests (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
HazAT authored Nov 22, 2023
1 parent 22b970c commit ae4d56f
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 35 deletions.
3 changes: 3 additions & 0 deletions packages/core/_fixtures/envelope1.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/core/_fixtures/envelope_python.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/core/src/components/Debugger.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactComponent as Logo } from '~/assets/glyph.svg';
import { Integration, IntegrationData } from '~/integrations/integration';
import classNames from '~/lib/classNames';
import useKeyPress from '~/lib/useKeyPress';
import classNames from '../lib/classNames';
import useKeyPress from '../lib/useKeyPress';
import Overview from './Overview';

export default function Debugger({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/Trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactComponent as Logo } from '~/assets/glyph.svg';
import classNames from '~/lib/classNames';
import { TriggerButtonCount } from '~/types';
import classNames from '../lib/classNames';
import { TriggerButtonCount } from '../types';

export default function Trigger({
isOpen,
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/integrations/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type IntegrationTab<T> = {
active?: boolean;
};

type ProcessedEventContainer<T> = {
export type ProcessedEventContainer<T> = {
/**
* The processed event data to be passed to your tabs.
*/
Expand All @@ -86,9 +86,11 @@ type ProcessedEventContainer<T> = {
*
* @default value is 'default'
*/
severity?: 'default' | 'severe';
severity?: Severity;
};

export type Severity = 'default' | 'severe';

export type IntegrationData<T> = Record<string, ProcessedEventContainer<T>[]>;

type TabsContext<T> = {
Expand All @@ -97,7 +99,7 @@ type TabsContext<T> = {

type TabsCreationFunction<T> = (context: TabsContext<T>) => IntegrationTab<T>[];

type RawEventContext = {
export type RawEventContext = {
/**
* The content-type header of the event
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { Link, Outlet, Route, Routes, useParams } from 'react-router-dom';
import Tabs from '~/components/Tabs';
import Tabs from '../../../components/Tabs';
import sentryDataCache from '../data/sentryDataCache';
import { SentryEvent } from '../types';
import EventBreadcrumbs from './EventBreadcrumbs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import classNames from '~/lib/classNames';
import classNames from '../../../../../lib/classNames';
import { EventFrame, FrameVars } from '../../../types';

function formatFilename(filename: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link, useParams } from 'react-router-dom';
import classNames from '~/lib/classNames';
import classNames from '../../../lib/classNames';
import { Span, TraceContext } from '../types';
import { getDuration, getSpanDurationClassName } from '../utils/duration';
import PlatformIcon from './PlatformIcon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from 'react-router-dom';
import classNames from '~/lib/classNames';
import classNames from '../../../lib/classNames';
import { useSentryTraces } from '../data/useSentryTraces';
import { getDuration } from '../utils/duration';
import PlatformIcon from './PlatformIcon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Envelope } from '@sentry/types';
import { generate_uuidv4 } from '~/lib/uuid';
import { generate_uuidv4 } from '../../../lib/uuid';
import { Sdk, SentryErrorEvent, SentryEvent, SentryTransactionEvent, Span, Trace } from '../types';
import { groupSpans } from '../utils/traces';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactNode } from 'react';
import React, { useEffect, useReducer } from 'react';
import sentryDataCache from '~/integrations/sentry/data/sentryDataCache';
import sentryDataCache from './sentryDataCache';
import { SentryEvent } from '../types';

export const SentryEventsContext = React.createContext<SentryEvent[]>([]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from 'react';
import sentryDataCache from '~/integrations/sentry/data/sentryDataCache';
import sentryDataCache from './sentryDataCache';
import { SentryEventsContext } from './sentryEventsContext';

export const useSentrySdks = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from 'react';
import sentryDataCache from '~/integrations/sentry/data/sentryDataCache';
import sentryDataCache from './sentryDataCache';
import { SentryEventsContext } from './sentryEventsContext';

export const useSentryTraces = () => {
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/integrations/sentry/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, test } from 'vitest';
import { processEnvelope } from './index';

import fs from 'fs';

describe('Sentry Integration', () => {
test('Process Envelope', () => {
const envelope = fs.readFileSync('./_fixtures/envelope1.txt', 'utf-8');
expect(processEnvelope({ data: envelope, contentType: 'test' })).not.toBe(undefined);
});

test('Process Python Transaction Envelope', () => {
const envelope = fs.readFileSync('./_fixtures/envelope_python.txt', 'utf-8');
expect(processEnvelope({ data: envelope, contentType: 'test' })).not.toBe(undefined);
});
});
43 changes: 23 additions & 20 deletions packages/core/src/integrations/sentry/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Envelope } from '@sentry/types';

import type { Integration } from '../integration';
import type { Integration, RawEventContext, Severity } from '../integration';

import sentryDataCache from './data/sentryDataCache';
import { Spotlight } from './sentry-integration';
Expand All @@ -21,25 +21,7 @@ export default function sentryIntegration() {
addSpotlightIntegrationToSentry();
},

processEvent({ data }) {
console.log('[spotlight] Received new envelope');
const [rawHeader, ...rawEntries] = data.split('\n');
const header = JSON.parse(rawHeader) as Envelope[0];
console.log(`[Spotlight] Received new envelope from SDK ${header.sdk?.name || '(unknown)'}`);

const items: Envelope[1][] = [];
for (let i = 0; i < rawEntries.length; i += 2) {
items.push([JSON.parse(rawEntries[i]), JSON.parse(rawEntries[i + 1])]);
}

const envelope = [header, items] as Envelope;
sentryDataCache.pushEnvelope(envelope);

return {
event: envelope,
severity: isErrorEnvelope(envelope) ? 'severe' : 'default',
};
},
processEvent: (event: RawEventContext) => processEnvelope(event),

tabs: () => [
{
Expand Down Expand Up @@ -77,6 +59,27 @@ type WindowWithSentry = Window & {
};
};

export function processEnvelope({ data }: RawEventContext) {
console.log('[Spotlight] Received new envelope');
const [rawHeader, ...rawEntries] = data.split(/\n/gm);

const header = JSON.parse(rawHeader) as Envelope[0];
console.log(`[Spotlight] Received new envelope from SDK ${header.sdk?.name || '(unknown)'}`);

const items: Envelope[1][] = [];
for (let i = 0; i < rawEntries.length; i += 2) {
items.push([JSON.parse(rawEntries[i]), JSON.parse(rawEntries[i + 1])]);
}

const envelope = [header, items] as Envelope;
sentryDataCache.pushEnvelope(envelope);

return {
event: envelope,
severity: isErrorEnvelope(envelope) ? 'severe' : ('default' as Severity),
};
}

function isErrorEnvelope(envelope: Envelope) {
return envelope[1].some(([itemHeader]) => itemHeader.type === 'event');
}
Expand Down

0 comments on commit ae4d56f

Please sign in to comment.