ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / agentHost / test / node / otel / agentHostOTelService.integrationTest.ts 498 строк · изменён 14 нояб., 04:52
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
import { deepStrictEqual, notStrictEqual, ok, strictEqual } from 'assert' ;
import { mkdtemp, rm } from 'fs/promises' ;
import type * as http from 'http' ;
import { tmpdir } from 'os' ;
import { join } from '../../../../../base/common/path.js' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js' ;
import { INativeEnvironmentService } from '../../../../environment/common/environment.js'
TestInstantiationService
ILogService NullLogService
OTelSqliteStore
IOtlpExportTraceServiceRequest
OtlpSpanKind
AgentHostSessionTitleAttribute AgentHostSessionTitleSpanName AgentHostSessionUriAttribute IAgentHostOTelService
AgentHostOTelService normalizeAgentHostOtlpBody readAgentHostOTelEnv
AgentHostOTelSpansDbSubPath
statusCode
body
endpoint payload object IPostResponse
httpModule
url endpoint
body Buffer payload
resolve reject
req http ClientRequest httpModule
host url hostname
port url port
method
path
headers
body length
req res
chunks Buffer
res chunk Buffer chunks chunk
res
statusCode res statusCode
body Buffer chunks
res reject
req reject
req body
req
traceId spanId IOtlpExportTraceServiceRequest
nowNs
endNs
resourceSpans
resource
attributes
key value stringValue
scopeSpans
scope name
spans
traceId
spanId
name
kind OtlpSpanKind
startTimeUnixNano nowNs
endTimeUnixNano endNs
attributes
key value stringValue
key value stringValue
key value stringValue
key value stringValue
key value stringValue
key
ISavedEnv
saved ISavedEnv
key
saved key process env key
process env key
saved
saved ISavedEnv
key value Object saved
value
process env key
process env key value
userDataPath INativeEnvironmentService
env Partial INativeEnvironmentService _serviceBrand userDataPath
env INativeEnvironmentService
store
cfg
cfg enabled
cfg dbSpanExporter
cfg exporterType
cfg
cfg enabled
cfg dbSpanExporter
protocol
cfg
protocol
cfg exporterType
cfg
headers cfg headers resourceAttributes cfg resourceAttributes
headers authorization
resourceAttributes
custom
payload
resourceSpans
resource
attributes
key value stringValue
key value stringValue
key value stringValue
scopeSpans
spans
name attributes key value stringValue
name attributes key value stringValue
name attributes
spans
spans name attributes key value stringValue
resource attributes key value stringValue
scopeSpans spans name attributes key value stringValue
resource attributes key value stringValue scopeSpans
normalized Buffer payload
result normalized body payload
normalized filteredSpanCount
result resourceSpans scopeSpans spans span span name
result resourceSpans scopeSpans spans
result resourceSpans scopeSpans spans
result resourceSpans scopeSpans spans length
result resourceSpans resource attributes attribute attribute key attribute value stringValue
result resourceSpans resourceSpan resourceSpan resource attributes attribute attribute key attribute value stringValue
saved
tmp
store tmp recursive force
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
di IAgentHostOTelService svc
svc
svc
saved
saved
process env
process env
process env
process env
tmp
store tmp recursive force
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
cfg svc
cfg
cfg exporterType
cfg sourceName
cfg captureContent
svc
saved
saved
protocol
process env
process env
process env protocol
tmp
store tmp recursive force
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
config svc
config external protocol protocol protocol
svc
saved
saved
process env
process env
di store
di ILogService
di INativeEnvironmentService
svc store di AgentHostOTelService
first svc
svc first
svc
svc first
saved
saved
tmp
store tmp recursive force
process env
process env
process env
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
config svc
config traces endpoint
config traces protocol
config external endpoint protocol
config resourceAttributes
context svc
context
context traceparent
svc context svc context
svc
saved
saved
tmp
tmp recursive force
process env
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
cfg svc
cfg
cfg exporterType
cfg otlpEndpoint
dbPath svc
dbPath
dbPath fsPath AgentHostOTelSpansDbSubPath
traceId
spanIdA
spanIdB
res1 cfg otlpEndpoint traceId spanIdA
res1 statusCode
res2 cfg otlpEndpoint traceId spanIdB
res2 statusCode
svc
cfg2 svc
cfg2 otlpEndpoint cfg otlpEndpoint
reader dbPath fsPath
persisted reader traceId
persisted length
names persisted s s name
names
operationNames persisted s s operation_name
operationNames op op
persisted request_model
reader
saved
saved
tmp
tmp recursive force
process env
process env
process env
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
svc
svc
svc
dbPath svc
dbPath
reader dbPath fsPath
spans reader
spans length
titleSpan spans span span name AgentHostSessionTitleSpanName
titleSpan
reader titleSpan span_id AgentHostSessionTitleAttribute length
reader titleSpan span_id AgentHostSessionUriAttribute
reader titleSpan span_id
reader titleSpan span_id
reader
saved
saved
protocol
process env
process env protocol
process env
process env protocol
fetchCalls
tmp
store tmp recursive force
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
fetchCalls
status
config svc
res config otlpEndpoint
res statusCode
svc
fetchCalls
saved
saved
tmp
tmp recursive force
process env
process env
process env
di store
di ILogService
di INativeEnvironmentService tmp
svc store di AgentHostOTelService
cfg svc
cfg otlpEndpoint
cfg otlpEndpoint process env
traceId
res cfg otlpEndpoint traceId
res statusCode
svc
saved
;
import
{
}
from
'../../../../instantiation/test/common/instantiationServiceMock.js'
;
import
{
,
}
from
'../../../../log/common/log.js'
;
import
{
}
from
'../../../../otel/node/sqlite/otelSqliteStore.js'
;
import
{
OTLP_TRACES_PATH
}
from
'../../../../otel/node/otlp/localOtlpReceiver.js'
;
import
{
,
,
}
from
'../../../../otel/node/otlp/otlpJsonTypes.js'
;
import
{
,
,
,
}
from
'../../../common/otel/agentHostOTelService.js'
;
import
{
,
,
}
from
'../../../node/otel/agentHostOTelService.js'
;
import
{
}
from
'../../../common/agentService.js'
;
interface
IPostResponse
{
:
number
;
:
string
;
}
async
function
postOtlp
(
:
string
,
:
)
:
Promise
<
>
{
const
=
await
import
(
'http'
)
;
const
=
new
URL
(
)
;
const
=
.
from
(
JSON
.
stringify
(
)
,
'utf8'
)
;
return
new
Promise < IPostResponse>
(
(
,
)
=>
{
const
:
.
=
.
request
(
{
:
.
,
:
Number
(
.
)
,
:
'POST'
,
:
OTLP_TRACES_PATH
,
:
{
'content-type'
:
'application/json'
,
'content-length'
:
String
(
.
)
,
}
,
}
)
;
.
on
(
'response'
,
=>
{
const
:
[
]
=
[
]
;
.
on
(
'data'
,
(
:
)
=>
.
push
(
)
)
;
.
on
(
'end'
,
(
)
=>
resolve
(
{
:
.
??
0
,
:
.
concat
(
)
.
toString
(
'utf8'
)
,
}
)
)
;
.
on
(
'error'
,
)
;
}
)
;
.
on
(
'error'
,
)
;
.
write
(
)
;
.
end
(
)
;
}
)
;
}
function
makeOtlpRequest
(
:
string
,
:
string
)
:
{
const
=
` ${ Date. now ( ) } 000000 `
;
const
=
` ${ Date. now ( ) + 500 } 000000 `
;
return
{
:
[
{
:
{
:
[
{
:
'service.name'
,
:
{
:
'agent-host-test'
}
}
,
]
,
}
,
:
[
{
:
{
:
'github.copilot.agent'
}
,
:
[
{
,
,
:
'invoke_agent copilotcli'
,
:
.
INTERNAL
,
:
,
:
,
:
[
{
:
'gen_ai.operation.name'
,
:
{
:
'invoke_agent'
}
}
,
{
:
'gen_ai.provider.name'
,
:
{
:
'github.copilot'
}
}
,
{
:
'gen_ai.agent.name'
,
:
{
:
'copilotcli'
}
}
,
{
:
'gen_ai.conversation.id'
,
:
{
:
'conv-1'
}
}
,
{
:
'gen_ai.request.model'
,
:
{
:
'gpt-4o'
}
}
,
]
,
}
]
,
}
]
,
}
]
,
}
;
}
interface
ISavedEnv
{
[
:
string
]
:
string
|
undefined
;
}
const
OTEL_ENV_KEYS
=
[
'COPILOT_OTEL_ENABLED'
,
'COPILOT_OTEL_DB_SPAN_EXPORTER_ENABLED'
,
'COPILOT_OTEL_EXPORTER_TYPE'
,
'COPILOT_OTEL_ENDPOINT'
,
'COPILOT_OTEL_FILE_EXPORTER_PATH'
,
'COPILOT_OTEL_SOURCE_NAME'
,
'COPILOT_OTEL_PROTOCOL'
,
'OTEL_EXPORTER_OTLP_ENDPOINT'
,
'OTEL_EXPORTER_OTLP_PROTOCOL'
,
'OTEL_EXPORTER_OTLP_HEADERS'
,
'OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT'
,
'OTEL_RESOURCE_ATTRIBUTES'
,
'OTEL_SERVICE_NAME'
,
]
as
const
;
function
saveEnv
(
)
:
{
const
:
=
{
}
;
for
(
const
of
OTEL_ENV_KEYS
)
{
[
]
=
.
[
]
;
delete
.
[
]
;
}
return
;
}
function
restoreEnv
(
:
)
:
void
{
for
(
const
[
,
]
of
.
entries
(
)
)
{
if
(
===
undefined
)
{
delete
.
[
]
;
}
else
{
.
[
]
=
;
}
}
}
function
makeEnvService
(
:
string
)
:
{
const
:
<
>
=
{
:
undefined
,
}
;
return
as
;
}
suite
(
'platform/agentHost - AgentHostOTelService (integration)'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'readAgentHostOTelEnv: disabled when no relevant env vars are set'
,
(
)
=>
{
const
=
readAgentHostOTelEnv
(
{
}
)
;
strictEqual
(
.
,
false
)
;
strictEqual
(
.
,
false
)
;
strictEqual
(
.
,
'otlp-http'
)
;
}
)
;
test
(
'readAgentHostOTelEnv: db mode implies enabled'
,
(
)
=>
{
const
=
readAgentHostOTelEnv
(
{
COPILOT_OTEL_DB_SPAN_EXPORTER_ENABLED
:
'true'
}
)
;
strictEqual
(
.
,
true
)
;
strictEqual
(
.
,
true
)
;
}
)
;
test
(
'readAgentHostOTelEnv: grpc aliases select the gRPC exporter type'
,
(
)
=>
{
for
(
const
of
[
'grpc'
,
'http/grpc'
]
)
{
const
=
readAgentHostOTelEnv
(
{
COPILOT_OTEL_ENABLED
:
'true'
,
COPILOT_OTEL_EXPORTER_TYPE
:
'otlp-http'
,
OTEL_EXPORTER_OTLP_PROTOCOL
:
,
}
)
;
strictEqual
(
.
,
'otlp-grpc'
)
;
}
}
)
;
test
(
'readAgentHostOTelEnv: parses headers and resource attributes'
,
(
)
=>
{
const
=
readAgentHostOTelEnv
(
{
COPILOT_OTEL_ENABLED
:
'true'
,
OTEL_EXPORTER_OTLP_HEADERS
:
'authorization=Bearer%20xyz,x-tenant=acme%2Fprod'
,
OTEL_RESOURCE_ATTRIBUTES
:
'deployment.environment.name=dev,custom=value%20with%20spaces,service.name=ignored,service.namespace=foreign'
,
OTEL_SERVICE_NAME
:
'agent-host'
,
}
)
;
deepStrictEqual
(
{
:
.
,
:
.
}
,
{
:
{
:
'Bearer xyz'
,
'x-tenant'
:
'acme/prod'
}
,
:
{
'deployment.environment.name'
:
'dev'
,
:
'value with spaces'
,
'service.name'
:
'agent-host'
,
'service.namespace'
:
'vscode.agent-host'
,
}
,
}
)
;
}
)
;
test
(
'normalizes resources and narrowly filters Codex 0.142 auth polling spans'
,
(
)
=>
{
const
=
{
:
[
{
:
{
:
[
{
:
'service.name'
,
:
{
:
'codex-app-server'
}
}
,
{
:
'service.namespace'
,
:
{
:
'foreign'
}
}
,
{
:
'deployment.environment.name'
,
:
{
:
'test'
}
}
,
]
}
,
:
[
{
:
[
{
:
'auth'
,
:
[
{
:
'code.module.name'
,
:
{
:
'codex_login::auth::manager'
}
}
]
}
,
{
:
'auth'
,
:
[
{
:
'code.module.name'
,
:
{
:
'other::module'
}
}
]
}
,
{
:
'list_models'
,
:
[
]
}
,
]
}
,
{
:
[
]
}
,
{
:
[
{
:
'auth'
,
:
[
{
:
'code.module.name'
,
:
{
:
'codex_login::auth::manager'
}
}
]
}
]
}
,
]
,
}
,
{
:
{
:
[
{
:
'service.name'
,
:
{
:
'another-service'
}
}
]
}
,
:
[
{
:
[
{
:
'auth'
,
:
[
{
:
'code.module.name'
,
:
{
:
'codex_login::auth::manager'
}
}
]
}
]
}
]
,
}
,
{
:
{
:
[
{
:
'custom'
,
:
{
:
'kept'
}
}
]
}
,
:
[
]
}
,
]
,
}
;
const
=
normalizeAgentHostOtlpBody
(
.
from
(
JSON
.
stringify
(
)
)
)
;
const
=
JSON
.
parse
(
.
.
toString
(
'utf8'
)
)
as
typeof
;
strictEqual
(
.
,
2
)
;
deepStrictEqual
(
.
[
0
]
.
[
0
]
.
.
map
(
=>
.
)
,
[
'auth'
,
'list_models'
]
)
;
deepStrictEqual
(
.
[
0
]
.
[
1
]
.
,
[
]
)
;
deepStrictEqual
(
.
[
0
]
.
[
2
]
.
,
[
]
)
;
strictEqual
(
.
[
1
]
.
[
0
]
.
.
,
1
)
;
ok
(
.
[
0
]
.
.
.
some
(
=>
.
===
'deployment.environment.name'
&&
.
.
===
'test'
)
)
;
ok
(
.
.
every
(
=>
.
.
.
some
(
=>
.
===
'service.namespace'
&&
.
.
===
'vscode.agent-host'
)
)
)
;
}
)
;
test
(
'getSdkTelemetryConfig: returns undefined when fully disabled'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
try
{
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
.
add
(
{
dispose
:
(
)
=>
void
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
}
)
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
.
set
(
,
)
;
strictEqual
(
await
.
getSdkTelemetryConfig
(
)
,
undefined
)
;
strictEqual
(
.
getSpansDbPath
(
)
,
undefined
)
;
}
finally
{
restoreEnv
(
)
;
}
}
)
;
test
(
'getSdkTelemetryConfig: pass-through mode returns user-configured exporter settings'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
try
{
.
.
COPILOT_OTEL_ENABLED
=
'true'
;
.
.
COPILOT_OTEL_EXPORTER_TYPE
=
'console'
;
.
.
COPILOT_OTEL_SOURCE_NAME
=
'agent-host'
;
.
.
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT
=
'true'
;
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
.
add
(
{
dispose
:
(
)
=>
void
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
}
)
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
const
=
await
.
getSdkTelemetryConfig
(
)
;
ok
(
,
'expected a TelemetryConfig'
)
;
strictEqual
(
!
.
,
'console'
)
;
strictEqual
(
!
.
,
'agent-host'
)
;
strictEqual
(
!
.
,
true
)
;
strictEqual
(
.
getSpansDbPath
(
)
,
undefined
)
;
}
finally
{
restoreEnv
(
)
;
}
}
)
;
test
(
'external-only unsupported synthetic protocols do not propagate a missing anchor'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
try
{
for
(
const
of
[
'http/protobuf'
,
'grpc'
,
'http/grpc'
]
)
{
.
.
COPILOT_OTEL_ENABLED
=
'true'
;
.
.
OTEL_EXPORTER_OTLP_ENDPOINT
=
'http://collector:4318'
;
.
.
OTEL_EXPORTER_OTLP_PROTOCOL
=
;
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
.
add
(
{
dispose
:
(
)
=>
void
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
}
)
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
const
=
await
.
getNativeSdkTelemetryConfig
(
)
;
strictEqual
(
?.
?.
,
===
'http/grpc'
?
'grpc'
:
)
;
strictEqual
(
.
getSessionTraceContext
(
'conversation'
,
` claude:/ ${ protocol} `
)
,
undefined
)
;
}
}
finally
{
restoreEnv
(
)
;
}
}
)
;
test
(
'session trace contexts are stable until permanent release'
,
(
)
=>
{
const
=
saveEnv
(
)
;
try
{
.
.
COPILOT_OTEL_ENABLED
=
'true'
;
.
.
COPILOT_OTEL_EXPORTER_TYPE
=
'console'
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
tmpdir
(
)
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
const
=
.
getSessionTraceContext
(
'conversation'
,
'claude:/conversation'
)
;
strictEqual
(
.
getSessionTraceContext
(
'conversation'
,
'claude:/conversation'
)
,
)
;
.
releaseSessionTraceContext
(
'claude:/conversation'
)
;
notStrictEqual
(
.
getSessionTraceContext
(
'conversation'
,
'claude:/conversation'
)
,
)
;
}
finally
{
restoreEnv
(
)
;
}
}
)
;
test
(
'native SDK config splits DB traces from direct external signals'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
.
add
(
{
dispose
:
(
)
=>
void
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
}
)
;
try
{
.
.
COPILOT_OTEL_DB_SPAN_EXPORTER_ENABLED
=
'true'
;
.
.
OTEL_EXPORTER_OTLP_ENDPOINT
=
'http://collector:4318'
;
.
.
OTEL_EXPORTER_OTLP_PROTOCOL
=
'http/protobuf'
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
const
=
await
.
getNativeSdkTelemetryConfig
(
)
;
ok
(
?.
?.
.
startsWith
(
'http://127.0.0.1:'
)
)
;
strictEqual
(
?.
?.
,
'http/json'
)
;
deepStrictEqual
(
?.
,
{
:
'http://collector:4318'
,
:
'http/protobuf'
}
)
;
deepStrictEqual
(
?.
,
{
'service.namespace'
:
'vscode.agent-host'
}
)
;
const
=
.
getSessionTraceContext
(
'conversation'
,
'claude:/conversation'
)
;
ok
(
)
;
strictEqual
(
.
,
` 00- ${ context. traceId} - ${ context. spanId} -01 `
)
;
strictEqual
(
.
withTraceContext
(
,
(
)
=>
.
getCurrentTraceContext
(
)
)
,
)
;
strictEqual
(
.
getCurrentTraceContext
(
)
,
undefined
)
;
}
finally
{
restoreEnv
(
)
;
}
}
)
;
test
(
'DB mode: starts loopback, persists posted spans to SQLite, and exposes db path'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
const
cleanup
=
(
)
=>
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
;
try
{
.
.
COPILOT_OTEL_DB_SPAN_EXPORTER_ENABLED
=
'true'
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
const
=
await
.
getSdkTelemetryConfig
(
)
;
ok
(
,
'expected a TelemetryConfig'
)
;
strictEqual
(
!
.
,
'otlp-http'
)
;
ok
(
!
.
?.
startsWith
(
'http://127.0.0.1:'
)
,
` expected loopback endpoint, got ${ cfg! . otlpEndpoint} `
)
;
const
=
.
getSpansDbPath
(
)
;
ok
(
,
'expected a db path in DB mode'
)
;
ok
(
!
.
.
replace
(
/ \\ / g
,
'/'
)
.
endsWith
(
)
)
;
const
=
'1122334455667788aabbccddeeff0011'
;
const
=
'0000000000000001'
;
const
=
'0000000000000002'
;
const
=
await
postOtlp
(
!
.
!
,
makeOtlpRequest
(
,
)
)
;
strictEqual
(
.
,
200
,
` unexpected res1: ${ res1. body} `
)
;
const
=
await
postOtlp
(
!
.
!
,
makeOtlpRequest
(
,
)
)
;
strictEqual
(
.
,
200
,
` unexpected res2: ${ res2. body} `
)
;
await
.
flush
(
)
;
const
=
await
.
getSdkTelemetryConfig
(
)
;
strictEqual
(
!
.
,
!
.
)
;
const
=
new
OTelSqliteStore
(
!
.
)
;
try
{
const
=
.
getSpansByTraceId
(
)
;
strictEqual
(
.
,
2
,
` expected 2 persisted spans, got ${ persisted. length} (res1.body= ${ res1. body} ) `
)
;
const
=
.
map
(
=>
.
)
.
sort
(
)
;
deepStrictEqual
(
,
[
'invoke_agent copilotcli'
,
'invoke_agent copilotcli'
]
)
;
const
=
.
map
(
=>
.
)
;
ok
(
.
every
(
=>
===
'invoke_agent'
)
)
;
notStrictEqual
(
[
0
]
.
,
null
)
;
}
finally
{
.
close
(
)
;
}
}
finally
{
restoreEnv
(
)
;
await
cleanup
(
)
;
}
}
)
;
test
(
'DB mode: emits session title metadata spans when content capture is enabled'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
const
cleanup
=
(
)
=>
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
;
try
{
.
.
COPILOT_OTEL_DB_SPAN_EXPORTER_ENABLED
=
'true'
;
.
.
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT
=
'true'
;
.
.
OTEL_SERVICE_NAME
=
'agent-host-test'
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
await
.
getSdkTelemetryConfig
(
)
;
.
emitSessionTitleChanged
(
'conv-title'
,
'copilotcli:/conv-title'
,
` Updated title ${ 'x' . repeat ( 300 ) } `
)
;
await
.
flush
(
)
;
const
=
.
getSpansDbPath
(
)
;
ok
(
)
;
const
=
new
OTelSqliteStore
(
!
.
)
;
try
{
const
=
.
getSpansByConversationId
(
'conv-title'
)
;
strictEqual
(
.
,
2
)
;
const
=
.
find
(
=>
.
===
)
;
ok
(
)
;
strictEqual
(
.
getSpanAttribute
(
.
,
)
?.
,
200
)
;
strictEqual
(
.
getSpanAttribute
(
.
,
)
,
'copilotcli:/conv-title'
)
;
strictEqual
(
.
getSpanAttribute
(
.
,
'service.name'
)
,
'agent-host-test'
)
;
strictEqual
(
.
getSpanAttribute
(
.
,
'service.namespace'
)
,
'vscode.agent-host'
)
;
}
finally
{
.
close
(
)
;
}
}
finally
{
restoreEnv
(
)
;
await
cleanup
(
)
;
}
}
)
;
test
(
'DB mode keeps protobuf and gRPC traces local instead of HTTP-posting the wrong wire format'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
try
{
for
(
const
of
[
'http/protobuf'
,
'grpc'
]
)
{
.
.
COPILOT_OTEL_DB_SPAN_EXPORTER_ENABLED
=
'true'
;
.
.
COPILOT_OTEL_EXPORTER_TYPE
=
===
'grpc'
?
'otlp-grpc'
:
'otlp-http'
;
.
.
OTEL_EXPORTER_OTLP_ENDPOINT
=
'http://collector:4318'
;
.
.
OTEL_EXPORTER_OTLP_PROTOCOL
=
;
let
=
0
;
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
.
add
(
{
dispose
:
(
)
=>
void
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
}
)
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
async
(
)
=>
{
++
;
return
new
Response
(
null
,
{
:
200
}
)
;
}
)
)
;
const
=
await
.
getSdkTelemetryConfig
(
)
;
const
=
await
postOtlp
(
!
.
!
,
makeOtlpRequest
(
'ffeeddccbbaa99887766554433221100'
,
'00000000000000aa'
)
)
;
strictEqual
(
.
,
200
)
;
await
.
flush
(
)
;
strictEqual
(
,
0
)
;
}
}
finally
{
restoreEnv
(
)
;
}
}
)
;
test
(
'DB mode + external endpoint: outbound forwarder is configured (best-effort)'
,
async
(
)
=>
{
const
=
saveEnv
(
)
;
const
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'vscode-otel-svc-'
)
)
;
const
cleanup
=
(
)
=>
rm
(
,
{
:
true
,
:
true
}
)
.
catch
(
(
)
=>
undefined
)
;
try
{
.
.
COPILOT_OTEL_DB_SPAN_EXPORTER_ENABLED
=
'true'
;
.
.
COPILOT_OTEL_EXPORTER_TYPE
=
'otlp-http'
;
.
.
OTEL_EXPORTER_OTLP_ENDPOINT
=
'http://127.0.0.1:1'
;
const
=
.
add
(
new
TestInstantiationService
(
)
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
makeEnvService
(
)
)
;
const
=
.
add
(
.
createInstance
(
,
undefined
)
)
;
const
=
await
.
getSdkTelemetryConfig
(
)
;
ok
(
!
.
?.
startsWith
(
'http://127.0.0.1:'
)
)
;
notStrictEqual
(
!
.
,
.
.
OTEL_EXPORTER_OTLP_ENDPOINT
)
;
const
=
'ffeeddccbbaa99887766554433221100'
;
const
=
await
postOtlp
(
!
.
!
,
makeOtlpRequest
(
,
'00000000000000ff'
)
)
;
strictEqual
(
.
,
200
)
;
await
.
flush
(
)
;
}
finally
{
restoreEnv
(
)
;
await
cleanup
(
)
;
}
}
)
;
}
)
;