fix(medusa): Re throw error in instrumentation after reporting it (#11464)

FIXES FRMW-2914

**What**
Currently, when the instrumentation is enabled, some instrument catches the errors in order to set the span status and info, unfortunately, these errors are not re throw leading to swallow them and return nothing in the end leading to potential breaks in flows
This commit is contained in:
Adrien de Peretti
2025-02-14 13:50:52 +01:00
committed by GitHub
parent e769c5afe3
commit ceb99d073a
2 changed files with 38 additions and 21 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Re throw error in instrumentation after reporting it

View File

@@ -148,14 +148,17 @@ export function instrumentRemoteQuery() {
span.setAttributes({
"query.fields": queryOptions.fields,
})
return await queryFn()
.catch((error) => {
span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message,
})
try {
return await queryFn()
} catch (err) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: err.message,
})
.finally(() => span.end())
throw err
} finally {
span.end()
}
}
)
})
@@ -176,14 +179,18 @@ export function instrumentRemoteQuery() {
span.setAttributes({
"query.fields": "fields" in queryOptions ? queryOptions.fields : [],
})
return await queryFn()
.catch((error) => {
span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message,
})
try {
return await queryFn()
} catch (error) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message,
})
.finally(() => span.end())
throw error
} finally {
span.end()
}
}
)
})
@@ -201,14 +208,18 @@ export function instrumentRemoteQuery() {
"fetch.select": options.select,
"fetch.relations": options.relations,
})
return await fetchFn()
.catch((error) => {
span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message,
})
try {
return await fetchFn()
} catch (error) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message,
})
.finally(() => span.end())
throw error
} finally {
span.end()
}
}
)
})
@@ -251,6 +262,7 @@ export function instrumentWorkflows() {
span.setAttribute(`workflow.step.${key}`, value)
})
// TODO: should we report error and re throw it?
return await stepHandler().finally(() => span.end())
}
)