Skip to content

Commit

Permalink
@robsunday PR with upstream updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge committed Sep 17, 2024
1 parent 5a82aac commit d623abe
Show file tree
Hide file tree
Showing 83 changed files with 3,158 additions and 388 deletions.
5 changes: 5 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ components:
- sfriberg
jmx-metrics:
- breedx-splk
jmx-scraper:
- breedx-splk
- robsunday
- sylvainjuge
maven-extension:
- cyrille-leclerc
- kenfinnigan
Expand All @@ -61,6 +65,7 @@ components:
- jeanbisutti
samplers:
- trask
- jack-berg
static-instrumenter:
- anosek-an
kafka-exporter:
Expand Down
2 changes: 2 additions & 0 deletions aws-xray-propagator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ dependencies {
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
testImplementation("io.opentelemetry:opentelemetry-sdk-trace")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")

testImplementation("io.opentelemetry:opentelemetry-sdk-extension-incubator")
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.0.3")
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
MapGetter.INSTANCE);
}

@Override
public String toString() {
return "AwsXrayLambdaPropagator";
}

private static boolean isEmptyOrNull(@Nullable String value) {
return value == null || value.isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
return getContextFromHeader(context, carrier, getter);
}

@Override
public String toString() {
return "AwsXrayPropagator";
}

