Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: Allow for attaching metadata and pass it to the API and transports#3177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
852f3dfacd4dd8f58a459d3cb487File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser'; | ||
| /** | ||
| * Inits the Angular SDK | ||
| */ | ||
| export function init(options: BrowserOptions): void { | ||
| options._metadata = options._metadata || {}; | ||
| options._metadata.sdk = { | ||
| name: 'sentry.javascript.angular', | ||
| packages: [ | ||
| { | ||
| name: 'npm:@sentry/angular', | ||
| version: SDK_VERSION, | ||
| }, | ||
| ], | ||
| version: SDK_VERSION, | ||
| }; | ||
| browserInit(options); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| // TODO: Remove in the next major release and rely only on @sentry/core SDK_VERSION and SdkInfo metadata | ||
| export const SDK_NAME = 'sentry.javascript.browser'; | ||
| export const SDK_VERSION = '5.30.0'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,42 @@ | ||
| import { Event, SentryRequest, Session } from '@sentry/types'; | ||
| import { Event, SdkInfo, SentryRequest, Session } from '@sentry/types'; | ||
| import { API } from './api'; | ||
| /** Extract sdk info from from the API metadata */ | ||
| function getSdkMetadataForEnvelopeHeader(api: API): SdkInfo | undefined { | ||
| if (!api.metadata || !api.metadata.sdk) { | ||
| return; | ||
| } | ||
| const { name, version } = api.metadata.sdk; | ||
| return { name, version }; | ||
| } | ||
| /** | ||
| * Apply SdkInfo (name, version, packages, integrations) to the corresponding event key. | ||
| * Merge with existing data if any. | ||
| **/ | ||
| function enhanceEventWithSdkInfo(event: Event, sdkInfo?: SdkInfo): Event { | ||
| if (!sdkInfo) { | ||
| return event; | ||
| } | ||
| event.sdk = event.sdk || { | ||
| name: sdkInfo.name, | ||
| version: sdkInfo.version, | ||
| }; | ||
| event.sdk.name = event.sdk.name || sdkInfo.name; | ||
| event.sdk.version = event.sdk.version || sdkInfo.version; | ||
| event.sdk.integrations = [...(event.sdk.integrations || []), ...(sdkInfo.integrations || [])]; | ||
| event.sdk.packages = [...(event.sdk.packages || []), ...(sdkInfo.packages || [])]; | ||
| return event; | ||
| } | ||
| /** Creates a SentryRequest from an event. */ | ||
| export function sessionToSentryRequest(session: Session, api: API): SentryRequest { | ||
| const sdkInfo = getSdkMetadataForEnvelopeHeader(api); | ||
| const envelopeHeaders = JSON.stringify({ | ||
| sent_at: new Date().toISOString(), | ||
| ...(sdkInfo && { sdk: sdkInfo }), | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only want | ||
| }); | ||
| const itemHeaders = JSON.stringify({ | ||
| type: 'session', | ||
| @@ -24,11 +55,13 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest { | ||
| const { __sentry_samplingMethod: samplingMethod, __sentry_sampleRate: sampleRate, ...otherTags } = event.tags || {}; | ||
| event.tags = otherTags; | ||
| const useEnvelope = event.type === 'transaction'; | ||
| const sdkInfo = getSdkMetadataForEnvelopeHeader(api); | ||
| const eventType = event.type || 'event'; | ||
| const useEnvelope = eventType === 'transaction'; | ||
| const req: SentryRequest = { | ||
| body: JSON.stringify(event), | ||
| type: event.type || 'event', | ||
| body: JSON.stringify(sdkInfo ? enhanceEventWithSdkInfo(event, api.metadata.sdk) : event), | ||
| type: eventType, | ||
| url: useEnvelope ? api.getEnvelopeEndpointWithUrlEncodedAuth() : api.getStoreEndpointWithUrlEncodedAuth(), | ||
| }; | ||
| @@ -42,6 +75,7 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest { | ||
| const envelopeHeaders = JSON.stringify({ | ||
| event_id: event.event_id, | ||
| sent_at: new Date().toISOString(), | ||
| ...(sdkInfo && { sdk: sdkInfo }), | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: We only want | ||
| }); | ||
| const itemHeaders = JSON.stringify({ | ||
| type: event.type, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const SDK_VERSION = '5.30.0'; |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.