• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / devtools-shared / 14664746835

25 Apr 2025 12:36PM CUT coverage: 72.362% (-0.03%) from 72.39%
14664746835

push

github

mongodb-devtools-bot[bot]
chore(ci): bump packages

1460 of 2285 branches covered (63.89%)

Branch coverage included in aggregate %.

3093 of 4007 relevant lines covered (77.19%)

636.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.88
/packages/devtools-proxy-support/src/logging.ts
1
// Most mongoLogId() calls here come from code that was
2
// previously part of the MongoDB Compass monorepo, hence the specific
3
// values used here; in particular,
4
// https://github.com/mongodb-js/compass/tree/55a5a608713d7316d158dc66febeb6b114d8b40d/packages/ssh-tunnel/src
5

6
interface BaseSocks5RequestMetadata {
7
  srcAddr: string;
8
  srcPort: number;
9
  dstAddr: string;
10
  dstPort: number;
11
}
12

13
export interface ProxyEventMap {
14
  'socks5:authentication-complete': (ev: { success: boolean }) => void;
15
  'socks5:skip-auth-setup': () => void;
16
  'socks5:start-listening': (ev: {
17
    proxyHost: string;
18
    proxyPort: number;
19
  }) => void;
20
  'socks5:forwarding-error': (
21
    ev: { error: string } & Partial<BaseSocks5RequestMetadata>,
22
  ) => void;
23
  'socks5:agent-initialized': () => void;
24
  'socks5:closing-tunnel': () => void;
25
  'socks5:got-forwarding-request': (ev: BaseSocks5RequestMetadata) => void;
26
  'socks5:accepted-forwarding-request': (ev: BaseSocks5RequestMetadata) => void;
27
  'socks5:failed-forwarding-request': (
28
    ev: { error: string } & Partial<BaseSocks5RequestMetadata>,
29
  ) => void;
30
  'socks5:forwarded-socket-closed': (ev: BaseSocks5RequestMetadata) => void;
31

32
  'ssh:client-closed': () => void;
33
  'ssh:establishing-conection': (ev: {
34
    host: string | undefined;
35
    port: number | undefined;
36
    password: boolean;
37
    passphrase: boolean;
38
    privateKey: boolean;
39
  }) => void;
40
  'ssh:failed-connection': (ev: { error: string }) => void;
41
  'ssh:established-connection': () => void;
42
  'ssh:failed-forward': (ev: {
43
    error: string;
44
    host: string;
45
    retryableError: boolean;
46
    retriesLeft: number;
47
  }) => void;
48
}
49

50
export type ProxyEventArgs<K extends keyof ProxyEventMap> =
51
  ProxyEventMap[K] extends (...args: infer P) => any ? P : never;
52

53
export interface ProxyLogEmitter {
54
  // TypeScript uses something like this itself for its EventTarget definitions.
55
  on<K extends keyof ProxyEventMap>(event: K, listener: ProxyEventMap[K]): this;
56
  off?<K extends keyof ProxyEventMap>(
57
    event: K,
58
    listener: ProxyEventMap[K],
59
  ): this;
60
  once<K extends keyof ProxyEventMap>(
61
    event: K,
62
    listener: ProxyEventMap[K],
63
  ): this;
64
  emit<K extends keyof ProxyEventMap>(
65
    event: K,
66
    ...args: ProxyEventArgs<K>
67
  ): unknown;
68
}
69

70
interface MongoLogWriter {
71
  info(c: string, id: unknown, ctx: string, msg: string, attr?: any): void;
72
  warn(c: string, id: unknown, ctx: string, msg: string, attr?: any): void;
73
  error(c: string, id: unknown, ctx: string, msg: string, attr?: any): void;
74
  mongoLogId(this: void, id: number): unknown;
75
}
76

