Skip to content

Commit 78c31aa

Browse files
authored
chore: revert add custom error serializer to console instrumentation (#918)
1 parent c39f95a commit 78c31aa

File tree

5 files changed

+2
-51
lines changed

5 files changed

+2
-51
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## Next
44

5-
- Feature (`@grafana/faro-web-sdk`): Add `errorSerializer` to the `consoleInstrumentation` property of the core
6-
configuration object to provide custom ways to serialize data captured by the `ConsoleInstrumentation` (#902)
75
- Feature (`@grafana/faro-web-sdk`): Provide APIs to send `service.name` override instructions to the
86
receiver (#893)
97
- Improvement (`@grafana/faro-web-sdk`): Send an event for `service.name` overrides (#903)

packages/core/src/config/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ export interface Config<P = APIEvent> {
179179
* By default, Faro sends an error for console.error calls. If you want to send a log instead, set this to true.
180180
*/
181181
consoleErrorAsLog?: boolean;
182-
183-
/**
184-
* Custom function to serialize the contents of error messages
185-
*/
186-
errorSerializer?: LogArgsSerializer;
187182
};
188183
}
189184

packages/web-sdk/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,3 @@ export {
168168
} from './instrumentations/session';
169169

170170
export { getIgnoreUrls } from './utils/url';
171-
export { stringifyExternalJson } from './utils/json';

packages/web-sdk/src/instrumentations/console/instrumentation.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { ExceptionEvent, LogEvent } from '@grafana/faro-core';
33
import { mockConfig, MockTransport } from '@grafana/faro-core/src/testUtils';
44

55
import { makeCoreConfig } from '../../config';
6-
import { stringifyExternalJson } from '../../utils';
76

87
import { ConsoleInstrumentation } from './instrumentation';
98

@@ -82,37 +81,6 @@ describe('ConsoleInstrumentation', () => {
8281
);
8382
});
8483

85-
it('Handles objects with circular references with custom serializer', () => {
86-
const mockTransport = new MockTransport();
87-
88-
initializeFaro(
89-
makeCoreConfig(
90-
mockConfig({
91-
transports: [mockTransport],
92-
instrumentations: [
93-
new ConsoleInstrumentation({
94-
errorSerializer: (args: any[]) => {
95-
return args.map((arg) => (typeof arg === 'string' ? arg : stringifyExternalJson(arg))).join(' ');
96-
},
97-
}),
98-
],
99-
unpatchedConsole: {
100-
error: jest.fn(),
101-
} as unknown as Console,
102-
})
103-
)!
104-
);
105-
106-
const objWithCircularRef = { foo: 'bar', baz: 'bam' };
107-
(objWithCircularRef as any).circular = objWithCircularRef;
108-
109-
console.error('with circular refs object', objWithCircularRef);
110-
111-
expect((mockTransport.items[0] as TransportItem<ExceptionEvent>)?.payload.value).toBe(
112-
`console.error: with circular refs object {\"foo\":\"bar\",\"baz\":\"bam\",\"circular\":null}`
113-
);
114-
});
115-
11684
it('sends a faro log for console.error calls if configured', () => {
11785
const mockTransport = new MockTransport();
11886

packages/web-sdk/src/instrumentations/console/instrumentation.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
allLogLevels,
3-
BaseInstrumentation,
4-
defaultLogArgsSerializer,
5-
LogArgsSerializer,
6-
LogLevel,
7-
VERSION,
8-
} from '@grafana/faro-core';
1+
import { allLogLevels, BaseInstrumentation, defaultLogArgsSerializer, LogLevel, VERSION } from '@grafana/faro-core';
92

103
import type { ConsoleInstrumentationOptions } from './types';
114

@@ -14,7 +7,6 @@ export class ConsoleInstrumentation extends BaseInstrumentation {
147
readonly version = VERSION;
158

169
static defaultDisabledLevels: LogLevel[] = [LogLevel.DEBUG, LogLevel.TRACE, LogLevel.LOG];
17-
private errorSerializer: LogArgsSerializer = defaultLogArgsSerializer;
1810

1911
constructor(private options: ConsoleInstrumentationOptions = {}) {
2012
super();
@@ -23,7 +15,6 @@ export class ConsoleInstrumentation extends BaseInstrumentation {
2315
initialize() {
2416
this.logDebug('Initializing\n', this.options);
2517
this.options = { ...this.options, ...this.config.consoleInstrumentation };
26-
this.errorSerializer = this.options.errorSerializer ?? defaultLogArgsSerializer;
2718

2819
allLogLevels
2920
.filter(
@@ -34,7 +25,7 @@ export class ConsoleInstrumentation extends BaseInstrumentation {
3425
console[level] = (...args) => {
3526
try {
3627
if (level === LogLevel.ERROR && !this.options?.consoleErrorAsLog) {
37-
this.api.pushError(new Error('console.error: ' + this.errorSerializer(args)));
28+
this.api.pushError(new Error('console.error: ' + defaultLogArgsSerializer(args)));
3829
} else {
3930
this.api.pushLog(args, { level });
4031
}

0 commit comments

Comments
 (0)