-
Notifications
You must be signed in to change notification settings - Fork 169
declarative config: support Inferred spans #2030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeitlinger
wants to merge
36
commits into
open-telemetry:main
Choose a base branch
from
zeitlinger:inferred-spans
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
039f678
add property translation for inferred spans
zeitlinger 54bd193
inferred spans
zeitlinger 276565a
inferred spans
zeitlinger 04b1e2b
inferred spans
zeitlinger c622bd4
format
zeitlinger 00c4eb5
fix
zeitlinger 135cacd
make temp dir more reliable
zeitlinger f410aac
make temp dir more reliable
zeitlinger 06039b6
test starts async profiler (?)
zeitlinger c2f1506
Revert "test starts async profiler (?)"
zeitlinger d91072b
leave profiler disabled in test
zeitlinger a297c8e
leave profiler disabled in test
zeitlinger 60728e5
copy declarative config from agent
zeitlinger 67d599f
fix
zeitlinger e49832b
fix package
zeitlinger 2e90880
update file format
zeitlinger 6ccd8ee
add comment
zeitlinger 5873f2e
extract common class
zeitlinger a5d2d60
add description and owner of the declarative config bridge
zeitlinger 11f5d80
./gradlew spotlessApply
otelbot[bot] ba16ddf
add description and owner of the declarative config bridge
zeitlinger 05eeaf8
move bridge to agent
zeitlinger c66298b
rebase
zeitlinger 4ddb381
update
zeitlinger 559f501
update
zeitlinger eca9228
readme
zeitlinger 6b2f57e
./gradlew spotlessApply
otelbot[bot] 0baba1e
lint
zeitlinger 69a9ba0
fix processor name
zeitlinger 13584b5
./gradlew spotlessApply
otelbot[bot] 775e311
pr review
zeitlinger 614903c
add enabled
zeitlinger b527dfe
add enabled
zeitlinger d8faf6e
fix processor name
zeitlinger dfd975e
fix
zeitlinger 58c4300
fix
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
inferred-spans/src/main/java/io/opentelemetry/contrib/inferredspans/InferredSpansConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.contrib.inferredspans; | ||
|
|
||
| import static java.util.Collections.unmodifiableList; | ||
| import static java.util.stream.Collectors.toList; | ||
|
|
||
| import io.opentelemetry.api.trace.SpanBuilder; | ||
| import io.opentelemetry.api.trace.SpanContext; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.trace.SpanProcessor; | ||
| import java.time.Duration; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.function.BiConsumer; | ||
| import java.util.function.Consumer; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| class InferredSpansConfig { | ||
|
|
||
| private InferredSpansConfig() {} | ||
|
|
||
| static final String ENABLED_OPTION = "otel.inferred.spans.enabled"; | ||
| static final String LOGGING_OPTION = "otel.inferred.spans.logging.enabled"; | ||
| static final String DIAGNOSTIC_FILES_OPTION = "otel.inferred.spans.backup.diagnostic.files"; | ||
| static final String SAFEMODE_OPTION = "otel.inferred.spans.safe.mode"; | ||
| static final String POSTPROCESSING_OPTION = "otel.inferred.spans.post.processing.enabled"; | ||
| static final String SAMPLING_INTERVAL_OPTION = "otel.inferred.spans.sampling.interval"; | ||
| static final String MIN_DURATION_OPTION = "otel.inferred.spans.min.duration"; | ||
| static final String INCLUDED_CLASSES_OPTION = "otel.inferred.spans.included.classes"; | ||
| static final String EXCLUDED_CLASSES_OPTION = "otel.inferred.spans.excluded.classes"; | ||
| static final String INTERVAL_OPTION = "otel.inferred.spans.interval"; | ||
| static final String DURATION_OPTION = "otel.inferred.spans.duration"; | ||
| static final String LIB_DIRECTORY_OPTION = "otel.inferred.spans.lib.directory"; | ||
| static final String PARENT_OVERRIDE_HANDLER_OPTION = | ||
| "otel.inferred.spans.parent.override.handler"; | ||
|
|
||
| static final List<String> ALL_PROPERTIES = | ||
| unmodifiableList( | ||
| Arrays.asList( | ||
| ENABLED_OPTION, | ||
| LOGGING_OPTION, | ||
| DIAGNOSTIC_FILES_OPTION, | ||
| SAFEMODE_OPTION, | ||
| POSTPROCESSING_OPTION, | ||
| SAMPLING_INTERVAL_OPTION, | ||
| MIN_DURATION_OPTION, | ||
| INCLUDED_CLASSES_OPTION, | ||
| EXCLUDED_CLASSES_OPTION, | ||
| INTERVAL_OPTION, | ||
| DURATION_OPTION, | ||
| LIB_DIRECTORY_OPTION, | ||
| PARENT_OVERRIDE_HANDLER_OPTION)); | ||
|
|
||
| static SpanProcessor createSpanProcessor(ConfigProperties properties) { | ||
| InferredSpansProcessorBuilder builder = InferredSpansProcessor.builder().profilerEnabled(true); | ||
|
|
||
| PropertiesApplier applier = new PropertiesApplier(properties); | ||
|
|
||
| applier.applyBool(LOGGING_OPTION, builder::profilerLoggingEnabled); | ||
| applier.applyBool(DIAGNOSTIC_FILES_OPTION, builder::backupDiagnosticFiles); | ||
| applier.applyInt(SAFEMODE_OPTION, builder::asyncProfilerSafeMode); | ||
| applier.applyBool(POSTPROCESSING_OPTION, builder::postProcessingEnabled); | ||
| applier.applyDuration(SAMPLING_INTERVAL_OPTION, builder::samplingInterval); | ||
| applier.applyDuration(MIN_DURATION_OPTION, builder::inferredSpansMinDuration); | ||
| applier.applyWildcards(INCLUDED_CLASSES_OPTION, builder::includedClasses); | ||
| applier.applyWildcards(EXCLUDED_CLASSES_OPTION, builder::excludedClasses); | ||
| applier.applyDuration(INTERVAL_OPTION, builder::profilerInterval); | ||
| applier.applyDuration(DURATION_OPTION, builder::profilingDuration); | ||
| applier.applyString(LIB_DIRECTORY_OPTION, builder::profilerLibDirectory); | ||
|
|
||
| String parentOverrideHandlerName = properties.getString(PARENT_OVERRIDE_HANDLER_OPTION); | ||
| if (parentOverrideHandlerName != null && !parentOverrideHandlerName.isEmpty()) { | ||
| builder.parentOverrideHandler(constructParentOverrideHandler(parentOverrideHandlerName)); | ||
| } | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static BiConsumer<SpanBuilder, SpanContext> constructParentOverrideHandler(String name) { | ||
| try { | ||
| Class<?> clazz = Class.forName(name); | ||
| return (BiConsumer<SpanBuilder, SpanContext>) clazz.getConstructor().newInstance(); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException("Could not construct parent override handler", e); | ||
| } | ||
| } | ||
|
|
||
| private static class PropertiesApplier { | ||
|
|
||
| private final ConfigProperties properties; | ||
|
|
||
| PropertiesApplier(ConfigProperties properties) { | ||
| this.properties = properties; | ||
| } | ||
|
|
||
| void applyBool(String configKey, Consumer<Boolean> funcToApply) { | ||
| applyValue(properties.getBoolean(configKey), funcToApply); | ||
| } | ||
|
|
||
| void applyInt(String configKey, Consumer<Integer> funcToApply) { | ||
| applyValue(properties.getInt(configKey), funcToApply); | ||
| } | ||
|
|
||
| void applyDuration(String configKey, Consumer<Duration> funcToApply) { | ||
| applyValue(properties.getDuration(configKey), funcToApply); | ||
| } | ||
|
|
||
| void applyString(String configKey, Consumer<String> funcToApply) { | ||
| applyValue(properties.getString(configKey), funcToApply); | ||
| } | ||
|
|
||
| void applyWildcards(String configKey, Consumer<? super List<WildcardMatcher>> funcToApply) { | ||
| String wildcardListString = properties.getString(configKey); | ||
| if (wildcardListString != null && !wildcardListString.isEmpty()) { | ||
| List<WildcardMatcher> values = | ||
| Arrays.stream(wildcardListString.split(",")) | ||
| .filter(str -> !str.isEmpty()) | ||
| .map(WildcardMatcher::valueOf) | ||
| .collect(toList()); | ||
| if (!values.isEmpty()) { | ||
| funcToApply.accept(values); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static <T> void applyValue(@Nullable T value, Consumer<T> funcToApply) { | ||
| if (value != null) { | ||
| funcToApply.accept(value); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.