Skip to content

Commit 9296b88

Browse files
committed
feat(node): Add getTracingMetaTags function
1 parent 964d050 commit 9296b88

File tree

5 files changed

+15
-290
lines changed

5 files changed

+15
-290
lines changed

packages/astro/src/server/meta.ts

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

packages/astro/src/server/middleware.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { Client, Scope, Span, SpanAttributes } from '@sentry/types';
1414
import { addNonEnumerableProperty, objectify, stripUrlQueryAndFragment } from '@sentry/utils';
1515
import type { APIContext, MiddlewareResponseHandler } from 'astro';
1616

17-
import { getTracingMetaTags } from './meta';
17+
import { getTracingMetaTags } from '@sentry/node';
1818

1919
type MiddlewareOptions = {
2020
/**
@@ -189,9 +189,14 @@ function addMetaTagToHead(htmlChunk: string, scope: Scope, client: Client, span?
189189
if (typeof htmlChunk !== 'string') {
190190
return htmlChunk;
191191
}
192+
console.log({ scope });
193+
const { 'sentry-trace': sentryTrace, baggage } = getTracingMetaTags(span, scope, client);
194+
195+
const sentryTraceMeta = `<meta name="sentry-trace" content="${sentryTrace}"/>`;
196+
const baggageMeta = baggage && `<meta name="baggage" content="${baggage}"/>`;
197+
198+
const content = `<head>\n${sentryTraceMeta}`.concat(baggageMeta ? `\n${baggageMeta}` : '', '\n');
192199

193-
const { sentryTrace, baggage } = getTracingMetaTags(span, scope, client);
194-
const content = `<head>\n${sentryTrace}\n${baggage}\n`;
195200
return htmlChunk.replace('<head>', content);
196201
}
197202

packages/astro/test/server/meta.test.ts

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

packages/astro/test/server/middleware.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
2+
import * as SentryCore from '@sentry/core';
23
import * as SentryNode from '@sentry/node';
34
import type { Client, Span } from '@sentry/types';
4-
import { vi } from 'vitest';
5+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
56

67
import { handleRequest, interpolateRouteFromUrlAndParams } from '../../src/server/middleware';
78

@@ -28,10 +29,14 @@ describe('sentryMiddleware', () => {
2829
setPropagationContext: vi.fn(),
2930
getSpan: getSpanMock,
3031
setSDKProcessingMetadata: setSDKProcessingMetadataMock,
32+
getPropagationContext: () => ({}),
3133
} as any;
3234
});
3335
vi.spyOn(SentryNode, 'getActiveSpan').mockImplementation(getSpanMock);
3436
vi.spyOn(SentryNode, 'getClient').mockImplementation(() => ({}) as Client);
37+
vi.spyOn(SentryCore, 'getDynamicSamplingContextFromSpan').mockImplementation(() => ({
38+
transaction: 'test',
39+
}));
3540
});
3641

3742
const nextResult = Promise.resolve(new Response(null, { status: 200, headers: new Headers() }));

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export { initOpenTelemetry, preloadOpenTelemetry } from './sdk/initOtel';
4040
export { getAutoPerformanceIntegrations } from './integrations/tracing';
4141
export { getSentryRelease, defaultStackParser } from './sdk/api';
4242
export { createGetModuleFromFilename } from './utils/module';
43+
export { getTracingMetaTags } from './utils/meta';
4344
export { makeNodeTransport } from './transports';
4445
export { NodeClient } from './sdk/client';
4546
export { cron } from './cron';

0 commit comments

Comments
 (0)