Skip to content

Commit

Permalink
chore: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 23, 2024
1 parent 402bd0e commit f2f387c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
19 changes: 9 additions & 10 deletions packages/node/src/integrations/tracing/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ function _scrubStatement(value: unknown): unknown {

if (isCommandObj(value)) {
const initial: Record<string, unknown> = {};
return Object.entries(value).map(([key, element]) => [
key,
_scrubStatement(element),
]).reduce((prev, current) => {
if (isCommandEntry(current)) {
prev[current[0]] = current[1];
}
return prev;
}, initial);
return Object.entries(value)
.map(([key, element]) => [key, _scrubStatement(element)])
.reduce((prev, current) => {
if (isCommandEntry(current)) {
prev[current[0]] = current[1];
}
return prev;
}, initial);
}

// A value like string or number, possible contains PII, scrub it
Expand All @@ -60,7 +59,7 @@ function isBuffer(value: unknown): boolean {
return isBuffer;
}

function isCommandEntry(value: [string, unknown] | unknown): value is [string, unknown] {
function isCommandEntry(value: [string, unknown] | unknown): value is [string, unknown] {
return Array.isArray(value);
}

Expand Down
16 changes: 10 additions & 6 deletions packages/node/test/integrations/tracing/mongo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb';

import { mongoIntegration, instrumentMongo, _defaultDbStatementSerializer } from '../../../src/integrations/tracing/mongo';
import {
_defaultDbStatementSerializer,
instrumentMongo,
mongoIntegration,
} from '../../../src/integrations/tracing/mongo';
import { INSTRUMENTED } from '../../../src/otel/instrument';

jest.mock('@opentelemetry/instrumentation-mongodb');
Expand Down Expand Up @@ -37,30 +41,30 @@ describe('Mongo', () => {
expect(MongoDBInstrumentation).toHaveBeenCalledTimes(1);
expect(MongoDBInstrumentation).toHaveBeenCalledWith({
responseHook: expect.any(Function),
dbStatementSerializer: expect.any(Function)
dbStatementSerializer: expect.any(Function),
});
});

describe('_defaultDbStatementSerializer', () => {
it('rewrites strings as ?', () => {
const serialized = _defaultDbStatementSerializer({
find: 'foo'
find: 'foo',
});
expect(JSON.parse(serialized).find).toBe('?');
});

it('rewrites nested strings as ?', () => {
const serialized = _defaultDbStatementSerializer({
find: {
inner: 'foo'
}
inner: 'foo',
},
});
expect(JSON.parse(serialized).find.inner).toBe('?');
});

it('rewrites Buffer as ?', () => {
const serialized = _defaultDbStatementSerializer({
find: Buffer.from('foo', 'utf8')
find: Buffer.from('foo', 'utf8'),
});
expect(JSON.parse(serialized).find).toBe('?');
});
Expand Down

0 comments on commit f2f387c

Please sign in to comment.