-
Notifications
You must be signed in to change notification settings - Fork 2
sdk-core, browser, node: add BacktraceApi #335
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3524309
sdk-core: add or move http request bodies and responses
perf2711 38d5c08
sdk-core: change RequestBacktraceReportSubmission to use new http bodies
perf2711 7d18b0a
sdk-core: add BacktraceCoreApi
perf2711 d07b0aa
node: add BacktraceApi
perf2711 e1afa76
browser: add BacktraceApi
perf2711 c7f9021
browser: remove options class variable from BacktraceBrowserRequestHa…
perf2711 44aa9e9
node: remove options class variable from BacktraceNodeRequestHandler
perf2711 67de531
sdk-core, node, browser: MR updates
perf2711 456e78b
sdk-core: rename http models
perf2711 95cf2bd
sdk-core: rename http models
perf2711 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,15 @@ | ||
import { BacktraceCoreApi, BacktraceCoreApiOptions } from '@backtrace/sdk-core'; | ||
import { | ||
BacktraceBrowserRequestHandler, | ||
BacktraceBrowserRequestHandlerOptions, | ||
} from './BacktraceBrowserRequestHandler.js'; | ||
|
||
export interface BacktraceApiOptions extends BacktraceCoreApiOptions { | ||
readonly requestHandlerOptions?: BacktraceBrowserRequestHandlerOptions; | ||
} | ||
|
||
export class BacktraceApi extends BacktraceCoreApi { | ||
constructor(options: BacktraceApiOptions) { | ||
super(options, options.requestHandler ?? new BacktraceBrowserRequestHandler(options.requestHandlerOptions)); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
import { BacktraceCoreApi, BacktraceCoreApiOptions } from '@backtrace/sdk-core'; | ||
import { BacktraceNodeRequestHandler, BacktraceNodeRequestHandlerOptions } from './BacktraceNodeRequestHandler.js'; | ||
|
||
export interface BacktraceApiOptions extends BacktraceCoreApiOptions { | ||
readonly requestHandlerOptions?: BacktraceNodeRequestHandlerOptions; | ||
} | ||
|
||
export class BacktraceApi extends BacktraceCoreApi { | ||
constructor(options: BacktraceApiOptions) { | ||
super(options, options.requestHandler ?? new BacktraceNodeRequestHandler(options.requestHandlerOptions)); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,97 @@ | ||
import { BacktraceAttachment } from './model/attachment/BacktraceAttachment.js'; | ||
import { | ||
BacktraceAttachmentResponse, | ||
BacktraceReportSubmissionResult, | ||
BacktraceRequestHandler, | ||
BacktraceSubmitBody, | ||
BacktraceSubmitResponse, | ||
RequestBacktraceReportSubmission, | ||
} from './model/http/index.js'; | ||
import { | ||
BacktraceSubmitSummedMetricsBody, | ||
BacktraceSubmitUniqueMetricsBody, | ||
} from './model/http/model/metric/request/BacktraceSubmitMetricsBody.js'; | ||
import { MetricsUrlInformation } from './modules/metrics/MetricsUrlInformation.js'; | ||
|
||
export interface BacktraceCoreApiOptions { | ||
readonly url: string; | ||
readonly token?: string; | ||
|
||
readonly metrics?: { | ||
readonly url?: string; | ||
}; | ||
|
||
readonly requestHandler?: BacktraceRequestHandler; | ||
readonly requestBacktraceReportSubmission?: RequestBacktraceReportSubmission; | ||
} | ||
|
||
export class BacktraceCoreApi { | ||
private readonly _summedMetricsSubmissionUrl?: string; | ||
private readonly _uniqueMetricsSubmissionUrl?: string; | ||
|
||
private readonly _requestHandler: BacktraceRequestHandler; | ||
private readonly _requestBacktraceReportSubmission: RequestBacktraceReportSubmission; | ||
|
||
constructor(options: BacktraceCoreApiOptions, requestHandler: BacktraceRequestHandler) { | ||
this._summedMetricsSubmissionUrl = MetricsUrlInformation.generateSummedEventsUrl( | ||
options.metrics?.url ?? 'https://events.backtrace.io', | ||
options.url, | ||
options.token, | ||
); | ||
|
||
this._uniqueMetricsSubmissionUrl = MetricsUrlInformation.generateUniqueEventsUrl( | ||
options.metrics?.url ?? 'https://events.backtrace.io', | ||
options.url, | ||
options.token, | ||
); | ||
|
||
this._requestHandler = options.requestHandler ?? requestHandler; | ||
perf2711 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
this._requestBacktraceReportSubmission = | ||
options.requestBacktraceReportSubmission ?? | ||
new RequestBacktraceReportSubmission( | ||
{ | ||
url: options.url, | ||
}, | ||
this._requestHandler, | ||
); | ||
} | ||
|
||
public sendReport( | ||
data: BacktraceSubmitBody, | ||
attachments: BacktraceAttachment[], | ||
abortSignal?: AbortSignal, | ||
): Promise<BacktraceReportSubmissionResult<BacktraceSubmitResponse>> { | ||
return this._requestBacktraceReportSubmission.send(data, attachments, abortSignal); | ||
} | ||
|
||
public sendAttachment( | ||
rxid: string, | ||
attachment: BacktraceAttachment, | ||
abortSignal?: AbortSignal, | ||
): Promise<BacktraceReportSubmissionResult<BacktraceAttachmentResponse>> { | ||
return this._requestBacktraceReportSubmission.sendAttachment(rxid, attachment, abortSignal); | ||
} | ||
|
||
public sendUniqueMetrics( | ||
metrics: BacktraceSubmitUniqueMetricsBody, | ||
abortSignal?: AbortSignal, | ||
): Promise<BacktraceReportSubmissionResult<unknown>> { | ||
if (!this._uniqueMetricsSubmissionUrl) { | ||
throw new Error('Unique metrics URL is not available.'); | ||
} | ||
|
||
return this._requestHandler.post(this._uniqueMetricsSubmissionUrl, JSON.stringify(metrics), abortSignal); | ||
} | ||
|
||
public sendSummedMetrics( | ||
metrics: BacktraceSubmitSummedMetricsBody, | ||
abortSignal?: AbortSignal, | ||
): Promise<BacktraceReportSubmissionResult<unknown>> { | ||
if (!this._summedMetricsSubmissionUrl) { | ||
throw new Error('Summed metrics URL is not available.'); | ||
} | ||
|
||
return this._requestHandler.post(this._summedMetricsSubmissionUrl, JSON.stringify(metrics), abortSignal); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
export * from './response/BacktraceAttachmentResponse.js'; |
4 changes: 2 additions & 2 deletions
4
...http/model/BacktraceAttachmentResponse.ts → ...t/response/BacktraceAttachmentResponse.ts
This file contains hidden or 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 hidden or 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,2 @@ | ||
export * from './request/BacktraceSubmitMetricEventBody.js'; | ||
export * from './request/BacktraceSubmitMetricsBody.js'; |
13 changes: 13 additions & 0 deletions
13
packages/sdk-core/src/model/http/model/metric/request/BacktraceSubmitMetricEventBody.ts
This file contains hidden or 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,13 @@ | ||
import { AttributeType } from '../../../../data/BacktraceData.js'; | ||
|
||
export interface BacktraceSubmitSummedMetricEventBody { | ||
timestamp: number; | ||
attributes: Record<string, AttributeType>; | ||
metric_group: string; | ||
} | ||
|
||
export interface BacktraceSubmitUniqueMetricEventBody { | ||
timestamp: number; | ||
attributes: Record<string, AttributeType>; | ||
unique: string[]; | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/sdk-core/src/model/http/model/metric/request/BacktraceSubmitMetricsBody.ts
This file contains hidden or 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,22 @@ | ||
import { | ||
BacktraceSubmitSummedMetricEventBody, | ||
BacktraceSubmitUniqueMetricEventBody, | ||
} from './BacktraceSubmitMetricEventBody.js'; | ||
|
||
export interface BacktraceSubmitMetricsMetadataBody { | ||
dropped_events?: number; | ||
} | ||
|
||
export type BacktraceSubmitSummedMetricsBody = { | ||
application: string; | ||
appversion: string; | ||
metadata?: BacktraceSubmitMetricsMetadataBody; | ||
summed_events: BacktraceSubmitSummedMetricEventBody[]; | ||
}; | ||
|
||
export type BacktraceSubmitUniqueMetricsBody = { | ||
application: string; | ||
appversion: string; | ||
metadata?: BacktraceSubmitMetricsMetadataBody; | ||
unique_events: BacktraceSubmitUniqueMetricEventBody[]; | ||
}; |
This file contains hidden or 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,10 @@ | ||
export * from './request/BacktraceSubmitArch.js'; | ||
export * from './request/BacktraceSubmitAttributeType.js'; | ||
export * from './request/BacktraceSubmitBody.js'; | ||
export * from './request/BacktraceSubmitMemory.js'; | ||
export * from './request/BacktraceSubmitModule.js'; | ||
export * from './request/BacktraceSubmitSourceCode.js'; | ||
export * from './request/BacktraceSubmitStackFrame.js'; | ||
export * from './request/BacktraceSubmitThread.js'; | ||
|
||
export * from './response/BacktraceSubmitResponse.js'; |
16 changes: 16 additions & 0 deletions
16
packages/sdk-core/src/model/http/model/submit/request/BacktraceSubmitArch.ts
This file contains hidden or 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,16 @@ | ||
export interface BacktraceSubmitArch { | ||
/** | ||
* On some systems the running program can be run with a different arch than the system itself. | ||
* `attributes.uname.machine` has to do with the system arch; | ||
* this field has to do with the running process arch. | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* It corresponds with registers in the stack frame. Specifies the names of the registers for this arch. | ||
* The values are the types. | ||
* | ||
* If you use `string`, you can format the value as you want. | ||
*/ | ||
registers: 'i32' | 'u32' | 'i64' | 'u64' | 'f32' | 'string'; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/sdk-core/src/model/http/model/submit/request/BacktraceSubmitAttributeType.ts
This file contains hidden or 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 @@ | ||
export type BacktraceSubmitAttributeType = string | number | boolean | undefined | null; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.