Skip to content

Commit

Permalink
s/getTracingMetaTags/getTracingMetaTagValues
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Jul 31, 2024
1 parent 6be5f22 commit 219b070
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export {
getSentryRelease,
getSpanDescendants,
getSpanStatusFromHttpCode,
getTracingMetaTags,
getTracingMetaTagValues,
graphqlIntegration,
hapiIntegration,
httpIntegration,
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { Client, Scope, Span, SpanAttributes } from '@sentry/types';
import { addNonEnumerableProperty, objectify, stripUrlQueryAndFragment } from '@sentry/utils';
import type { APIContext, MiddlewareResponseHandler } from 'astro';

import { getTracingMetaTags } from '@sentry/node';
import { getTracingMetaTagValues } from '@sentry/node';

type MiddlewareOptions = {
/**
Expand Down Expand Up @@ -189,7 +189,7 @@ function addMetaTagToHead(htmlChunk: string, scope: Scope, client: Client, span?
if (typeof htmlChunk !== 'string') {
return htmlChunk;
}
const { 'sentry-trace': sentryTrace, baggage } = getTracingMetaTags(span, scope, client);
const { 'sentry-trace': sentryTrace, baggage } = getTracingMetaTagValues(span, scope, client);

const sentryTraceMeta = `<meta name="sentry-trace" content="${sentryTrace}"/>`;
const baggageMeta = baggage && `<meta name="baggage" content="${baggage}"/>`;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/integration/middleware/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, it, vi } from 'vitest';
import { onRequest } from '../../../src/integration/middleware';

vi.mock('../../../src/server/meta', () => ({
getTracingMetaTags: () => ({
getTracingMetaTagValues: () => ({
sentryTrace: '<meta name="sentry-trace" content="123">',
baggage: '<meta name="baggage" content="abc">',
}),
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 @@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { handleRequest, interpolateRouteFromUrlAndParams } from '../../src/server/middleware';

vi.mock('../../src/server/meta', () => ({
getTracingMetaTags: () => ({
getTracingMetaTagValues: () => ({
sentryTrace: '<meta name="sentry-trace" content="123">',
baggage: '<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 @@ -20,7 +20,7 @@ export {
getCurrentScope,
getGlobalScope,
getIsolationScope,
getTracingMetaTags,
getTracingMetaTagValues,
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 @@ -40,7 +40,7 @@ export {
getCurrentScope,
getGlobalScope,
getIsolationScope,
getTracingMetaTags,
getTracingMetaTagValues,
setCurrentClient,
Scope,
SDK_VERSION,
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 @@ -20,7 +20,7 @@ export {
getCurrentScope,
getGlobalScope,
getIsolationScope,
getTracingMetaTags,
getTracingMetaTagValues,
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 @@ -40,7 +40,7 @@ export { initOpenTelemetry, preloadOpenTelemetry } from './sdk/initOtel';
export { getAutoPerformanceIntegrations } from './integrations/tracing';
export { getSentryRelease, defaultStackParser } from './sdk/api';
export { createGetModuleFromFilename } from './utils/module';
export { getTracingMetaTags } from './utils/meta';
export { getTracingMetaTagValues } from './utils/meta';
export { makeNodeTransport } from './transports';
export { NodeClient } from './sdk/client';
export { cron } from './cron';
Expand Down
22 changes: 16 additions & 6 deletions packages/node/src/utils/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@ import {
} from '@sentry/utils';

/**
* Extracts the tracing data from the current span or from the client's scope (via transaction or propagation context)
* and serializes the data to <meta> tag contents.
* Extracts trace propagation data from the current span or from the client's scope (via transaction or propagation
* context) and serializes it to meta tag content values.
*
* Use this function to obtain the tracing meta tags you can inject when rendering an HTML response to continue
* the server-initiated trace on the client.
* Use this function to obtain data for the tracing meta tags you can inject when rendering an HTML response to
* continue the server-initiated trace on the client.
*
* Example usage:
*
* ```js
* // render meta tags as html
* const tagValues = getTracingMetaTagValues(span, scope, client);
* return `
* <meta name="sentry-trace" content="${tagValues['sentry-trace']}"/>
* ${tagValues.baggage ? `<meta name="baggage" content="${tagValues.baggage}"/>` : ''}`
* ```
*
* @param span the currently active span
* @param client the SDK's client
*
* @returns an object with the two meta tags. The object keys are the name of the meta tag,
* @returns an object with the values of the tracing meta tags. The object keys are the name of the meta tag,
* the respective value is the content.
*/
export function getTracingMetaTags(
export function getTracingMetaTagValues(
span: Span | undefined,
scope: Scope,
client: Client | undefined,
Expand Down
12 changes: 6 additions & 6 deletions packages/node/test/utils/meta.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as SentryCore from '@sentry/core';
import { SentrySpan } from '@sentry/core';

import { getTracingMetaTags, isValidBaggageString } from '../../src/utils/meta';
import { getTracingMetaTagValues, isValidBaggageString } from '../../src/utils/meta';

const TRACE_FLAG_SAMPLED = 1;

Expand All @@ -19,14 +19,14 @@ const mockedScope = {
}),
} as any;

describe('getTracingMetaTags', () => {
describe('getTracingMetaTagValues', () => {
it('returns the tracing meta tags from the span, if it is provided', () => {
{
jest.spyOn(SentryCore, 'getDynamicSamplingContextFromSpan').mockReturnValueOnce({
environment: 'production',
});

const tags = getTracingMetaTags(mockedSpan, mockedScope, mockedClient);
const tags = getTracingMetaTagValues(mockedSpan, mockedScope, mockedClient);

expect(tags).toEqual({
'sentry-trace': '12345678901234567890123456789012-1234567890123456-1',
Expand All @@ -36,7 +36,7 @@ describe('getTracingMetaTags', () => {
});

it('returns propagationContext DSC data if no span is available', () => {
const tags = getTracingMetaTags(
const tags = getTracingMetaTagValues(
undefined,
{
getPropagationContext: () => ({
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('getTracingMetaTags', () => {
public_key: undefined,
});

const tags = getTracingMetaTags(
const tags = getTracingMetaTagValues(
// @ts-expect-error - we don't need to provide all the properties
{
isRecording: () => true,
Expand All @@ -92,7 +92,7 @@ describe('getTracingMetaTags', () => {
public_key: undefined,
});

const tags = getTracingMetaTags(
const tags = getTracingMetaTagValues(
// @ts-expect-error - we don't need to provide all the properties
{
isRecording: () => true,
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 @@ -51,7 +51,7 @@ export {
getSentryRelease,
getSpanDescendants,
getSpanStatusFromHttpCode,
getTracingMetaTags,
getTracingMetaTagValues,
graphqlIntegration,
hapiIntegration,
httpIntegration,
Expand Down

0 comments on commit 219b070

Please sign in to comment.