Skip to content

Commit 2a10197

Browse files
committed
🔧 fix: type
1 parent 6cac3e6 commit 2a10197

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

src/index.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -517,21 +517,28 @@ export const opentelemetry = ({
517517
if ((rootSpan as any).ended) return
518518

519519
{
520-
let status = context.set.status;
521-
if (typeof status === "string") {
522-
status = StatusMap[status];
523-
} else if (typeof status !== "number" && typeof (error == null ? void 0 : error.status) === "number") {
524-
status = error.status;
525-
}
526-
if (typeof status === "number") {
527-
attributes["http.response.status_code"] = status;
528-
if (status >= 500) {
520+
let status = context.set.status
521+
522+
if (typeof status === 'string') {
523+
status = StatusMap[status]
524+
} else if (
525+
typeof status !== 'number' &&
526+
// @ts-ignore
527+
typeof error?.status === 'number'
528+
)
529+
// @ts-ignore
530+
status = error.status
531+
532+
if (typeof status === 'number') {
533+
attributes['http.response.status_code'] = status
534+
535+
if (status >= 500)
529536
rootSpan.setStatus({
530537
code: SpanStatusCode.ERROR
531-
});
532-
}
538+
})
533539
}
534-
rootSpan.setAttributes(attributes);
540+
541+
rootSpan.setAttributes(attributes)
535542
}
536543

537544
if (
@@ -801,15 +808,19 @@ export const opentelemetry = ({
801808
}
802809
}
803810

804-
if (!rootSpan.ended) {
805-
const statusCode = attributes["http.response.status_code"];
806-
if (typeof statusCode === "number" && statusCode >= 500) {
807-
rootSpan.setStatus({
808-
code: SpanStatusCode.ERROR
809-
});
810-
}
811-
rootSpan.setAttributes(attributes);
811+
if (!(rootSpan as any).ended) {
812+
const statusCode =
813+
attributes['http.response.status_code']
814+
if (
815+
typeof statusCode === 'number' &&
816+
statusCode >= 500
817+
) {
818+
rootSpan.setStatus({
819+
code: SpanStatusCode.ERROR
820+
})
812821
}
822+
rootSpan.setAttributes(attributes)
823+
}
813824
})
814825

815826
onAfterResponse((event) => {
@@ -848,14 +859,19 @@ export const opentelemetry = ({
848859
}
849860
}
850861

851-
if (!rootSpan.ended) {
852-
const statusCode = attributes["http.response.status_code"];
853-
if (typeof statusCode === "number" && statusCode >= 500) {
862+
if (!(rootSpan as any).ended) {
863+
const statusCode =
864+
attributes['http.response.status_code']
865+
866+
if (
867+
typeof statusCode === 'number' &&
868+
statusCode >= 500
869+
)
854870
rootSpan.setStatus({
855871
code: SpanStatusCode.ERROR
856-
});
857-
}
858-
rootSpan.setAttributes(attributes);
872+
})
873+
874+
rootSpan.setAttributes(attributes)
859875
}
860876

861877
event.onStop(() => {

0 commit comments

Comments
 (0)