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

demo #1

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
package io.opentelemetry.contrib.inferredspans;

import com.google.auto.service.AutoService;
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 io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.ServiceLoader;
import java.util.function.Consumer;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -76,14 +76,14 @@ public void customize(AutoConfigurationCustomizer config) {
});
}

@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 ParentOverrideHandler constructParentOverrideHandler(String name) {
for (ComponentProvider<?> componentProvider : ServiceLoader.load(ComponentProvider.class)) {
if (componentProvider.getType().equals(ParentOverrideHandler.class)
&& componentProvider.getName().equals(name)) {
return (ParentOverrideHandler) componentProvider.create(StructuredConfigProperties.empty());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the trick I was missing: I didn't think of simply passing empty StructuredConfigProperties here, that's why I though we need to hook entirely into declarative config process.

}
}
throw new IllegalArgumentException("Could not find parent override handler: " + name);
}

private static class PropertiesApplier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@

package io.opentelemetry.contrib.inferredspans;

import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.contrib.inferredspans.internal.CallTree;
import io.opentelemetry.contrib.inferredspans.internal.InferredSpansConfiguration;
import io.opentelemetry.contrib.inferredspans.internal.SpanAnchoredClock;
import java.io.File;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;

@SuppressWarnings("CanIgnoreReturnValueSuggester")
Expand Down Expand Up @@ -52,7 +49,7 @@ public class InferredSpansProcessorBuilder {

@Nullable private File activationEventsFile = null;
@Nullable private File jfrFile = null;
private BiConsumer<SpanBuilder, SpanContext> parentOverrideHandler =
private ParentOverrideHandler parentOverrideHandler =
CallTree.DEFAULT_PARENT_OVERRIDE;

InferredSpansProcessorBuilder() {}
Expand Down Expand Up @@ -204,7 +201,7 @@ InferredSpansProcessorBuilder jfrFile(@Nullable File jfrFile) {
* relationship.
*/
InferredSpansProcessorBuilder parentOverrideHandler(
BiConsumer<SpanBuilder, SpanContext> handler) {
ParentOverrideHandler handler) {
this.parentOverrideHandler = handler;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.opentelemetry.contrib.inferredspans;

import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanContext;

@FunctionalInterface
public interface ParentOverrideHandler {

void setParent(SpanBuilder spanBuilder, SpanContext spanContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.contrib.inferredspans.ParentOverrideHandler;
import io.opentelemetry.contrib.inferredspans.internal.pooling.ObjectPool;
import io.opentelemetry.contrib.inferredspans.internal.pooling.Recyclable;
import io.opentelemetry.contrib.inferredspans.internal.util.HexUtils;
Expand All @@ -25,7 +26,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.agrona.collections.LongHashSet;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class CallTree implements Recyclable {
public static final Attributes CHILD_LINK_ATTRIBUTES =
Attributes.builder().put(LINK_IS_CHILD, true).build();

public static final BiConsumer<SpanBuilder, SpanContext> DEFAULT_PARENT_OVERRIDE =
public static final ParentOverrideHandler DEFAULT_PARENT_OVERRIDE =
(inferredSpan, child) -> inferredSpan.addLink(child, CHILD_LINK_ATTRIBUTES);

@Nullable private CallTree parent;
Expand Down Expand Up @@ -431,7 +431,7 @@ int spanify(
@Nullable Span parentSpan,
TraceContext parentContext,
SpanAnchoredClock clock,
BiConsumer<SpanBuilder, SpanContext> spanParentOverride,
ParentOverrideHandler spanParentOverride,
StringBuilder tempBuilder,
Tracer tracer) {
int createdSpans = 0;
Expand Down Expand Up @@ -469,7 +469,7 @@ protected Span asSpan(
TraceContext parentContext,
Tracer tracer,
SpanAnchoredClock clock,
BiConsumer<SpanBuilder, SpanContext> spanParentOverride,
ParentOverrideHandler spanParentOverride,
StringBuilder tempBuilder) {

Context parentOtelCtx;
Expand Down Expand Up @@ -529,7 +529,7 @@ private void insertChildIdLinks(
SpanBuilder span,
SpanContext parentContext,
TraceContext nonInferredParent,
BiConsumer<SpanBuilder, SpanContext> spanParentOverride,
ParentOverrideHandler spanParentOverride,
StringBuilder tempBuilder) {
if (childIds == null || childIds.isEmpty()) {
return;
Expand All @@ -546,7 +546,7 @@ private void insertChildIdLinks(
tempBuilder.toString(),
parentContext.getTraceFlags(),
parentContext.getTraceState());
spanParentOverride.accept(span, childSpanContext);
spanParentOverride.setParent(span, childSpanContext);
}
}
}
Expand Down Expand Up @@ -879,7 +879,7 @@ private static CallTree findCommonAncestor(CallTree previousTopOfStack, CallTree
public int spanify(
SpanAnchoredClock clock,
Tracer tracer,
BiConsumer<SpanBuilder, SpanContext> normalSpanOverride) {
ParentOverrideHandler normalSpanOverride) {
StringBuilder tempBuilder = new StringBuilder();
int createdSpans = 0;
List<CallTree> callTrees = getChildren();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

package io.opentelemetry.contrib.inferredspans.internal;

import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.contrib.inferredspans.ParentOverrideHandler;
import io.opentelemetry.contrib.inferredspans.WildcardMatcher;
import java.time.Duration;
import java.util.List;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;

public class InferredSpansConfiguration {
Expand All @@ -26,7 +24,7 @@ public class InferredSpansConfiguration {
private final Duration profilerInterval;
private final Duration profilingDuration;
@Nullable private final String profilerLibDirectory;
private final BiConsumer<SpanBuilder, SpanContext> parentOverrideHandler;
private final ParentOverrideHandler parentOverrideHandler;

@SuppressWarnings("TooManyParameters")
public InferredSpansConfiguration(
Expand All @@ -41,7 +39,7 @@ public InferredSpansConfiguration(
Duration profilerInterval,
Duration profilingDuration,
@Nullable String profilerLibDirectory,
BiConsumer<SpanBuilder, SpanContext> parentOverrideHandler) {
ParentOverrideHandler parentOverrideHandler) {
this.profilerLoggingEnabled = profilerLoggingEnabled;
this.backupDiagnosticFiles = backupDiagnosticFiles;
this.asyncProfilerSafeMode = asyncProfilerSafeMode;
Expand Down Expand Up @@ -106,7 +104,7 @@ public boolean isPostProcessingEnabled() {
return postProcessingEnabled;
}

public BiConsumer<SpanBuilder, SpanContext> getParentOverrideHandler() {
public ParentOverrideHandler getParentOverrideHandler() {
return parentOverrideHandler;
}
}
Loading