Skip to content

Commit

Permalink
feat(instrumentation-dns): allow ignoreHostnames to be only a single …
Browse files Browse the repository at this point in the history
…IgnoreMatcher
  • Loading branch information
10xLaCroixDrinker committed Feb 7, 2024
1 parent 39c34df commit 98d624c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/node/opentelemetry-instrumentation-dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Dns instrumentation has currently one option. You can set the following:

| Options | Type | Description |
| ------- | ---- | ----------- |
| [`ignoreHostnames`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-dns/src/types.ts#L99) | `IgnoreMatcher[]` | Dns instrumentation will not trace all requests that match hostnames |
| [`ignoreHostnames`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-dns/src/types.ts#L99) | `IgnoreMatcher | IgnoreMatcher[]` | Dns instrumentation will not trace all requests that match hostnames |

## Useful links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ import { InstrumentationConfig } from '@opentelemetry/instrumentation';

export type IgnoreMatcher = string | RegExp | ((url: string) => boolean);
export interface DnsInstrumentationConfig extends InstrumentationConfig {
ignoreHostnames?: IgnoreMatcher[];
ignoreHostnames?: IgnoreMatcher | IgnoreMatcher[];
}
5 changes: 4 additions & 1 deletion plugins/node/opentelemetry-instrumentation-dns/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ export const satisfiesPattern = (
*/
export const isIgnored = (
constant: string,
list?: IgnoreMatcher[],
list?: IgnoreMatcher | IgnoreMatcher[],
onException?: (error: Error) => void
): boolean => {
if (!list) {
// No ignored urls - trace everything
return false;
}
if (!Array.isArray(list)) {
list = [list];
}
// Try/catch outside the loop for failing fast
try {
for (const pattern of list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ describe('Utility', () => {
assert.strictEqual(answer1, true);
});

it('should call isSatisfyPattern, match for a single mathcer', () => {
const answer1 = utils.isIgnored('api.montreal.ca', url =>
url.endsWith('montreal.ca')
);
assert.strictEqual(answer1, true);
});

it('should not re-throw when function throws an exception', () => {
satisfiesPatternStub.restore();
const onException = (e: Error) => {
Expand Down

0 comments on commit 98d624c

Please sign in to comment.