Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(solidstart): Use core's getTraceMetaTags over own implementation #13274

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering what happens if a user has any attributes set on the <head>tag like lang="de" or something like this? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea then no meta-tags, but I have never seen attributes placed on head ever before. Are there any such cases? (also our other sdks will have this problem too).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's technically possible although very uncommon


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
Loading