-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): Add connected tracing meta tags (#13098)
Also changes the `findDefaultSdkInitFile` function as the backend-related file is located and named differently than the client config file (`sentry.client.config.ts` and `public/instrument.server.mjs`). closes #13097
- Loading branch information
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
import { addSentryTracingMetaTags } from '../../../src/runtime/utils'; | ||
|
||
const mockReturns = vi.hoisted(() => { | ||
return { | ||
traceHeader: 'trace-header', | ||
baggageHeader: 'baggage-header', | ||
}; | ||
}); | ||
|
||
vi.mock('@sentry/core', async () => { | ||
const actual = await vi.importActual('@sentry/core'); | ||
|
||
return { | ||
...actual, | ||
getActiveSpan: vi.fn().mockReturnValue({ spanId: '123' }), | ||
getRootSpan: vi.fn().mockReturnValue({ spanId: 'root123' }), | ||
spanToTraceHeader: vi.fn(() => mockReturns.traceHeader), | ||
}; | ||
}); | ||
|
||
vi.mock('@sentry/opentelemetry', async () => { | ||
const actual = await vi.importActual('@sentry/opentelemetry'); | ||
|
||
return { | ||
...actual, | ||
getDynamicSamplingContextFromSpan: vi.fn().mockReturnValue('contextValue'), | ||
}; | ||
}); | ||
|
||
vi.mock('@sentry/utils', async () => { | ||
const actual = await vi.importActual('@sentry/utils'); | ||
|
||
return { | ||
...actual, | ||
dynamicSamplingContextToSentryBaggageHeader: vi.fn().mockReturnValue(mockReturns.baggageHeader), | ||
}; | ||
}); | ||
|
||
describe('addSentryTracingMetaTags', () => { | ||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it('should add meta tags when there is an active root span', () => { | ||
const head: string[] = []; | ||
addSentryTracingMetaTags(head); | ||
|
||
expect(head).toContain(`<meta name="sentry-trace" content="${mockReturns.traceHeader}"/>`); | ||
expect(head).toContain(`<meta name="baggage" content="${mockReturns.baggageHeader}"/>`); | ||
}); | ||
|
||
it('should not add meta tags when there is no active root span', () => { | ||
vi.doMock('@sentry/core', async () => { | ||
const actual = await vi.importActual('@sentry/core'); | ||
|
||
return { | ||
...actual, | ||
getActiveSpan: vi.fn().mockReturnValue(undefined), | ||
}; | ||
}); | ||
|
||
const head: string[] = []; | ||
addSentryTracingMetaTags(head); | ||
|
||
expect(head).toHaveLength(0); | ||
}); | ||
}); |