compatibility-adapters.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. commandCompatibilityAttributes,
  4. httpResponseCompatibilityAttributes,
  5. modelAttemptCompatibilityAttributes,
  6. modelResponseCompatibilityAttributes,
  7. toolCompatibilityAttributes,
  8. } from "../src/compatibility-adapters.js";
  9. describe("telemetry compatibility adapters", () => {
  10. it("projects tool facts to GenAI aliases without inventing a second canonical schema", () => {
  11. expect(
  12. toolCompatibilityAttributes({
  13. toolCallId: "tool-1",
  14. toolName: "Bash",
  15. }),
  16. ).toEqual({
  17. "gen_ai.operation.name": "execute_tool",
  18. "gen_ai.tool.call.id": "tool-1",
  19. "gen_ai.tool.name": "Bash",
  20. });
  21. });
  22. it("projects a sanitized model target to GenAI and standard server aliases", () => {
  23. expect(
  24. modelAttemptCompatibilityAttributes({
  25. providerId: "anthropic-prod",
  26. providerKind: "anthropic",
  27. providerOrigin: "https://api.example.com:8443",
  28. reasoning: {
  29. capability: "supported",
  30. requestedControl: "fixed_level",
  31. requestedLevel: "high",
  32. requestedState: "enabled",
  33. },
  34. requestedModel: "claude-sonnet-4",
  35. }),
  36. ).toEqual({
  37. "gen_ai.provider.name": "anthropic",
  38. "gen_ai.request.model": "claude-sonnet-4",
  39. "server.address": "api.example.com",
  40. "server.port": 8443,
  41. });
  42. });
  43. it("projects response, usage and HTTP facts to their standard aliases", () => {
  44. expect(
  45. modelResponseCompatibilityAttributes({
  46. finishReason: "tool_calls",
  47. inputTokens: 120,
  48. outputTokens: 30,
  49. responseModel: "claude-sonnet-4-20260701",
  50. }),
  51. ).toEqual({
  52. "gen_ai.response.finish_reasons": ["tool_calls"],
  53. "gen_ai.response.model": "claude-sonnet-4-20260701",
  54. "gen_ai.usage.input_tokens": 120,
  55. "gen_ai.usage.output_tokens": 30,
  56. });
  57. expect(httpResponseCompatibilityAttributes(429)).toEqual({
  58. "http.response.status_code": 429,
  59. });
  60. expect(commandCompatibilityAttributes({ exitCode: 127, signal: "SIGTERM" })).toEqual({
  61. "process.exit.code": 127,
  62. "process.signal.name": "SIGTERM",
  63. });
  64. });
  65. });