Skip to content

Commit 301c7be

Browse files
authored
Replace inferred-spans extension with upstream contrib extension (#370)
1 parent c485453 commit 301c7be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+197
-11726
lines changed

common/src/main/java/co/elastic/otel/common/ElasticAttributes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public interface ElasticAttributes {
3030
AttributeKey<String> SPAN_TYPE = AttributeKey.stringKey("elastic.span.type");
3131
AttributeKey<String> SPAN_SUBTYPE = AttributeKey.stringKey("elastic.span.subtype");
3232

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

3939
AttributeKey<List<String>> PROFILER_STACK_TRACE_IDS =
4040
AttributeKey.stringArrayKey("elastic.profiler_stack_trace_ids");

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ awsContribResources = { group = "io.opentelemetry.contrib", name = "opentelemetr
3333
gcpContribResources = { group = "io.opentelemetry.contrib", name = "opentelemetry-gcp-resources", version.ref = "opentelemetryContribAlpha" }
3434
contribResources = { group = "io.opentelemetry.contrib", name = "opentelemetry-resource-providers", version.ref = "opentelemetryContribAlpha" }
3535
contribSpanStacktrace = { group = "io.opentelemetry.contrib", name = "opentelemetry-span-stacktrace", version.ref = "opentelemetryContribAlpha" }
36+
contribInferredSpans = { group = "io.opentelemetry.contrib", name = "opentelemetry-inferred-spans", version.ref = "opentelemetryContribAlpha" }
3637

3738
opentelemetrySemconv = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv", version.ref = "opentelemetrySemconvAlpha"}
3839
opentelemetrySemconvIncubating = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv-incubating", version.ref = "opentelemetrySemconvAlpha"}

inferred-spans/README.md

Lines changed: 3 additions & 195 deletions
Large diffs are not rendered by default.

inferred-spans/build.gradle.kts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
plugins {
22
id("elastic-otel.library-packaging-conventions")
3-
id("elastic-otel.sign-and-publish-conventions")
43
}
54

65
description = "Elastic Inferred Spans extension for OpenTelemetry Java"
76

87
dependencies {
98
compileOnly("io.opentelemetry:opentelemetry-sdk")
109
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
11-
implementation(libs.lmax.disruptor)
12-
implementation(libs.jctools)
13-
implementation(libs.asyncprofiler)
14-
implementation(libs.bundles.semconv)
15-
implementation(project(":common"))
10+
implementation(libs.contribInferredSpans)
1611

1712
testImplementation(project(":testing-common"))
1813
testImplementation("io.opentelemetry:opentelemetry-sdk")
1914
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
20-
testImplementation(libs.github.api)
21-
testImplementation(libs.apachecommons.compress)
2215
testImplementation(libs.bundles.semconv)
2316
}
2417

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package co.elastic.otel;
20+
21+
import com.google.auto.service.AutoService;
22+
import io.opentelemetry.api.common.AttributeKey;
23+
import io.opentelemetry.api.common.Attributes;
24+
import io.opentelemetry.api.trace.SpanBuilder;
25+
import io.opentelemetry.api.trace.SpanContext;
26+
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
27+
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
import java.util.function.BiConsumer;
31+
import java.util.logging.Level;
32+
import java.util.logging.Logger;
33+
34+
@AutoService(AutoConfigurationCustomizerProvider.class)
35+
public class InferredSpansBackwardsCompatibilityConfig
36+
implements AutoConfigurationCustomizerProvider {
37+
38+
private static final Logger log =
39+
Logger.getLogger(InferredSpansBackwardsCompatibilityConfig.class.getName());
40+
41+
private static final Map<String, String> CONFIG_MAPPING = new HashMap<>();
42+
43+
static {
44+
CONFIG_MAPPING.put("elastic.otel.inferred.spans.enabled", "otel.inferred.spans.enabled");
45+
CONFIG_MAPPING.put(
46+
"elastic.otel.inferred.spans.logging.enabled", "otel.inferred.spans.logging.enabled");
47+
CONFIG_MAPPING.put(
48+
"elastic.otel.inferred.spans.backup.diagnostic.files",
49+
"otel.inferred.spans.backup.diagnostic.files");
50+
CONFIG_MAPPING.put("elastic.otel.inferred.spans.safe.mode", "otel.inferred.spans.safe.mode");
51+
CONFIG_MAPPING.put(
52+
"elastic.otel.inferred.spans.post.processing.enabled",
53+
"otel.inferred.spans.post.processing.enabled");
54+
CONFIG_MAPPING.put(
55+
"elastic.otel.inferred.spans.sampling.interval", "otel.inferred.spans.sampling.interval");
56+
CONFIG_MAPPING.put(
57+
"elastic.otel.inferred.spans.min.duration", "otel.inferred.spans.min.duration");
58+
CONFIG_MAPPING.put(
59+
"elastic.otel.inferred.spans.included.classes", "otel.inferred.spans.included.classes");
60+
CONFIG_MAPPING.put(
61+
"elastic.otel.inferred.spans.excluded.classes", "otel.inferred.spans.excluded.classes");
62+
CONFIG_MAPPING.put("elastic.otel.inferred.spans.interval", "otel.inferred.spans.interval");
63+
CONFIG_MAPPING.put("elastic.otel.inferred.spans.duration", "otel.inferred.spans.duration");
64+
CONFIG_MAPPING.put(
65+
"elastic.otel.inferred.spans.lib.directory", "otel.inferred.spans.lib.directory");
66+
}
67+
68+
@Override
69+
public void customize(AutoConfigurationCustomizer config) {
70+
config.addPropertiesCustomizer(
71+
props -> {
72+
Map<String, String> overrides = new HashMap<>();
73+
for (String oldKey : CONFIG_MAPPING.keySet()) {
74+
String value = props.getString(oldKey);
75+
if (value != null) {
76+
String newKey = CONFIG_MAPPING.get(oldKey);
77+
if (props.getString(newKey) == null) { // new value has not been configured
78+
log.log(
79+
Level.WARNING,
80+
"The configuration property {0} is deprecated, use {1} instead",
81+
new Object[] {oldKey, newKey});
82+
overrides.put(newKey, value);
83+
}
84+
}
85+
}
86+
87+
String userDefinedHandler =
88+
props.getString("otel.inferred.spans.parent.override.handler");
89+
if (userDefinedHandler == null || userDefinedHandler.isEmpty()) {
90+
overrides.put(
91+
"otel.inferred.spans.parent.override.handler",
92+
BackwardsCompatibilitySpanLinkHandler.class.getName());
93+
}
94+
95+
return overrides;
96+
});
97+
}
98+
99+
public static class BackwardsCompatibilitySpanLinkHandler
100+
implements BiConsumer<SpanBuilder, SpanContext> {
101+
102+
private static final Attributes LINK_ATTRIBUTES =
103+
Attributes.of(
104+
AttributeKey.booleanKey("is_child"), true,
105+
AttributeKey.booleanKey("elastic.is_child"), true);
106+
107+
@Override
108+
public void accept(SpanBuilder spanBuilder, SpanContext spanContext) {
109+
spanBuilder.addLink(spanContext, LINK_ATTRIBUTES);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)