(client: Client, baggageOrgId?: string)
| 151 | * See https://develop.sentry.dev/sdk/telemetry/traces/#stricttracecontinuation |
| 152 | */ |
| 153 | export function shouldContinueTrace(client: Client, baggageOrgId?: string): boolean { |
| 154 | const clientOrgId = extractOrgIdFromClient(client); |
| 155 | |
| 156 | // Case: baggage orgID and Client orgID don't match - always start new trace |
| 157 | if (baggageOrgId && clientOrgId && baggageOrgId !== clientOrgId) { |
| 158 | debug.log( |
| 159 | `Won't continue trace because org IDs don't match (incoming baggage: ${baggageOrgId}, SDK options: ${clientOrgId})`, |
| 160 | ); |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | const strictTraceContinuation = client.getOptions().strictTraceContinuation || false; // default for `strictTraceContinuation` is `false` |
| 165 | |
| 166 | if (strictTraceContinuation) { |
| 167 | // With strict continuation enabled, don't continue trace if: |
| 168 | // - Baggage has orgID, but Client doesn't have one |
| 169 | // - Client has orgID, but baggage doesn't have one |
| 170 | if ((baggageOrgId && !clientOrgId) || (!baggageOrgId && clientOrgId)) { |
| 171 | debug.log( |
| 172 | `Starting a new trace because strict trace continuation is enabled but one org ID is missing (incoming baggage: ${baggageOrgId}, Sentry client: ${clientOrgId})`, |
| 173 | ); |
| 174 | return false; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | return true; |
| 179 | } |
no test coverage detected