Skip to content

Commit

Permalink
ref(solidstart): Use core's getTraceMetaTags over own implementation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiborza authored Aug 8, 2024
1 parent 6a08d90 commit 6cbc416
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
14 changes: 4 additions & 10 deletions packages/solidstart/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTraceData } from '@sentry/core';
import { getTraceMetaTags } from '@sentry/core';
import { addNonEnumerableProperty } from '@sentry/utils';
import type { ResponseMiddleware } from '@solidjs/start/middleware';
import type { FetchEvent } from '@solidjs/start/server';
Expand All @@ -8,19 +8,13 @@ export type ResponseMiddlewareResponse = Parameters<ResponseMiddleware>[1] & {
};

function addMetaTagToHead(html: string): string {
const { 'sentry-trace': sentryTrace, baggage } = getTraceData();
const metaTags = getTraceMetaTags();

if (!sentryTrace) {
if (!metaTags) {
return html;
}

const metaTags = [`<meta name="sentry-trace" content="${sentryTrace}">`];

if (baggage) {
metaTags.push(`<meta name="baggage" content="${baggage}">`);
}

const content = `<head>\n${metaTags.join('\n')}\n`;
const content = `<head>\n${metaTags}\n`;
return html.replace('<head>', content);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/solidstart/test/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { ResponseMiddlewareResponse } from '../src/middleware';

describe('middleware', () => {
describe('sentryBeforeResponseMiddleware', () => {
vi.spyOn(SentryCore, 'getTraceData').mockReturnValue({
'sentry-trace': '123',
baggage: 'abc',
});
vi.spyOn(SentryCore, 'getTraceMetaTags').mockReturnValue(`
<meta name="sentry-trace" content="123">,
<meta name="baggage" content="abc">
`);

const mockFetchEvent = {
request: {},
Expand Down

0 comments on commit 6cbc416

Please sign in to comment.