Skip to content

Commit f89dd18

Browse files
committed
fix: type errors
1 parent acb3909 commit f89dd18

3 files changed

Lines changed: 240 additions & 233 deletions

File tree

lib/src/emitter/proxy-handler/query-executor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** biome-ignore-all lint/suspicious/noExplicitAny: Those any are unknown. It's ok to leave it as is for internal module. */
12
import { PG_EVENT_NAME } from "../../constants.js";
23
import { type DbQueryEvent, getDbEventEmitter } from "../../db-events.js";
34
import type { Logger } from "../../logger.js";

lib/src/instrumentation.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { context, SpanStatusCode, trace, ValueType } from "@opentelemetry/api";
1+
import {
2+
context,
3+
type Counter,
4+
type Histogram,
5+
type Span,
6+
SpanStatusCode,
7+
trace,
8+
ValueType,
9+
} from "@opentelemetry/api";
210
import {
311
InstrumentationBase,
412
type InstrumentationConfig,
@@ -47,10 +55,10 @@ import { analyzeQuery } from "./query-analysis.js";
4755

4856
const LOG_PREFIX = "[POSTGRES-INSTRUMENTATION]";
4957

50-
type ParameterSanitizer = (param: unknown, index: number) => string;
51-
type BeforeSpanHook = (span: any, event: DbQueryEvent) => void;
52-
type AfterSpanHook = (span: any, event: DbQueryEvent) => void;
53-
type ResponseHook = (span: any, result: unknown) => void;
58+
type ParameterSanitizer = (param: unknown) => string;
59+
type BeforeSpanHook = (span: Span, event: DbQueryEvent) => void;
60+
type AfterSpanHook = (span: Span, event: DbQueryEvent) => void;
61+
type ResponseHook = (span: Span, result: unknown) => void;
5462

5563
export interface PostgresInstrumentationConfig extends InstrumentationConfig {
5664
serviceName?: string;
@@ -81,11 +89,11 @@ export class PostgresInstrumentation extends InstrumentationBase {
8189
private beforeSpan?: BeforeSpanHook;
8290
private afterSpan?: AfterSpanHook;
8391
private responseHook?: ResponseHook;
84-
private queryDurationHistogram: any;
85-
private queryCounter: any;
86-
private errorCounter: any;
87-
private connectionCounter: any;
88-
private connectionDurationHistogram: any;
92+
private queryDurationHistogram: Histogram | undefined;
93+
private queryCounter: Counter | undefined;
94+
private errorCounter: Counter | undefined;
95+
private connectionCounter: Counter | undefined;
96+
private connectionDurationHistogram: Histogram | undefined;
8997
private connectionStartTimes: Map<string, number> = new Map();
9098

9199
constructor(config: PostgresInstrumentationConfig = {}) {
@@ -218,10 +226,7 @@ export class PostgresInstrumentation extends InstrumentationBase {
218226
this.listener = (event: DbQueryEvent) => {
219227
this.handleQueryEvent(event);
220228
};
221-
getDbEventEmitter(this.customLogger).on(
222-
PG_EVENT_NAME,
223-
this.listener as any,
224-
);
229+
getDbEventEmitter(this.customLogger).on(PG_EVENT_NAME, this.listener);
225230

226231
// Add connection event listener
227232
getDbEventEmitter(this.customLogger).on(
@@ -234,10 +239,7 @@ export class PostgresInstrumentation extends InstrumentationBase {
234239

235240
private removeEventListeners(): void {
236241
if (this.listener) {
237-
getDbEventEmitter(this.customLogger).off(
238-
PG_EVENT_NAME,
239-
this.listener as any,
240-
);
242+
getDbEventEmitter(this.customLogger).off(PG_EVENT_NAME, this.listener);
241243
this.listener = undefined;
242244
}
243245
}
@@ -354,17 +356,17 @@ export class PostgresInstrumentation extends InstrumentationBase {
354356
return sql.replace(/password\s*=\s*['"][^'"]*['"]/gi, "password=***");
355357
}
356358

357-
private addQueryParameters(span: any, params: unknown[]): void {
359+
private addQueryParameters(span: Span, params: unknown[]): void {
358360
params.forEach((param, index) => {
359361
const paramKey = `${PG_DB_QUERY_PARAMETER_PREFIX}${index}`;
360-
const paramValue = this.parameterSanitizer(param, index);
362+
const paramValue = this.parameterSanitizer(param);
361363
span.setAttribute(paramKey, paramValue);
362364
});
363365
}
364366

365-
private defaultParameterSanitizer(param: unknown, index: number): string {
367+
private defaultParameterSanitizer(param: unknown): string {
366368
if (typeof param === "string" && param.length > 100) {
367-
return param.substring(0, 100) + "...";
369+
return `${param.substring(0, 100)}...`;
368370
}
369371
// Redact common sensitive fields
370372
if (typeof param === "string" && /password|token|secret/i.test(param)) {

0 commit comments

Comments
 (0)