-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace inferred-spans extension with upstream contrib extension (#370)
- Loading branch information
Showing
50 changed files
with
197 additions
and
11,726 deletions.
There are no files selected for viewing
This file contains 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
112 changes: 112 additions & 0 deletions
112
inferred-spans/src/main/java/co/elastic/otel/InferredSpansBackwardsCompatibilityConfig.java
This file contains 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,112 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.otel; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.trace.SpanBuilder; | ||
import io.opentelemetry.api.trace.SpanContext; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
@AutoService(AutoConfigurationCustomizerProvider.class) | ||
public class InferredSpansBackwardsCompatibilityConfig | ||
implements AutoConfigurationCustomizerProvider { | ||
|
||
private static final Logger log = | ||
Logger.getLogger(InferredSpansBackwardsCompatibilityConfig.class.getName()); | ||
|
||
private static final Map<String, String> CONFIG_MAPPING = new HashMap<>(); | ||
|
||
static { | ||
CONFIG_MAPPING.put("elastic.otel.inferred.spans.enabled", "otel.inferred.spans.enabled"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.logging.enabled", "otel.inferred.spans.logging.enabled"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.backup.diagnostic.files", | ||
"otel.inferred.spans.backup.diagnostic.files"); | ||
CONFIG_MAPPING.put("elastic.otel.inferred.spans.safe.mode", "otel.inferred.spans.safe.mode"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.post.processing.enabled", | ||
"otel.inferred.spans.post.processing.enabled"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.sampling.interval", "otel.inferred.spans.sampling.interval"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.min.duration", "otel.inferred.spans.min.duration"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.included.classes", "otel.inferred.spans.included.classes"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.excluded.classes", "otel.inferred.spans.excluded.classes"); | ||
CONFIG_MAPPING.put("elastic.otel.inferred.spans.interval", "otel.inferred.spans.interval"); | ||
CONFIG_MAPPING.put("elastic.otel.inferred.spans.duration", "otel.inferred.spans.duration"); | ||
CONFIG_MAPPING.put( | ||
"elastic.otel.inferred.spans.lib.directory", "otel.inferred.spans.lib.directory"); | ||
} | ||
|
||
@Override | ||
public void customize(AutoConfigurationCustomizer config) { | ||
config.addPropertiesCustomizer( | ||
props -> { | ||
Map<String, String> overrides = new HashMap<>(); | ||
for (String oldKey : CONFIG_MAPPING.keySet()) { | ||
String value = props.getString(oldKey); | ||
if (value != null) { | ||
String newKey = CONFIG_MAPPING.get(oldKey); | ||
if (props.getString(newKey) == null) { // new value has not been configured | ||
log.log( | ||
Level.WARNING, | ||
"The configuration property {0} is deprecated, use {1} instead", | ||
new Object[] {oldKey, newKey}); | ||
overrides.put(newKey, value); | ||
} | ||
} | ||
} | ||
|
||
String userDefinedHandler = | ||
props.getString("otel.inferred.spans.parent.override.handler"); | ||
if (userDefinedHandler == null || userDefinedHandler.isEmpty()) { | ||
overrides.put( | ||
"otel.inferred.spans.parent.override.handler", | ||
BackwardsCompatibilitySpanLinkHandler.class.getName()); | ||
} | ||
|
||
return overrides; | ||
}); | ||
} | ||
|
||
public static class BackwardsCompatibilitySpanLinkHandler | ||
implements BiConsumer<SpanBuilder, SpanContext> { | ||
|
||
private static final Attributes LINK_ATTRIBUTES = | ||
Attributes.of( | ||
AttributeKey.booleanKey("is_child"), true, | ||
AttributeKey.booleanKey("elastic.is_child"), true); | ||
|
||
@Override | ||
public void accept(SpanBuilder spanBuilder, SpanContext spanContext) { | ||
spanBuilder.addLink(spanContext, LINK_ATTRIBUTES); | ||
} | ||
} | ||
} |
Oops, something went wrong.