Skip to content

Commit

Permalink
Replace inferred-spans extension with upstream contrib extension (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz authored Jan 10, 2025
1 parent c485453 commit 301c7be
Show file tree
Hide file tree
Showing 50 changed files with 197 additions and 11,726 deletions.
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
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

9 changes: 1 addition & 8 deletions inferred-spans/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
plugins {
id("elastic-otel.library-packaging-conventions")
id("elastic-otel.sign-and-publish-conventions")
}

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

0 comments on commit 301c7be

Please sign in to comment.