77
let idCounter = 0;
1✔
78
export function hookLogger(
1✔
79
  emitter: ProxyLogEmitter,
80
  log: MongoLogWriter,
81
  logCtx: string,
82
): void {
83
  logCtx = `${logCtx}-${idCounter++}`;
×
84
  const { mongoLogId } = log;
×
85

86
  emitter.on('socks5:authentication-complete', (ev) => {
×
87
    log.info(
×
88
      'DEVTOOLS-PROXY',
89
      mongoLogId(1_001_000_253),
90
      `socks5-${logCtx}`,
91
      'Validated auth parameters',
92
      { ...ev },
93
    );
94
  });
95

96
  emitter.on('socks5:skip-auth-setup', () => {
×
97
    log.info(
×
98
      'DEVTOOLS-PROXY',
99
      mongoLogId(1_001_000_254),
100
      `socks5-${logCtx}`,
101
      'Skipping auth setup',
102
    );
103
  });
104

105
  emitter.on('socks5:start-listening', (ev) => {
×
106
    log.info(
×
107
      'DEVTOOLS-PROXY',
108
      mongoLogId(1_001_000_255),
109
      `socks5-${logCtx}`,
110
      'Listening for Socks5 connections',
111
      { ...ev },
112
    );
113
  });
114

115
  emitter.on('socks5:forwarding-error', (ev) => {
×
116
    log.error(
×
117
      'DEVTOOLS-PROXY',
118
      mongoLogId(1_001_000_259),
119
      `socks5-${logCtx}`,
120
      'Failed to establish new outgoing connection from Socks5 proxy',
121
      { ...ev },
122
    );
123
  });
124

125
  emitter.on('socks5:agent-initialized', () => {
×
126
    log.info(
×
127
      'DEVTOOLS-PROXY',
128
      mongoLogId(1_001_000_259),
129
      `socks5-${logCtx}`,
130
      'Finished initializing agent',
131
    );
132
  });
133

134
  emitter.on('socks5:closing-tunnel', () => {
×
135
    log.info(
×
136
      'DEVTOOLS-PROXY',
137
      mongoLogId(1_001_000_256),
138
      `socks5-${logCtx}`,
139
      'Closing Socks5 tunnel',
140
    );
141
  });
142

143
  emitter.on('socks5:got-forwarding-request', (ev) => {
×
144
    log.info(
×
145
      'DEVTOOLS-PROXY',
146
      mongoLogId(1_001_000_260),
147
      `socks5-${logCtx}`,
148
      'Received Socks5 fowarding request',
149
      { ...ev },
150
    );
151
  });
152

153
  emitter.on('socks5:accepted-forwarding-request', (ev) => {
×
154
    log.info(
×
155
      'DEVTOOLS-PROXY',
156
      mongoLogId(1_001_000_262),
157
      `socks5-${logCtx}`,
158
      'Established outbound connection and accepting socks5 request',
159
      { ...ev },
160
    );
161
  });
162

163
  emitter.on('socks5:failed-forwarding-request', (ev) => {
×
164
    log.error(
×
165
      'DEVTOOLS-PROXY',
166
      mongoLogId(1_001_000_265),
167
      `socks5-${logCtx}`,
168
      'Error establishing outbound connection for socks5 request',
169
      { ...ev },
170
    );
171
  });
172

173
  emitter.on('socks5:forwarded-socket-closed', (ev) => {
×
174
    log.info(
×
175
      'DEVTOOLS-PROXY',
176
      mongoLogId(1_001_000_264),
177
      `socks5-${logCtx}`,
178
      'Socks5 stream socket closed',
179
      { ...ev },
180
    );
181
  });
182

183
  emitter.on('ssh:client-closed', () => {
×
184
    log.info(
×
185
      'DEVTOOLS-PROXY',
186
      mongoLogId(1_001_000_252),
187
      `ssh-${logCtx}`,
188
      'sshClient closed',
189
    );
190
  });
191

192
  emitter.on('ssh:establishing-conection', (ev) => {
×
193
    log.info(
×
194
      'DEVTOOLS-PROXY',
195
      mongoLogId(1_001_000_257),
196
      `ssh-${logCtx}`,
197
      'Establishing new SSH connection',
198
      { ...ev },
199
    );
200
  });
201
  emitter.on('ssh:failed-connection', (ev) => {
×
202
    log.info(
×
203
      'DEVTOOLS-PROXY',
204
      mongoLogId(1_001_000_258),
205
      `ssh-${logCtx}`,
206
      'Failed to establish new SSH connection',
207
      { ...ev },
208
    );
209
  });
210
  emitter.on('ssh:established-connection', () => {
×
211
    log.info(
×
212
      'DEVTOOLS-PROXY',
213
      mongoLogId(1_001_000_259),
214
      `ssh-${logCtx}`,
215
      'Finished establishing new SSH connection',
216
    );
217
  });
218

219
  emitter.on('ssh:failed-forward', (ev) => {
×
220
    log.error(
×
221
      'DEVTOOLS-PROXY',
222
      mongoLogId(1_001_000_261),
223
      `ssh-${logCtx}`,
224
      'Error forwarding outbound SSH connection, potentially retrying',
225
      {
226
        ...ev,
227
      },
228
    );
229
  });
230
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc