Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit d40a1b2

Browse files
authored
fix(instrumentation-sequelize): handle query call without options (#139)
1 parent 0eb9c76 commit d40a1b2

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

packages/instrumentation-sequelize/src/sequelize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class SequelizeInstrumentation extends InstrumentationBase<typeof sequeli
9797
}
9898

9999
let statement = sql?.query ? sql.query : sql;
100-
let operation = option.type;
100+
let operation = option?.type;
101101

102102
if (typeof statement === 'string') {
103103
statement = statement.trim();

packages/instrumentation-sequelize/test/sequelize.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,49 @@ describe('instrumentation-sequelize', () => {
225225
'SELECT `id`, `firstName`, `createdAt`, `updatedAt` FROM `Users` AS `User`;'
226226
);
227227
});
228+
229+
describe('query is instrumented', () => {
230+
it('with options not specified', async () => {
231+
try {
232+
await instance.query('SELECT 1 + 1');
233+
} catch {
234+
// Do not care about the error
235+
}
236+
const spans = getSequelizeSpans();
237+
expect(spans.length).toBe(1);
238+
const attributes = spans[0].attributes;
239+
240+
expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT');
241+
expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe('SELECT 1 + 1');
242+
});
243+
it('with type not specified in options', async () => {
244+
try {
245+
await instance.query('SELECT 1 + 1', {});
246+
} catch {
247+
// Do not care about the error
248+
}
249+
const spans = getSequelizeSpans();
250+
expect(spans.length).toBe(1);
251+
const attributes = spans[0].attributes;
252+
253+
expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT');
254+
expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe('SELECT 1 + 1');
255+
});
256+
257+
it('with type specified in options', async () => {
258+
try {
259+
await instance.query('SELECT 1 + 1', { type: sequelize.QueryTypes.RAW });
260+
} catch {
261+
// Do not care about the error
262+
}
263+
const spans = getSequelizeSpans();
264+
expect(spans.length).toBe(1);
265+
const attributes = spans[0].attributes;
266+
267+
expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('RAW');
268+
expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe('SELECT 1 + 1');
269+
});
270+
});
228271
});
229272

230273
describe('sqlite', () => {

0 commit comments

Comments
 (0)