Skip to content

Commit

Permalink
s/getTracingMetaTags/getTraceMetaTags
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Aug 5, 2024
1 parent 478c23b commit 1fcd07b
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ app.get('/test', (_req, res) => {
response: `
<html>
<head>
${Sentry.getTracingMetaTags()}
${Sentry.getTraceMetaTags()}
</head>
<body>
Hi :)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

describe('getTracingMetaTags', () => {
describe('getTraceMetaTags', () => {
afterAll(() => {
cleanupChildProcesses();
});
Expand Down
6 changes: 2 additions & 4 deletions packages/astro/src/server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getActiveSpan,
getClient,
getCurrentScope,
getTracingMetaTags,
getTraceMetaTags,
setHttpStatus,
startSpan,
withIsolationScope,
Expand All @@ -15,8 +15,6 @@ import type { Client, Scope, Span, SpanAttributes } from '@sentry/types';
import { addNonEnumerableProperty, objectify, stripUrlQueryAndFragment } from '@sentry/utils';
import type { APIContext, MiddlewareResponseHandler } from 'astro';

import { getTraceData } from '@sentry/node';

type MiddlewareOptions = {
/**
* If true, the client IP will be attached to the event by calling `setUser`.
Expand Down Expand Up @@ -190,7 +188,7 @@ function addMetaTagToHead(htmlChunk: string, scope: Scope, client: Client, span?
if (typeof htmlChunk !== 'string') {
return htmlChunk;
}
const metaTags = getTracingMetaTags(span, scope, client);
const metaTags = getTraceMetaTags(span, scope, client);

if (!metaTags) {
return htmlChunk;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/server/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('sentryMiddleware', () => {
});
vi.spyOn(SentryNode, 'getActiveSpan').mockImplementation(getSpanMock);
vi.spyOn(SentryNode, 'getClient').mockImplementation(() => ({}) as Client);
vi.spyOn(SentryNode, 'getTracingMetaTags').mockImplementation(
vi.spyOn(SentryNode, 'getTraceMetaTags').mockImplementation(
() => `
<meta name="sentry-trace" content="123">
<meta name="baggage" content="abc">
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export {
getGlobalScope,
getIsolationScope,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
setCurrentClient,
Scope,
SDK_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export {
getGlobalScope,
getIsolationScope,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
setCurrentClient,
Scope,
SDK_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export {
getActiveSpan,
getRootSpan,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
startSpan,
startInactiveSpan,
startSpanManual,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export {
export { parseSampleRate } from './utils/parseSampleRate';
export { applySdkMetadata } from './utils/sdkMetadata';
export { getTraceData } from './utils/traceData';
export { getTracingMetaTags } from './utils/meta';
export { getTraceMetaTags } from './utils/meta';
export { DEFAULT_ENVIRONMENT } from './constants';
export { addBreadcrumb } from './breadcrumbs';
export { functionToStringIntegration } from './integrations/functiontostring';
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/utils/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ import type { Client, Scope, Span } from '@sentry/types';
import { getTraceData } from './traceData';

/**
* Returns a string of meta tags that represent the tracing data.
* Returns a string of meta tags that represent the current trace data.
*
* You can use this to propagate a trace from your server-side rendered Html to the browser.
* This function returns up to two meta tags, `sentry-trace` and `baggage`, depending on the
* current trace data state.
*
* @example
* Usage example:
*
* ```js
* function renderHtml() {
* return `
* <head>
* ${getTracingMetaTags()}
* ${getTraceMetaTags()}
* </head>
* `;
* }
* ```
*
* @returns
*/
export function getTracingMetaTags(span?: Span, scope?: Scope, client?: Client): string {
export function getTraceMetaTags(span?: Span, scope?: Scope, client?: Client): string {
return Object.entries(getTraceData(span, scope, client))
.map(([key, value]) => `<meta name="${key}" content="${value}"/>`)
.join('\n');
Expand Down
10 changes: 5 additions & 5 deletions packages/core/test/lib/utils/meta.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { getTracingMetaTags } from '../../../src/utils/meta';
import { getTraceMetaTags } from '../../../src/utils/meta';
import * as TraceDataModule from '../../../src/utils/traceData';

describe('getTracingMetaTags', () => {
describe('getTraceMetaTags', () => {
it('renders baggage and sentry-trace values to stringified Html meta tags', () => {
jest.spyOn(TraceDataModule, 'getTraceData').mockReturnValueOnce({
'sentry-trace': '12345678901234567890123456789012-1234567890123456-1',
baggage: 'sentry-environment=production',
});

expect(getTracingMetaTags()).toBe(`<meta name="sentry-trace" content="12345678901234567890123456789012-1234567890123456-1"/>
expect(getTraceMetaTags()).toBe(`<meta name="sentry-trace" content="12345678901234567890123456789012-1234567890123456-1"/>
<meta name="baggage" content="sentry-environment=production"/>`);
});

Expand All @@ -17,14 +17,14 @@ describe('getTracingMetaTags', () => {
'sentry-trace': '12345678901234567890123456789012-1234567890123456-1',
});

expect(getTracingMetaTags()).toBe(
expect(getTraceMetaTags()).toBe(
'<meta name="sentry-trace" content="12345678901234567890123456789012-1234567890123456-1"/>',
);
});

it('returns an empty string if neither sentry-trace nor baggage values are available', () => {
jest.spyOn(TraceDataModule, 'getTraceData').mockReturnValueOnce({});

expect(getTracingMetaTags()).toBe('');
expect(getTraceMetaTags()).toBe('');
});
});
2 changes: 1 addition & 1 deletion packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export {
getActiveSpan,
getRootSpan,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
startSpan,
startInactiveSpan,
startSpanManual,
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export {
getGlobalScope,
getIsolationScope,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
setCurrentClient,
Scope,
SDK_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export {
getCurrentScope,
getIsolationScope,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
withScope,
withIsolationScope,
captureException,
Expand Down
2 changes: 1 addition & 1 deletion packages/sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export {
getSpanDescendants,
getSpanStatusFromHttpCode,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
graphqlIntegration,
hapiIntegration,
httpIntegration,
Expand Down
2 changes: 1 addition & 1 deletion packages/vercel-edge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export {
getActiveSpan,
getRootSpan,
getTraceData,
getTracingMetaTags,
getTraceMetaTags,
startSpan,
startInactiveSpan,
startSpanManual,
Expand Down

0 comments on commit 1fcd07b

Please sign in to comment.