private static <C> Context getContextFromHeader(
Context context, @Nullable C carrier, TextMapGetter<C> getter) {
String traceHeader = getter.get(carrier, TRACE_HEADER_KEY);
Expand Down Expand Up @@ -290,7 +295,8 @@ private static String parseShortTraceId(String xrayTraceId) {
int secondDelimiter = xrayTraceId.indexOf(TRACE_ID_DELIMITER, firstDelimiter + 2);
if (firstDelimiter != TRACE_ID_DELIMITER_INDEX_1
|| secondDelimiter == -1
|| secondDelimiter > TRACE_ID_DELIMITER_INDEX_2) {
|| secondDelimiter > TRACE_ID_DELIMITER_INDEX_2
|| xrayTraceId.length() < secondDelimiter + 25) {
return TraceId.getInvalid();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator;
package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;

public class AwsXrayComponentProvider implements ComponentProvider<TextMapPropagator> {
@Override
public Class<TextMapPropagator> getType() {
return TextMapPropagator.class;
}

@Override
public String getName() {
return "xray";
}

@Override
public TextMapPropagator create(StructuredConfigProperties config) {
return AwsXrayPropagator.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;

public class AwsXrayLambdaComponentProvider implements ComponentProvider<TextMapPropagator> {
@Override
public Class<TextMapPropagator> getType() {
return TextMapPropagator.class;
}

@Override
public String getName() {
return "xray-lambda";
}

@Override
public TextMapPropagator create(StructuredConfigProperties config) {
return AwsXrayLambdaPropagator.getInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator;
package io.opentelemetry.contrib.awsxray.propagator.internal;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.opentelemetry.contrib.awsxray.propagator.AwsConfigurablePropagator
io.opentelemetry.contrib.awsxray.propagator.internal.AwsConfigurablePropagator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
io.opentelemetry.contrib.awsxray.propagator.internal.AwsXrayComponentProvider
io.opentelemetry.contrib.awsxray.propagator.internal.AwsXrayLambdaComponentProvider
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void extract_InvalidTraceId() {
}

@Test
void extract_InvalidTraceId_Size() {
void extract_InvalidTraceId_Size_TooBig() {
Map<String, String> invalidHeaders = new LinkedHashMap<>();
invalidHeaders.put(
TRACE_HEADER_KEY,
Expand All @@ -306,6 +306,16 @@ void extract_InvalidTraceId_Size() {
verifyInvalidBehavior(invalidHeaders);
}

@Test
void extract_InvalidTraceId_Size_TooShort() {
Map<String, String> invalidHeaders = new LinkedHashMap<>();
invalidHeaders.put(
TRACE_HEADER_KEY,
"Root=1-64fbd5a9-2202432c9dfed25ae1e6996;Parent=53995c3f42cd8ad8;Sampled=0");

verifyInvalidBehavior(invalidHeaders);
}

@Test
void extract_InvalidSpanId() {
Map<String, String> invalidHeaders = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.awsxray.propagator.internal;

import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayLambdaPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfiguration;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class AwsComponentProviderTest {

@Test
void endToEnd() {
String yaml = "file_format: 0.1\n" + "propagator:\n" + " composite: [xray, xray-lambda]\n";

OpenTelemetrySdk openTelemetrySdk =
FileConfiguration.parseAndCreate(
new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
TextMapPropagator expectedPropagator =
TextMapPropagator.composite(
AwsXrayPropagator.getInstance(), AwsXrayLambdaPropagator.getInstance());
assertThat(openTelemetrySdk.getPropagators().getTextMapPropagator().toString())
.isEqualTo(expectedPropagator.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.logging.Level;
Expand All @@ -40,7 +41,6 @@ public final class AwsXrayRemoteSampler implements Sampler, Closeable {

static final long DEFAULT_TARGET_INTERVAL_NANOS = TimeUnit.SECONDS.toNanos(10);

private static final Random RANDOM = new Random();
private static final Logger logger = Logger.getLogger(AwsXrayRemoteSampler.class.getName());

private final Resource resource;
Expand Down Expand Up @@ -97,7 +97,7 @@ public static AwsXrayRemoteSamplerBuilder newBuilder(Resource resource) {

this.pollingIntervalNanos = pollingIntervalNanos;
// Add ~1% of jitter
jitterNanos = RANDOM.longs(0, pollingIntervalNanos / 100).iterator();
jitterNanos = ThreadLocalRandom.current().longs(0, pollingIntervalNanos / 100).iterator();

// Execute first update right away on the executor thread.
executor.execute(this::getAndUpdateSampler);
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")
implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.0.1")
implementation("net.ltgt.gradle:gradle-nullaway-plugin:2.0.0")
implementation("com.gradle.enterprise:com.gradle.enterprise.gradle.plugin:3.18")
implementation("com.gradle.enterprise:com.gradle.enterprise.gradle.plugin:3.18.1")
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.sampler.consistent56;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.LinkData;
import java.util.List;

/** An interface for components to be used by composite consistent probability samplers. */
public interface ComposableSampler {

/**
* Returns the SamplingIntent that is used for the sampling decision. The SamplingIntent includes
* the threshold value which will be used for the sampling decision.
*
* <p>NOTE: Keep in mind, that in any case the returned threshold value must not depend directly
* or indirectly on the random value. In particular this means that the parent sampled flag must
* not be used for the calculation of the threshold as the sampled flag depends itself on the
* random value.
*/
SamplingIntent getSamplingIntent(
Context parentContext,
String name,
SpanKind spanKind,
Attributes attributes,
List<LinkData> parentLinks);

/** Return the string providing a description of the implementation. */
String getDescription();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

package io.opentelemetry.contrib.sampler.consistent56;

import static io.opentelemetry.contrib.sampler.consistent56.ConsistentSamplingUtil.getInvalidThreshold;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.LinkData;
import java.util.List;
import javax.annotation.concurrent.Immutable;

@Immutable
Expand All @@ -19,8 +26,14 @@ static ConsistentAlwaysOffSampler getInstance() {
}

@Override
protected long getThreshold(long parentThreshold, boolean isRoot) {
return ConsistentSamplingUtil.getMaxThreshold();
public SamplingIntent getSamplingIntent(
Context parentContext,
String name,
SpanKind spanKind,
Attributes attributes,
List<LinkData> parentLinks) {

return () -> getInvalidThreshold();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import static io.opentelemetry.contrib.sampler.consistent56.ConsistentSamplingUtil.getMinThreshold;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.LinkData;
import java.util.List;
import javax.annotation.concurrent.Immutable;

@Immutable
Expand All @@ -21,8 +26,14 @@ static ConsistentAlwaysOnSampler getInstance() {
}

@Override
protected long getThreshold(long parentThreshold, boolean isRoot) {
return getMinThreshold();
public SamplingIntent getSamplingIntent(
Context parentContext,
String name,
SpanKind spanKind,
Attributes attributes,
List<LinkData> parentLinks) {

return () -> getMinThreshold();
}

@Override
Expand Down
Loading

0 comments on commit d623abe

Please sign in to comment.