-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/extract-fieldset
- Loading branch information
Showing
11 changed files
with
256 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import axios from 'axios'; | ||
|
||
import { getSearch, SearchParams } from 'src/features/routing/AppRoutingContext'; | ||
import { appPath } from 'src/utils/urls/appUrlHelper'; | ||
|
||
function getCookies(): { [key: string]: string } { | ||
const cookie = {}; | ||
document.cookie.split(';').forEach((el) => { | ||
const split = el.split('='); | ||
cookie[split[0].trim()] = split.slice(1).join('='); | ||
}); | ||
return cookie; | ||
} | ||
|
||
export function propagateTraceWhenPdf() { | ||
try { | ||
const isPdf = new URLSearchParams(getSearch('')).get(SearchParams.Pdf) === '1'; | ||
|
||
if (isPdf) { | ||
const cookies = getCookies(); | ||
axios.interceptors.request.use((config) => { | ||
try { | ||
if (config.url?.startsWith(appPath) !== true) { | ||
return config; | ||
} | ||
|
||
// This header is caught in app-lib/backend and used to allow injection of traceparent/context | ||
config.headers['X-Altinn-IsPdf'] = 'true'; | ||
|
||
const traceparent = cookies['altinn-telemetry-traceparent']; | ||
const tracestate = cookies['altinn-telemetry-tracestate']; | ||
if (traceparent) { | ||
config.headers['traceparent'] = traceparent; | ||
} | ||
if (tracestate) { | ||
config.headers['tracestate'] = tracestate; | ||
} | ||
return config; | ||
} catch (err) { | ||
console.error('Error configuring propagation of W3C trace for request', err); | ||
return config; | ||
} | ||
}); | ||
} | ||
} catch (err) { | ||
console.error('Error configuring propagation of W3C trace', err); | ||
} | ||
} |
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
Oops, something went wrong.