@outputai/http 0.2.1-next.23c3ed0.0 → 0.2.1-next.2ddcc3e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cost.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Tracing } from '@outputai/core/sdk_activity_integration';
1
+ import { Tracing, emitEvent } from '@outputai/core/sdk_activity_integration';
2
2
  import { requestIdSymbol } from './consts.js';
3
3
  /**
4
4
  * Attach cost information to the trace of an HTTP Request using the response
@@ -14,4 +14,5 @@ export const addRequestCost = (response, cost) => {
14
14
  return;
15
15
  }
16
16
  Tracing.addEventAttribute({ eventId, name: Tracing.Attribute.COST, value: cost });
17
+ emitEvent('cost:http:request', { requestId: eventId, url: response.url, cost });
17
18
  };
package/dist/cost.spec.js CHANGED
@@ -6,14 +6,17 @@ vi.mock('@outputai/core/sdk_activity_integration', () => ({
6
6
  Attribute: {
7
7
  COST: 'cost'
8
8
  }
9
- }
9
+ },
10
+ emitEvent: vi.fn()
10
11
  }));
11
- import { Tracing } from '@outputai/core/sdk_activity_integration';
12
+ import { Tracing, emitEvent } from '@outputai/core/sdk_activity_integration';
12
13
  import { addRequestCost } from './cost.js';
13
14
  const tracing = vi.mocked(Tracing, true);
15
+ const emit = vi.mocked(emitEvent, true);
14
16
  describe('addRequestCost', () => {
15
17
  beforeEach(() => {
16
18
  tracing.addEventAttribute.mockClear();
19
+ emit.mockClear();
17
20
  vi.spyOn(console, 'warn').mockImplementation(() => { });
18
21
  });
19
22
  afterEach(() => {
@@ -25,9 +28,10 @@ describe('addRequestCost', () => {
25
28
  addRequestCost(response, cost);
26
29
  expect(console.warn).toHaveBeenCalledWith('addRequestCost(): The "response" argument did not originate from @outputai/http, no costs were added.');
27
30
  expect(tracing.addEventAttribute).not.toHaveBeenCalled();
31
+ expect(emit).not.toHaveBeenCalled();
28
32
  });
29
33
  it('records cost on the trace event when the response carries the request id', () => {
30
- const response = new Response();
34
+ const response = new Response(undefined, { status: 200 });
31
35
  Reflect.set(response, requestIdSymbol, 'evt-cost-1');
32
36
  const cost = { total: 2.5 };
33
37
  addRequestCost(response, cost);
@@ -37,6 +41,11 @@ describe('addRequestCost', () => {
37
41
  name: Tracing.Attribute.COST,
38
42
  value: cost
39
43
  });
44
+ expect(emit).toHaveBeenCalledWith('cost:http:request', {
45
+ requestId: 'evt-cost-1',
46
+ url: response.url,
47
+ cost
48
+ });
40
49
  });
41
50
  it('forwards multiple components to tracing', () => {
42
51
  const response = new Response();
@@ -54,6 +63,11 @@ describe('addRequestCost', () => {
54
63
  name: Tracing.Attribute.COST,
55
64
  value: cost
56
65
  });
66
+ expect(emit).toHaveBeenCalledWith('cost:http:request', {
67
+ requestId: 'evt-cost-2',
68
+ url: response.url,
69
+ cost
70
+ });
57
71
  });
58
72
  it('forwards an empty components array to tracing', () => {
59
73
  const response = new Response();
@@ -65,5 +79,10 @@ describe('addRequestCost', () => {
65
79
  name: Tracing.Attribute.COST,
66
80
  value: cost
67
81
  });
82
+ expect(emit).toHaveBeenCalledWith('cost:http:request', {
83
+ requestId: 'evt-cost-3',
84
+ url: response.url,
85
+ cost
86
+ });
68
87
  });
69
88
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outputai/http",
3
- "version": "0.2.1-next.23c3ed0.0",
3
+ "version": "0.2.1-next.2ddcc3e.0",
4
4
  "description": "Framework abstraction to make HTTP calls with tracing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "ky": "1.14.3",
13
13
  "undici": "8.1.0",
14
- "@outputai/core": "0.2.1-next.23c3ed0.0"
14
+ "@outputai/core": "0.2.1-next.2ddcc3e.0"
15
15
  },
16
16
  "license": "Apache-2.0",
17
17
  "publishConfig": {