-
Notifications
You must be signed in to change notification settings - Fork 57
feat: Create Logging Service SDKE-511 #1123
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
base: blackout2025
Are you sure you want to change the base?
Conversation
… up imports in reportingLogger
… window for location and ROKT_DOMAIN
…locker parameter from related functions
…Uploader and XHRUploader
…proved type safety
… and update tests for new rate limiting behavior
…d update related tests
…n apiClient tests for improved compatibility
…rtingLogger for better encapsulation and update related tests
…uctor to accept accountId, with corresponding test adjustments
| @@ -0,0 +1,5 @@ | |||
| export type ErrorCodes = (typeof ErrorCodes)[keyof typeof ErrorCodes]; | |||
|
|
|||
| export const ErrorCodes = { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be ErrorMessages. ErrorCodes sounds like they'd be something numerical like HTTP Error Codes (404, 429, etc).
Are you naming this ErrorMessages because that's something defined on the server side?
| @@ -0,0 +1,21 @@ | |||
| import { ErrorCodes } from "./errorCodes"; | |||
|
|
|||
| export enum LogRequestSeverity { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a type for LogLevelType. Is there any way we can consolidate these into one thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep them separated because these ones depends on the API contract.
| [LogRequestSeverity.Error, 10], | ||
| [LogRequestSeverity.Warning, 10], | ||
| [LogRequestSeverity.Info, 10], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If each of these default to 10, should we just make this a constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to discuss if these amounts are good amount first. @mattbodle @rmi22186 what do you think about these limits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the same rate limits and logic from WSDK?
|
|
||
| public incrementAndCheck(severity: LogRequestSeverity): boolean { | ||
| const count = this.logCount.get(severity) || 0; | ||
| const limit = this.rateLimits.get(severity) || 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want 10 to be the default rate limit, we can then reuse a constant here.
src/logging/reportingLogger.ts
Outdated
| } | ||
|
|
||
| private getUrl(): string { | ||
| return window.location.href; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In these cases where you're using window, you should first check if window exists, especially if this module is going to log errors that are independent of the SDK itself.
We've had problems in the past of customers and partners using the Web SDK server side and window will not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added null conditional operator
src/logging/reportingLogger.ts
Outdated
| headers: { | ||
| Accept: 'text/plain;charset=UTF-8', | ||
| 'Content-Type': 'text/plain;charset=UTF-8', | ||
| 'rokt-account-id': this.accountId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens here if accountId is undefined or null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added default value 0, which is the same behavior from rokt wsdk.
test/jest/reportingLogger.spec.ts
Outdated
| global.fetch = mockFetch; | ||
|
|
||
| mpInstance = { | ||
| _Helpers: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be future work but if it's easy enough, we should rewrite createServiceUrl so that it isn't as tightly coupled to the full SDK instance or Store, or make it a function within Store.
If it's future work, we should collect some of these refactors into a launch pad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed mpInstance
…tion with valueof utility and update ReportingLogger to use baseUrl; adjust tests accordingly
…in ReportingLogger, with corresponding tests for fallback behavior
…responding test expectation
|
| return window. | ||
| mParticle?. | ||
| config?. | ||
| isWebSdkLoggingEnabled ?? false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should pass this in as a param in the constructor so that we're not tightly coupled to the window.
|
|
||
| private isDebugModeEnabled(): boolean { | ||
| return ( | ||
| window. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. We should not be tightly coupled to the window. There should be a utility method to get url params.
| private readonly rateLimiter: IRateLimiter; | ||
| private readonly DEFAULT_ACCOUNT_ID: string = '0'; | ||
| private readonly DEFAULT_USER_AGENT: string = 'no-user-agent-set'; | ||
| private readonly DEFAULT_URL: string = 'no-url-set'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add rokt-launcher-instance-guid as a default header
| Info = 'info', | ||
| } | ||
|
|
||
| export interface LogRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy the exact types from WSDK:
export type WSDKErrorSeverity = (typeof WSDKErrorSeverity)[keyof typeof WSDKErrorSeverity];
export const WSDKErrorSeverity = {
ERROR: 'ERROR',
INFO: 'INFO',
WARNING: 'WARNING',
} as const;
export interface IWSDKError {
name: string;
message: string;
stack?: string;
code?: ErrorCode;
reporter?: string;
integration?: string;
severity?: WSDKErrorSeverity;
additionalInformation?: Record<string, string>;
handled?: boolean;
}
| private readonly reporter: string = 'mp-wsdk'; | ||
| private readonly integration: string = 'mp-wsdk'; | ||
| private readonly rateLimiter: IRateLimiter; | ||
| private readonly DEFAULT_ACCOUNT_ID: string = '0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to set default, do not add account id header if it doesn't exist
| private readonly integration: string = 'mp-wsdk'; | ||
| private readonly rateLimiter: IRateLimiter; | ||
| private readonly DEFAULT_ACCOUNT_ID: string = '0'; | ||
| private readonly DEFAULT_USER_AGENT: string = 'no-user-agent-set'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required??
| private readonly rateLimiter: IRateLimiter; | ||
| private readonly DEFAULT_ACCOUNT_ID: string = '0'; | ||
| private readonly DEFAULT_USER_AGENT: string = 'no-user-agent-set'; | ||
| private readonly DEFAULT_URL: string = 'no-url-set'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? When do we not get a href?
| } | ||
|
|
||
| public error(msg: string, code?: ErrorCodes, stackTrace?: string) { | ||
| this.sendLog(LogRequestSeverity.Error, msg, code ?? ErrorCodes.UNHANDLED_EXCEPTION, stackTrace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make code a mandatory parameter?
UNHANDLED_EXCEPTION is a code we specifically use when an error escapes any catch clause and is receeived by the window
| const logRequest: LogRequest = { | ||
| additionalInformation: { | ||
| message: msg, | ||
| version: this.sdkVersion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should version be here?
| code: code, | ||
| url: this.getUrl(), | ||
| deviceInfo: this.getUserAgent(), | ||
| stackTrace: stackTrace ?? '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stacktrace or stack?
4cc5aa8 to
c48930e
Compare



Background
This PR introduces a new server-side logging service that enables the mParticle Web SDK to send error and warning logs to mParticle's backend for improved monitoring and debugging. The implementation includes creating a new
ReportingLoggerservice that can send logs to the server when enabled.Important: Next PR will include the reporting service call from Logger.tsWhat Has Changed
Major Features
Technical Highlights
Screenshots/Video
Checklist
Additional Notes
Reference Issue (For employees only. Ignore if you are an outside contributor)