Skip to content

Commit 81e4ee5

Browse files
fix: tables compare (#79)
1 parent b765cc9 commit 81e4ee5

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

packages/expect-opentelemetry/src/matchers/utils/filters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { CompareOptions } from './compare-types';
44

55
export const extractAttributeStringValues = (
66
spans: opentelemetry.proto.trace.v1.ISpan[],
7-
attribute: string,
8-
) => {
7+
expected: string,
8+
): string[] => {
99
return spans
1010
.map((span) => {
1111
return span.attributes?.find(
1212
(attribute: opentelemetry.proto.common.v1.IKeyValue) =>
13-
attribute.key === attribute,
13+
attribute.key === expected,
1414
)?.value?.stringValue;
1515
})
1616
.filter((statement) => !!statement) as string[];

packages/expect-opentelemetry/src/resources/postgresql-query.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export class PostgreSQLQuery {
2424

2525
if (filteredSpans.length === 0) {
2626
throw new Error(
27-
`No query by ${this.serviceName} to postgresql with database name ${name} was found`,
27+
`No query by ${
28+
this.serviceName
29+
} to postgresql with database name ${name} was found. Found db names: ${extractAttributeStringValues(
30+
this.spans,
31+
SemanticAttributes.DB_NAME,
32+
)}`,
2833
);
2934
}
3035

@@ -43,10 +48,10 @@ export class PostgreSQLQuery {
4348
throw new Error(
4449
`No query by ${
4550
this.serviceName
46-
} to postgresql with statement ${statement} was found. Found statements: ${extractAttributeStringValues(
51+
} to postgresql with statement ${statement} was found. Found statements:\n ${extractAttributeStringValues(
4752
this.spans,
4853
SemanticAttributes.DB_STATEMENT,
49-
)}`,
54+
).join('\n\n')}`,
5055
);
5156
}
5257

@@ -78,7 +83,7 @@ export class PostgreSQLQuery {
7883
} to postgresql with operations ${operations} was found. Found statements: ${extractAttributeStringValues(
7984
this.spans,
8085
SemanticAttributes.DB_STATEMENT,
81-
)}`,
86+
).join('\n\n')}`,
8287
);
8388
}
8489

@@ -100,10 +105,10 @@ export class PostgreSQLQuery {
100105
const cleaned = matches?.map((elem: string) => {
101106
const [_, second] = elem.split(' ');
102107
return second
103-
.replace('"', '')
104-
.replace('(', '')
105-
.replace(')', '')
106-
.replace('\n', '')
108+
.replaceAll('"', '')
109+
.replaceAll('(', '')
110+
.replaceAll(')', '')
111+
.replaceAll('\n', '')
107112
.toLocaleLowerCase();
108113
});
109114

@@ -119,7 +124,7 @@ export class PostgreSQLQuery {
119124
} to postgresql with tables ${tables} was found. Found statements: ${extractAttributeStringValues(
120125
this.spans,
121126
SemanticAttributes.DB_STATEMENT,
122-
)}`,
127+
).join('\n\n')}`,
123128
);
124129
}
125130

0 commit comments

Comments
 (0)