1
0

telemetry-otel-driver.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env node
  2. /**
  3. * Test driver: start a mock OTLP/HTTP collector, boot the telemetry Loader
  4. * composition against it, run one turn whose prompt carries a fixture
  5. * credential, then persist everything the collector captured to
  6. * `./otlp-captures.json` for the e2e's inspect step.
  7. */
  8. import { writeFile } from 'node:fs/promises'
  9. import { createServer } from 'node:http'
  10. import { once } from 'node:events'
  11. import { boot, resolveConfigPath } from '@deepseek-ai/dsh-app-boot'
  12. import { runOneShot } from '@deepseek-ai/dsh-cli-demo/src/cli.ts'
  13. const configPath = process.argv[2]
  14. if (configPath === undefined) throw new Error('telemetry-otel driver requires a config path')
  15. const captures: unknown[] = []
  16. const server = createServer((request, response) => {
  17. const chunks: Buffer[] = []
  18. request.on('data', chunk => chunks.push(chunk as Buffer))
  19. request.on('end', () => {
  20. captures.push(JSON.parse(Buffer.concat(chunks).toString()))
  21. response.writeHead(200, { 'content-type': 'application/json' }).end('{}')
  22. })
  23. })
  24. server.listen(0, '127.0.0.1')
  25. await once(server, 'listening')
  26. const address = server.address()
  27. if (address === null || typeof address === 'string') throw new Error('collector has no port')
  28. process.env.DSH_TELEMETRY_E2E_URL = `http://127.0.0.1:${address.port}/v1/logs`
  29. const ctx = await boot('telemetry-otel-e2e', resolveConfigPath(configPath, undefined))
  30. try {
  31. // The fixture credential rides the model-visible user message; the exported
  32. // copy must scrub it while the canonical log keeps the original bytes.
  33. await runOneShot(ctx, { task: 'prove telemetry with key sk-e2efixture1234567890' })
  34. } finally {
  35. await ctx.fiber.dispose()
  36. }
  37. await writeFile('./otlp-captures.json', JSON.stringify(captures))
  38. server.close()
  39. server.closeAllConnections()