@outputai/http 0.8.1 → 0.8.2-next.0f9af4b.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 +2 -2
- package/dist/cost.spec.js +11 -9
- package/dist/fetch/logger.js +2 -2
- package/dist/fetch/logger.spec.js +10 -8
- package/package.json +3 -3
package/dist/cost.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Tracing,
|
|
1
|
+
import { Tracing, Event } from '@outputai/core/sdk/runtime';
|
|
2
2
|
import { requestIdSymbol } from './consts.js';
|
|
3
3
|
/**
|
|
4
4
|
* Attach cost information to the trace of an HTTP Request using the response
|
|
@@ -15,5 +15,5 @@ export const addRequestCost = (response, value) => {
|
|
|
15
15
|
}
|
|
16
16
|
const attribute = new Tracing.Attribute.HTTPRequestCost(response.url, eventId, value);
|
|
17
17
|
Tracing.addEventAttribute({ eventId, attribute });
|
|
18
|
-
|
|
18
|
+
Event.emit('cost:http:request', attribute);
|
|
19
19
|
};
|
package/dist/cost.spec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { Response } from 'undici';
|
|
3
3
|
import { requestIdSymbol } from './consts.js';
|
|
4
|
-
vi.mock('@outputai/core/
|
|
4
|
+
vi.mock('@outputai/core/sdk/runtime', () => {
|
|
5
5
|
class HTTPRequestCost {
|
|
6
6
|
static TYPE = 'http:request:cost';
|
|
7
7
|
type = HTTPRequestCost.TYPE;
|
|
@@ -21,18 +21,20 @@ vi.mock('@outputai/core/sdk_activity_integration', () => {
|
|
|
21
21
|
HTTPRequestCost
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
|
|
24
|
+
Event: {
|
|
25
|
+
emit: vi.fn()
|
|
26
|
+
}
|
|
25
27
|
};
|
|
26
28
|
});
|
|
27
|
-
import { Tracing,
|
|
29
|
+
import { Tracing, Event } from '@outputai/core/sdk/runtime';
|
|
28
30
|
import { addRequestCost } from './cost.js';
|
|
29
31
|
import { addRequestIdToResponse } from './fetch/utils.js';
|
|
30
32
|
const tracing = vi.mocked(Tracing, true);
|
|
31
|
-
const
|
|
33
|
+
const event = vi.mocked(Event, true);
|
|
32
34
|
describe('addRequestCost', () => {
|
|
33
35
|
beforeEach(() => {
|
|
34
36
|
tracing.addEventAttribute.mockClear();
|
|
35
|
-
emit.mockClear();
|
|
37
|
+
event.emit.mockClear();
|
|
36
38
|
vi.spyOn(console, 'warn').mockImplementation(() => { });
|
|
37
39
|
});
|
|
38
40
|
afterEach(() => {
|
|
@@ -44,7 +46,7 @@ describe('addRequestCost', () => {
|
|
|
44
46
|
addRequestCost(response, cost);
|
|
45
47
|
expect(console.warn).toHaveBeenCalledWith('addRequestCost(): The "response" argument did not originate from @outputai/http, no costs were added.');
|
|
46
48
|
expect(tracing.addEventAttribute).not.toHaveBeenCalled();
|
|
47
|
-
expect(emit).not.toHaveBeenCalled();
|
|
49
|
+
expect(event.emit).not.toHaveBeenCalled();
|
|
48
50
|
});
|
|
49
51
|
it('records cost on the trace event when the response carries the request id', () => {
|
|
50
52
|
const response = new Response(undefined, { status: 200 });
|
|
@@ -62,7 +64,7 @@ describe('addRequestCost', () => {
|
|
|
62
64
|
})
|
|
63
65
|
});
|
|
64
66
|
const attribute = tracing.addEventAttribute.mock.calls[0][0].attribute;
|
|
65
|
-
expect(emit).toHaveBeenCalledWith('cost:http:request', attribute);
|
|
67
|
+
expect(event.emit).toHaveBeenCalledWith('cost:http:request', attribute);
|
|
66
68
|
});
|
|
67
69
|
it('records zero cost on the trace event', () => {
|
|
68
70
|
const response = new Response();
|
|
@@ -79,7 +81,7 @@ describe('addRequestCost', () => {
|
|
|
79
81
|
})
|
|
80
82
|
});
|
|
81
83
|
const attribute = tracing.addEventAttribute.mock.calls[0][0].attribute;
|
|
82
|
-
expect(emit).toHaveBeenCalledWith('cost:http:request', attribute);
|
|
84
|
+
expect(event.emit).toHaveBeenCalledWith('cost:http:request', attribute);
|
|
83
85
|
});
|
|
84
86
|
// ky clones the response before passing it to afterResponse hooks. Without
|
|
85
87
|
// the clone-propagation patch in addRequestIdToResponse, this path silently
|
|
@@ -100,6 +102,6 @@ describe('addRequestCost', () => {
|
|
|
100
102
|
})
|
|
101
103
|
});
|
|
102
104
|
const attribute = tracing.addEventAttribute.mock.calls[0][0].attribute;
|
|
103
|
-
expect(emit).toHaveBeenCalledWith('cost:http:request', attribute);
|
|
105
|
+
expect(event.emit).toHaveBeenCalledWith('cost:http:request', attribute);
|
|
104
106
|
});
|
|
105
107
|
});
|
package/dist/fetch/logger.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Tracing,
|
|
1
|
+
import { Tracing, Event } from '@outputai/core/sdk/runtime';
|
|
2
2
|
import { config } from '../config.js';
|
|
3
3
|
import { parseBody, redactHeaders, serializeError } from './utils.js';
|
|
4
4
|
/** Single source of truth for the `http:request` event shape. */
|
|
5
5
|
const emitHttpRequestEvent = (payload) => {
|
|
6
|
-
|
|
6
|
+
Event.emit('http:request', payload);
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Sends the trace start event for an http request
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { Response, Request } from 'undici';
|
|
3
|
-
vi.mock('@outputai/core/
|
|
3
|
+
vi.mock('@outputai/core/sdk/runtime', () => {
|
|
4
4
|
class HTTPRequestCount {
|
|
5
5
|
static TYPE = 'http:request:count';
|
|
6
6
|
type = HTTPRequestCount.TYPE;
|
|
@@ -21,12 +21,14 @@ vi.mock('@outputai/core/sdk_activity_integration', () => {
|
|
|
21
21
|
HTTPRequestCount
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
|
|
24
|
+
Event: {
|
|
25
|
+
emit: vi.fn()
|
|
26
|
+
}
|
|
25
27
|
};
|
|
26
28
|
});
|
|
27
|
-
import { Tracing,
|
|
29
|
+
import { Tracing, Event } from '@outputai/core/sdk/runtime';
|
|
28
30
|
const tracing = vi.mocked(Tracing, true);
|
|
29
|
-
const
|
|
31
|
+
const event = vi.mocked(Event, true);
|
|
30
32
|
/** Loads logger with optional verbose tracing env so `config.js` is evaluated fresh. */
|
|
31
33
|
async function logLogger(verbose) {
|
|
32
34
|
vi.resetModules();
|
|
@@ -43,7 +45,7 @@ beforeEach(() => {
|
|
|
43
45
|
tracing.addEventEnd.mockClear();
|
|
44
46
|
tracing.addEventError.mockClear();
|
|
45
47
|
tracing.addEventAttribute.mockClear();
|
|
46
|
-
emit.mockClear();
|
|
48
|
+
event.emit.mockClear();
|
|
47
49
|
});
|
|
48
50
|
describe('fetch/logger', () => {
|
|
49
51
|
describe('logRequest', () => {
|
|
@@ -231,7 +233,7 @@ describe('fetch/logger', () => {
|
|
|
231
233
|
url: 'https://api.example.com/ok',
|
|
232
234
|
durationMs: 42
|
|
233
235
|
});
|
|
234
|
-
expect(emit).toHaveBeenCalledWith('http:request', {
|
|
236
|
+
expect(event.emit).toHaveBeenCalledWith('http:request', {
|
|
235
237
|
requestId: 'r-ok',
|
|
236
238
|
method: 'GET',
|
|
237
239
|
url: 'https://api.example.com/ok',
|
|
@@ -250,7 +252,7 @@ describe('fetch/logger', () => {
|
|
|
250
252
|
url: 'https://api.example.com/err',
|
|
251
253
|
durationMs: 15
|
|
252
254
|
});
|
|
253
|
-
expect(emit).toHaveBeenCalledWith('http:request', {
|
|
255
|
+
expect(event.emit).toHaveBeenCalledWith('http:request', {
|
|
254
256
|
requestId: 'r-err',
|
|
255
257
|
method: 'POST',
|
|
256
258
|
url: 'https://api.example.com/err',
|
|
@@ -269,7 +271,7 @@ describe('fetch/logger', () => {
|
|
|
269
271
|
url: 'https://api.example.com/net',
|
|
270
272
|
durationMs: 9
|
|
271
273
|
});
|
|
272
|
-
expect(emit).toHaveBeenCalledWith('http:request', {
|
|
274
|
+
expect(event.emit).toHaveBeenCalledWith('http:request', {
|
|
273
275
|
requestId: 'r-net',
|
|
274
276
|
method: 'GET',
|
|
275
277
|
url: 'https://api.example.com/net',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outputai/http",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2-next.0f9af4b.0",
|
|
4
4
|
"description": "Framework abstraction to make HTTP calls with tracing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ky": "1.14.3",
|
|
13
|
-
"undici": "8.
|
|
14
|
-
"@outputai/core": "0.8.
|
|
13
|
+
"undici": "8.5.0",
|
|
14
|
+
"@outputai/core": "0.8.2-next.0f9af4b.0"
|
|
15
15
|
},
|
|
16
16
|
"license": "Apache-2.0",
|
|
17
17
|
"publishConfig": {
|