Skip to content
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

Replace inferred-spans extension with upstream contrib extension #370

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public interface ElasticAttributes {
AttributeKey<String> SPAN_TYPE = AttributeKey.stringKey("elastic.span.type");
AttributeKey<String> SPAN_SUBTYPE = AttributeKey.stringKey("elastic.span.subtype");

/** Marker attribute for inferred spans. */
AttributeKey<Boolean> IS_INFERRED = AttributeKey.booleanKey("elastic.is_inferred");

/** Used as marker on span-links to override the parent-child relationship for inferred spans. */
AttributeKey<Boolean> IS_CHILD = AttributeKey.booleanKey("elastic.is_child");
/**
* Marker attribute for inferred spans. Does not have the elastic-prefix anymore because it has
* been contributed upstream
*/
AttributeKey<Boolean> IS_INFERRED = AttributeKey.booleanKey("is_inferred");

AttributeKey<List<String>> PROFILER_STACK_TRACE_IDS =
AttributeKey.stringArrayKey("elastic.profiler_stack_trace_ids");
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ opentelemetryJavaagentAlpha = "2.10.0-alpha"

# otel contrib
# updated from upstream agent with .ci/update-upstream.sh
opentelemetryContribAlpha = "1.40.0-alpha"
opentelemetryContribAlpha = "1.41.0-alpha"

# otel semconv
# updated from upstream agent with .ci/update-upstream.sh
Expand All @@ -33,6 +33,7 @@ awsContribResources = { group = "io.opentelemetry.contrib", name = "opentelemetr
gcpContribResources = { group = "io.opentelemetry.contrib", name = "opentelemetry-gcp-resources", version.ref = "opentelemetryContribAlpha" }
contribResources = { group = "io.opentelemetry.contrib", name = "opentelemetry-resource-providers", version.ref = "opentelemetryContribAlpha" }
contribSpanStacktrace = { group = "io.opentelemetry.contrib", name = "opentelemetry-span-stacktrace", version.ref = "opentelemetryContribAlpha" }
contribInferredSpans = { group = "io.opentelemetry.contrib", name = "opentelemetry-inferred-spans", version.ref = "opentelemetryContribAlpha" }

opentelemetrySemconv = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv", version.ref = "opentelemetrySemconvAlpha"}
opentelemetrySemconvIncubating = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv-incubating", version.ref = "opentelemetrySemconvAlpha"}
Expand Down
198 changes: 3 additions & 195 deletions inferred-spans/README.md

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions inferred-spans/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@ description = "Elastic Inferred Spans extension for OpenTelemetry Java"
dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk")
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
implementation(libs.lmax.disruptor)
implementation(libs.jctools)
implementation(libs.asyncprofiler)
implementation(libs.bundles.semconv)
implementation(project(":common"))
implementation(libs.contribInferredSpans)

testImplementation(project(":testing-common"))
testImplementation("io.opentelemetry:opentelemetry-sdk")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
testImplementation(libs.github.api)
testImplementation(libs.apachecommons.compress)
testImplementation(libs.bundles.semconv)
}

Expand Down
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);
}
}
}
Loading
Loading