|
1 | 1 | import { describe, expect, it, test } from 'vitest'; |
2 | | -import { extractTraceparentData, propagationContextFromHeaders } from '../../src/utils-hoist/tracing'; |
| 2 | +import { |
| 3 | + extractTraceparentData, |
| 4 | + propagationContextFromHeaders, |
| 5 | + shouldContinueTrace, |
| 6 | +} from '../../src/utils-hoist/tracing'; |
| 7 | +import { getDefaultTestClientOptions, TestClient } from '../mocks/client'; |
3 | 8 |
|
4 | 9 | const EXAMPLE_SENTRY_TRACE = '12312012123120121231201212312012-1121201211212012-1'; |
5 | 10 | const EXAMPLE_BAGGAGE = 'sentry-release=1.2.3,sentry-foo=bar,other=baz,sentry-sample_rand=0.42'; |
@@ -124,3 +129,65 @@ describe('extractTraceparentData', () => { |
124 | 129 | expect(extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-x')).toBeUndefined(); |
125 | 130 | }); |
126 | 131 | }); |
| 132 | + |
| 133 | +describe('shouldContinueTrace', () => { |
| 134 | + test('returns true when both baggage and SDK org IDs are undefined', () => { |
| 135 | + const client = new TestClient(getDefaultTestClientOptions({})); |
| 136 | + |
| 137 | + const result = shouldContinueTrace(client, undefined); |
| 138 | + expect(result).toBe(true); |
| 139 | + }); |
| 140 | + |
| 141 | + test('returns true when org IDs match', () => { |
| 142 | + const orgId = '123456'; |
| 143 | + const client = new TestClient(getDefaultTestClientOptions({ orgId })); |
| 144 | + |
| 145 | + const result = shouldContinueTrace(client, orgId); |
| 146 | + expect(result).toBe(true); |
| 147 | + }); |
| 148 | + |
| 149 | + test('returns false when org IDs do not match', () => { |
| 150 | + const client = new TestClient(getDefaultTestClientOptions({ orgId: '123456' })); |
| 151 | + |
| 152 | + const result = shouldContinueTrace(client, '654321'); |
| 153 | + expect(result).toBe(false); |
| 154 | + }); |
| 155 | + |
| 156 | + test('returns true when baggage org ID is undefined and strictTraceContinuation is false', () => { |
| 157 | + const client = new TestClient(getDefaultTestClientOptions({ orgId: '123456', strictTraceContinuation: false })); |
| 158 | + |
| 159 | + const result = shouldContinueTrace(client, undefined); |
| 160 | + expect(result).toBe(true); |
| 161 | + }); |
| 162 | + |
| 163 | + test('returns true when SDK org ID is undefined and strictTraceContinuation is false', () => { |
| 164 | + const client = new TestClient(getDefaultTestClientOptions({ strictTraceContinuation: false })); |
| 165 | + |
| 166 | + const result = shouldContinueTrace(client, '123456'); |
| 167 | + expect(result).toBe(true); |
| 168 | + }); |
| 169 | + |
| 170 | + test('returns false when baggage org ID is undefined and strictTraceContinuation is true', () => { |
| 171 | + const client = new TestClient(getDefaultTestClientOptions({ orgId: '123456', strictTraceContinuation: true })); |
| 172 | + |
| 173 | + const result = shouldContinueTrace(client, undefined); |
| 174 | + expect(result).toBe(false); |
| 175 | + }); |
| 176 | + |
| 177 | + test('returns false when SDK org ID is undefined and strictTraceContinuation is true', () => { |
| 178 | + const client = new TestClient(getDefaultTestClientOptions({ strictTraceContinuation: true })); |
| 179 | + |
| 180 | + const result = shouldContinueTrace(client, '123456'); |
| 181 | + expect(result).toBe(false); |
| 182 | + }); |
| 183 | + |
| 184 | + test('returns true when client is undefined', () => { |
| 185 | + const result = shouldContinueTrace(undefined, '123456'); |
| 186 | + expect(result).toBe(true); |
| 187 | + }); |
| 188 | + |
| 189 | + test('returns true when both org IDs and client are undefined', () => { |
| 190 | + const result = shouldContinueTrace(undefined, undefined); |
| 191 | + expect(result).toBe(true); |
| 192 | + }); |
| 193 | +}); |
0 commit comments