Skip to content

Commit 4871fbd

Browse files
committed
update the way we validate scope
1 parent 7aeb07c commit 4871fbd

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/parsers/MetricParser.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* This class is responsible for parsing metric files from the `.telemetry` directory of an
2121
* instrumentation module and filtering them by scope.
2222
*/
23-
public class MetricParser extends TelemetryParser {
23+
public class MetricParser {
2424

2525
/**
2626
* Retrieves metrics for a given instrumentation module, filtered by scope.
@@ -109,10 +109,7 @@ public static Map<String, Map<String, AggregatedMetricInfo>> aggregateMetrics(
109109
aggregatedMetrics.computeIfAbsent(when, k -> new HashMap<>());
110110

111111
for (EmittedMetrics.MetricsByScope metricsByScope : metrics.getMetricsByScope()) {
112-
if (metricsByScope.getScope().equals(targetScopeName)
113-
|| scopeAllowList
114-
.getOrDefault(targetScopeName, Set.of())
115-
.contains(metricsByScope.getScope())) {
112+
if (TelemetryParser.scopeIsValid(metricsByScope.getScope(), targetScopeName)) {
116113
for (EmittedMetrics.Metric metric : metricsByScope.getMetrics()) {
117114
AggregatedMetricInfo aggInfo =
118115
metricKindMap.computeIfAbsent(

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/parsers/SpanParser.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* This class is responsible for parsing span files from the `.telemetry` directory of an
2222
* instrumentation module and filtering them by scope.
2323
*/
24-
public class SpanParser extends TelemetryParser {
24+
public class SpanParser {
2525

2626
// We want to ignore test related attributes
2727
private static final List<String> EXCLUDED_ATTRIBUTES =
@@ -87,10 +87,7 @@ public static Map<String, Map<String, Set<TelemetryAttribute>>> aggregateSpans(
8787
aggregatedAttributes.computeIfAbsent(when, k -> new HashMap<>());
8888

8989
for (EmittedSpans.SpansByScope spansByScope : spans.getSpansByScope()) {
90-
if (spansByScope.getScope().equals(targetScopeName)
91-
|| scopeAllowList
92-
.getOrDefault(targetScopeName, Set.of())
93-
.contains(spansByScope.getScope())) {
90+
if (TelemetryParser.scopeIsValid(spansByScope.getScope(), targetScopeName)) {
9491
processSpansForScope(spansByScope, spanKindMap);
9592
}
9693
}

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/parsers/TelemetryParser.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@
88
import java.util.Map;
99
import java.util.Set;
1010

11-
abstract class TelemetryParser {
11+
class TelemetryParser {
1212

13-
// If an instrumentation module uses an instrumenter or telemetry class from another module, it
14-
// might report telemetry with a different scope name, resulting in us excluding it. There are
15-
// cases where we want to include this data, so we provide this way to override that exclusion
16-
// filter. The key is the scope of the module being analyzed, the value is a set of additional
17-
// allowed scopes.
18-
protected static final Map<String, Set<String>> scopeAllowList =
13+
// Key is the scope of the module being analyzed, value is a set of additional allowed scopes.
14+
private static final Map<String, Set<String>> scopeAllowList =
1915
Map.of("io.opentelemetry.armeria-grpc-1.14", Set.of("io.opentelemetry.grpc-1.6"));
16+
17+
/**
18+
* Checks if the given telemetry scope is valid for the specified module scope.
19+
*
20+
* <p>If an instrumentation module uses an instrumenter or telemetry class from another module, it
21+
* might report telemetry with a different scope name, resulting in us excluding it. There are
22+
* cases where we want to include this data, so we provide this way to override that exclusion
23+
* filter.
24+
*
25+
* @param telemetryScope the scope of the telemetry signal
26+
* @param moduleScope the scope of the module being analyzed
27+
* @return true if the telemetry scope is valid for the module, false otherwise
28+
*/
29+
static boolean scopeIsValid(String telemetryScope, String moduleScope) {
30+
return telemetryScope.equals(moduleScope)
31+
|| scopeAllowList.getOrDefault(moduleScope, Set.of()).contains(telemetryScope);
32+
}
33+
34+
private TelemetryParser() {}
2035
}

0 commit comments

Comments
 (0)