@outputai/http 0.10.1-next.fc0a41f.0 → 0.11.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.
@@ -1,6 +1,6 @@
1
1
  import { Tracing } from '@outputai/core/sdk/runtime';
2
2
  import { config } from '../config.js';
3
- import { parseBody, redactHeaders, serializeError } from './utils.js';
3
+ import { parseBody, redactHeaders } from './utils.js';
4
4
  /**
5
5
  * Sends the trace start event for an http request
6
6
  *
@@ -32,4 +32,4 @@ export const logResponse = async ({ requestId, response }) => Tracing.addEventEn
32
32
  ...(config.logVerbose && { headers: redactHeaders(response.headers), body: await parseBody(response) })
33
33
  }
34
34
  });
35
- export const logFailure = ({ requestId, error }) => Tracing.addEventError({ id: requestId, details: serializeError(error) });
35
+ export const logFailure = ({ requestId, error }) => Tracing.addEventError({ id: requestId, details: error });
@@ -167,19 +167,10 @@ describe('instrumented_fetch/logger', () => {
167
167
  });
168
168
  });
169
169
  describe('logFailure', () => {
170
- it('records a serialized error', () => {
170
+ it('records the error', () => {
171
171
  const error = new TypeError('network unavailable');
172
172
  logFailure({ requestId: 'request-failure', error });
173
- expect(tracing.addEventError).toHaveBeenCalledWith({
174
- id: 'request-failure',
175
- details: {
176
- name: 'TypeError',
177
- message: 'network unavailable',
178
- stack: error.stack,
179
- code: undefined,
180
- cause: undefined
181
- }
182
- });
173
+ expect(tracing.addEventError).toHaveBeenCalledWith({ id: 'request-failure', details: error });
183
174
  });
184
175
  });
185
176
  });
@@ -1,4 +1,3 @@
1
- export function serializeError(error: Error, depth?: number): any;
2
1
  export function redactHeaders(headers: Headers): object;
3
2
  export function parseBody(r: Request | Response): object | string;
4
3
  export function addRequestIdToResponse(response: Response, requestId: string): void;
@@ -25,33 +25,6 @@ const SENSITIVE_HEADER_PATTERNS = [
25
25
  // matches header that contain words ending with these sequences
26
26
  wordEndMatcher('key')
27
27
  ];
28
- /**
29
- * Serialize a given error to a plain object keeping main properties:
30
- * - name (from constructor.name)
31
- * - message
32
- * - stack
33
- * - code (optional, but present on Node errors)
34
- * - cause (error chain)
35
- *
36
- * @param {Error} error Error to serialize
37
- * @param {number} depth Current recursion depth for the error.cause chain
38
- * @returns Object
39
- */
40
- export const serializeError = (error, depth = 1) => ({
41
- name: error.constructor.name,
42
- message: error.message,
43
- stack: error.stack,
44
- code: error?.code,
45
- cause: (() => {
46
- if (depth > 5) {
47
- return '<Max recursion depth reached>';
48
- }
49
- if (error.cause instanceof Error) {
50
- return serializeError(error.cause, depth + 1);
51
- }
52
- return undefined; // eslint-disable-line consistent-return
53
- })()
54
- });
55
28
  /**
56
29
  * Redacts sensitive headers for safe logging
57
30
  *
@@ -1,43 +1,8 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import { Headers, Request, Response } from 'undici';
3
3
  import { requestIdSymbol } from '../consts.js';
4
- import { addRequestIdToResponse, parseBody, redactHeaders, serializeError } from './utils.js';
5
- const createErrorChain = levels => {
6
- const root = new Error('level-1');
7
- Array.from({ length: levels - 1 }, (_, index) => index + 2).reduce((current, level) => {
8
- const cause = new Error(`level-${level}`);
9
- current.cause = cause;
10
- return cause;
11
- }, root);
12
- return root;
13
- };
4
+ import { addRequestIdToResponse, parseBody, redactHeaders } from './utils.js';
14
5
  describe('instrumented_fetch/utils', () => {
15
- describe('serializeError', () => {
16
- it('serializes standard error properties and a nested cause', () => {
17
- const cause = new TypeError('cause');
18
- const error = new Error('failure', { cause });
19
- error.code = 'E_FAILURE';
20
- expect(serializeError(error)).toEqual({
21
- name: 'Error',
22
- message: 'failure',
23
- stack: error.stack,
24
- code: 'E_FAILURE',
25
- cause: {
26
- name: 'TypeError',
27
- message: 'cause',
28
- stack: cause.stack,
29
- code: undefined,
30
- cause: undefined
31
- }
32
- });
33
- });
34
- it('limits the serialized cause depth', () => {
35
- const serialized = serializeError(createErrorChain(7));
36
- const current = Array.from({ length: 5 }).reduce(cause => cause.cause, serialized);
37
- expect(current.message).toBe('level-6');
38
- expect(current.cause).toBe('<Max recursion depth reached>');
39
- });
40
- });
41
6
  describe('redactHeaders', () => {
42
7
  it('redacts sensitive header names while preserving safe values', () => {
43
8
  const headers = new Headers({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outputai/http",
3
- "version": "0.10.1-next.fc0a41f.0",
3
+ "version": "0.11.0",
4
4
  "description": "Framework abstraction to make HTTP calls with tracing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,11 +16,11 @@
16
16
  "undici": ">=8 <9"
17
17
  },
18
18
  "dependencies": {
19
- "@outputai/core": "0.10.1-next.fc0a41f.0"
19
+ "@outputai/core": "0.11.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "ky": "2.0.2",
23
- "undici": "8.5.0"
23
+ "undici": "8.9.0"
24
24
  },
25
25
  "license": "Apache-2.0",
26
26
  "publishConfig": {