-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
51 lines (48 loc) · 1.96 KB
/
instrumentation.ts
File metadata and controls
51 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import { SDK_VERSION } from '@sentry/core';
import { type ClickHouseModuleExports,patchClickHouseClient } from './patch';
import type { ClickHouseInstrumentationConfig } from './types';
const PACKAGE_NAME = '@sentry/instrumentation-clickhouse';
const supportedVersions = ['>=0.0.1'];
/**
*
*/
export class ClickHouseInstrumentation extends InstrumentationBase<ClickHouseInstrumentationConfig> {
public constructor(config: ClickHouseInstrumentationConfig = {}) {
super(PACKAGE_NAME, SDK_VERSION, config);
}
/**
*
*/
public override init(): InstrumentationModuleDefinition {
return new InstrumentationNodeModuleDefinition(
'@clickhouse/client',
supportedVersions,
moduleExports =>
patchClickHouseClient(moduleExports as ClickHouseModuleExports, {
wrap: this._wrap.bind(this),
unwrap: this._unwrap.bind(this),
tracer: this.tracer,
getConfig: this.getConfig.bind(this),
isEnabled: this.isEnabled.bind(this),
}),
moduleExports => {
const moduleExportsTyped = moduleExports as ClickHouseModuleExports;
const ClickHouseClient = moduleExportsTyped.ClickHouseClient;
if (ClickHouseClient && typeof ClickHouseClient === 'function' && 'prototype' in ClickHouseClient) {
const ClickHouseClientCtor = ClickHouseClient as new () => {
query: unknown;
insert: unknown;
exec: unknown;
command: unknown;
};
this._unwrap(ClickHouseClientCtor.prototype, 'query');
this._unwrap(ClickHouseClientCtor.prototype, 'insert');
this._unwrap(ClickHouseClientCtor.prototype, 'exec');
this._unwrap(ClickHouseClientCtor.prototype, 'command');
}
},
);
}
}