Skip to content

Commit 9f936e8

Browse files
authored
fix(bff): filter app configuration telemetry spans (#3788)
1 parent e3f94f4 commit 9f936e8

File tree

3 files changed

+66
-17
lines changed

3 files changed

+66
-17
lines changed

packages/bff/src/instrumentation.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ import {
2121
} from '@opentelemetry/sdk-trace-base';
2222
import { ATTR_SERVICE_NAME, SEMRESATTRS_SERVICE_INSTANCE_ID } from '@opentelemetry/semantic-conventions';
2323
import config from './config.ts';
24+
import { filterAppConfigSpans, filterGraphQLSpans } from './instrumentationFilters.ts';
2425

2526
const { openTelemetry } = config;
26-
const spansExcludedFromExport = new Set([
27-
'graphql.parse',
28-
'graphql.validate',
29-
'graphql.parseSchema',
30-
'graphql.validateSchema',
31-
]);
32-
33-
const shouldDropSpanByName = (spanName: string): boolean => {
34-
return spansExcludedFromExport.has(spanName);
27+
28+
const shouldDropSpan = (span: ReadableSpan): boolean => {
29+
return filterGraphQLSpans(span.name) || filterAppConfigSpans(span.attributes);
3530
};
3631

3732
// Configure HTTP instrumentation with filtering
@@ -48,13 +43,6 @@ const httpInstrumentationConfig: HttpInstrumentationConfig = {
4843
}
4944
return false;
5045
},
51-
ignoreOutgoingRequestHook: (request) => {
52-
// Ignore outgoing requests to Azure App Configuration
53-
if ((request.hostname ?? request.host)?.includes('appconfiguration.azconfig.io')) {
54-
return true;
55-
}
56-
return false;
57-
},
5846
};
5947

6048
// Configure instrumentations
@@ -84,7 +72,7 @@ class SpanNameFilteringProcessor implements SpanProcessor {
8472
}
8573

8674
onEnd(span: ReadableSpan): void {
87-
if (shouldDropSpanByName(span.name)) {
75+
if (shouldDropSpan(span)) {
8876
return;
8977
}
9078
this.delegate.onEnd(span);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const appConfigurationHostIdentifier = 'appconfiguration.azconfig.io';
2+
const graphqlSpansExcludedFromExport = new Set([
3+
'graphql.parse',
4+
'graphql.validate',
5+
'graphql.parseSchema',
6+
'graphql.validateSchema',
7+
]);
8+
9+
export const filterGraphQLSpans = (spanName: string): boolean => {
10+
return graphqlSpansExcludedFromExport.has(spanName);
11+
};
12+
13+
export const filterAppConfigSpans = (attributes: Record<string, unknown>): boolean => {
14+
const httpHost = attributes['http.host'];
15+
if (typeof httpHost !== 'string') {
16+
return false;
17+
}
18+
19+
return httpHost.toLowerCase().includes(appConfigurationHostIdentifier);
20+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { filterAppConfigSpans, filterGraphQLSpans } from '../src/instrumentationFilters.ts';
3+
4+
describe('filterGraphQLSpans', () => {
5+
it('returns true for internal GraphQL parse and validation spans', () => {
6+
expect(filterGraphQLSpans('graphql.parse')).toBe(true);
7+
expect(filterGraphQLSpans('graphql.validate')).toBe(true);
8+
expect(filterGraphQLSpans('graphql.parseSchema')).toBe(true);
9+
expect(filterGraphQLSpans('graphql.validateSchema')).toBe(true);
10+
});
11+
12+
it('returns false for other span names', () => {
13+
expect(filterGraphQLSpans('http GET')).toBe(false);
14+
});
15+
});
16+
17+
describe('filterAppConfigSpans', () => {
18+
it('returns true for spans with app configuration host attributes', () => {
19+
expect(
20+
filterAppConfigSpans({
21+
'http.host': 'dp-fe-staging-appconfiguration.azconfig.io:443',
22+
}),
23+
).toBe(true);
24+
});
25+
26+
it('returns false when http.host is missing', () => {
27+
expect(
28+
filterAppConfigSpans({
29+
'http.url': 'https://dp-fe-staging-appconfiguration.azconfig.io/kv?api-version=2023-11-01',
30+
}),
31+
).toBe(false);
32+
});
33+
34+
it('returns false for spans without app configuration host attributes', () => {
35+
expect(
36+
filterAppConfigSpans({
37+
'http.host': 'example.com',
38+
}),
39+
).toBe(false);
40+
});
41+
});

0 commit comments

Comments
 (0)