Skip to content

Commit

Permalink
fix: ✨ improve logs for distributor assets
Browse files Browse the repository at this point in the history
  • Loading branch information
ignazio-bovo authored and WRadoslaw committed Mar 13, 2024
1 parent 1649aa3 commit 7cefcff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/atlas/src/hooks/useGetAssetUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const getSingleAssetUrl = async (
dataObjectId: id,
dataObjectType: type || undefined,
resolvedUrl: distributionAssetUrl,
// https://mrbovo.distributor.cc/distributor/api/v1/assets/48451 -> regexp match for https://mrbovo.distributor.cc
distributorUrl: distributionAssetUrl.match(/https?:\/\/[^/]+/)?.[0] ?? undefined,
}
const [assetTestPromise, cleanup] = testAssetDownload(distributionAssetUrl, type, opts)
const assetTestPromiseWithTimeout = withTimeout(
Expand Down
2 changes: 1 addition & 1 deletion packages/atlas/src/providers/uploads/uploads.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const useStartFileUpload = () => {

// only retry on Axios error, otherwise code is to blame
if (networkFailure) {
UserEventsLogger.logDistributorError({ dataObjectId: asset.id, storageOperatorId: uploadOperator.id }, e)
UserEventsLogger.logUploadError({ dataObjectId: asset.id, storageOperatorId: uploadOperator.id }, e)

markStorageOperatorFailed(uploadOperator.id)
const retry = opts?.retry ?? 0
Expand Down
19 changes: 16 additions & 3 deletions packages/atlas/src/utils/logs/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ type UserLogEvent = {
[x: string]: unknown
}

export type DistributorEventEntry = {
export type DataObjectEventEntry = {
dataObjectId?: string | null
dataObjectType?: DataObjectType['__typename'] | AssetType
resolvedUrl?: string
} & StorageOperatorEventDetails
}

export type StorageOperatorEventEntry = DataObjectEventEntry & StorageOperatorEventDetails

export type DistributorEventEntry = DataObjectEventEntry & DistributorEventDetails

type CodecInfo = {
assetType: string | null
Expand Down Expand Up @@ -149,6 +153,15 @@ class _UserEventsLogger {
this.addErrorEvent(event)
}

logUploadError(entry: StorageOperatorEventEntry, error: Error) {
const event: UserLogEvent = {
type: 'distributor-response-error',
...entry,
error: error.message,
}
this.addErrorEvent(event)
}

logDistributorResponseTimeout(entry: DistributorEventEntry) {
const event: UserPerformanceEvent = {
type: 'distributor-response-timeout',
Expand Down Expand Up @@ -182,7 +195,7 @@ class _UserEventsLogger {
this.addErrorEvent(event)
}

logAssetUploadFailedEvent(entry: DistributorEventEntry, error: Error) {
logAssetUploadFailedEvent(entry: StorageOperatorEventEntry, error: Error) {
const event: UserLogEvent = {
type: 'asset-upload-failed',
...entry,
Expand Down

0 comments on commit 7cefcff

Please sign in to comment.