Skip to content

Commit 7a53357

Browse files
authored
Merge branch 'main' into modernize-junit
2 parents 36f656b + ff61b4a commit 7a53357

File tree

54 files changed

+3841
-140
lines changed

Some content is hidden

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

54 files changed

+3841
-140
lines changed

.github/component_owners.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ components:
2525
baggage-processor:
2626
- mikegoldsmith
2727
- zeitlinger
28+
cel-sampler:
29+
- dol
30+
- trask
31+
- jack-berg
32+
- breedx-splk
2833
cloudfoundry-resources:
2934
- KarstenSchnitter
3035
compressors:

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0
5151

5252
- name: Initialize CodeQL
53-
uses: github/codeql-action/init@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8
53+
uses: github/codeql-action/init@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
5454
with:
5555
languages: ${{ matrix.language }}
5656
# using "linked" helps to keep up with the latest Kotlin support
@@ -65,6 +65,6 @@ jobs:
6565
run: ./gradlew assemble --no-build-cache --no-daemon
6666

6767
- name: Perform CodeQL analysis
68-
uses: github/codeql-action/analyze@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8
68+
uses: github/codeql-action/analyze@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
6969
with:
7070
category: "/language:${{matrix.language}}"

.github/workflows/ossf-scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ jobs:
5252
# Upload the results to GitHub's code scanning dashboard (optional).
5353
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
5454
- name: "Upload to code-scanning"
55-
uses: github/codeql-action/upload-sarif@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8
55+
uses: github/codeql-action/upload-sarif@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
5656
with:
5757
sarif_file: results.sarif

.github/workflows/release.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
release:
1818
permissions:
1919
contents: write # for creating the release
20+
id-token: write # for signing artifacts with Sigstore
21+
attestations: write # for uploading attestations
2022
runs-on: ubuntu-latest
2123
needs:
2224
- common
@@ -152,16 +154,24 @@ jobs:
152154
.github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
153155
fi
154156
155-
- id: create-github-release
156-
name: Create GitHub release
157-
env:
158-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
- name: Simplify paths for attaching
159158
run: |
160159
cp jmx-metrics/build/libs/opentelemetry-jmx-metrics-$VERSION-alpha.jar opentelemetry-jmx-metrics.jar
161160
cp jmx-metrics/build/libs/opentelemetry-jmx-metrics-$VERSION-alpha.jar.asc opentelemetry-jmx-metrics.jar.asc
162161
cp jmx-scraper/build/libs/opentelemetry-jmx-scraper-$VERSION-alpha.jar opentelemetry-jmx-scraper.jar
163162
cp jmx-scraper/build/libs/opentelemetry-jmx-scraper-$VERSION-alpha.jar.asc opentelemetry-jmx-scraper.jar.asc
164-
163+
164+
- uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0
165+
with:
166+
subject-path: |
167+
opentelemetry-jmx-metrics.jar
168+
opentelemetry-jmx-scraper.jar
169+
170+
- id: create-github-release
171+
name: Create GitHub release
172+
env:
173+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174+
run: |
165175
gh release create --target $GITHUB_REF_NAME \
166176
--title "Version $VERSION" \
167177
--notes-file /tmp/release-notes.txt \

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ feature or via instrumentation, this project is hopefully for you.
2121
| alpha | [AWS X-Ray Propagator](./aws-xray-propagator/README.md) |
2222
| alpha | [Baggage Processors](./baggage-processor/README.md) |
2323
| alpha | [zstd Compressor](./compressors/compressor-zstd/README.md) |
24+
| alpha | [CEL-Based Sampler](./cel-sampler/README.md) |
2425
| alpha | [Consistent Sampling](./consistent-sampling/README.md) |
2526
| alpha | [Disk Buffering](./disk-buffering/README.md) |
2627
| alpha | [GCP Authentication Extension](./gcp-auth-extension/README.md) |

RELEASING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ and deadlocks.
5858
* Run the [Release workflow](https://github.com/open-telemetry/opentelemetry-java-contrib/actions/workflows/release.yml).
5959
* Press the "Run workflow" button, then select the release branch from the dropdown list,
6060
e.g. `release/v1.9.x`, and click the "Run workflow" button below that.
61-
* This workflow will publish the artifacts to maven central and will publish a GitHub release
62-
with release notes based on the change log and with the jmx metrics jar attached.
61+
* This workflow will:
62+
* Publish the artifacts to Maven Central
63+
* Generate [GitHub Artifact Attestations](https://docs.github.com/en/actions/security-for-github-actions/using-artifact-attestations) for the JMX Metrics and JMX Scraper jars
64+
* Publish a GitHub release with release notes based on the change log and with the jars attached
6365
* Review and merge the pull request that it creates for updating the change log in main
6466
(note that if this is not a patch release then the change log on main may already be up-to-date,
6567
in which case no pull request will be created).

aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import io.opentelemetry.api.baggage.Baggage;
1212
import io.opentelemetry.api.baggage.BaggageBuilder;
13+
import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator;
1314
import io.opentelemetry.api.internal.StringUtils;
1415
import io.opentelemetry.api.trace.Span;
1516
import io.opentelemetry.api.trace.SpanContext;
@@ -80,6 +81,9 @@ public final class AwsXrayPropagator implements TextMapPropagator {
8081
private static final String INVALID_LINEAGE = "-1:11111111:0";
8182
private static final int NUM_OF_LINEAGE_DELIMITERS = 2;
8283

84+
// Copied from AwsSamplingResult in aws-xray extension
85+
private static final String AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY = "xrsr";
86+
8387
private static final List<String> FIELDS = singletonList(TRACE_HEADER_KEY);
8488

8589
private static final AwsXrayPropagator INSTANCE = new AwsXrayPropagator();
@@ -140,6 +144,16 @@ public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> se
140144

141145
Baggage baggage = Baggage.fromContext(context);
142146
String lineageHeader = baggage.getEntryValue(LINEAGE_KEY);
147+
// Get sampling rule from trace state and inject into baggage
148+
// This is a back up in case the next service does not have trace state propagation
149+
String ruleFromTraceState =
150+
spanContext.getTraceState().get(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY);
151+
if (ruleFromTraceState != null) {
152+
baggage =
153+
baggage.toBuilder()
154+
.put(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY, ruleFromTraceState)
155+
.build();
156+
}
143157

144158
if (lineageHeader != null) {
145159
traceHeader
@@ -152,6 +166,9 @@ public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> se
152166
// add 256 character truncation
153167
String truncatedTraceHeader = traceHeader.substring(0, Math.min(traceHeader.length(), 256));
154168
setter.set(carrier, TRACE_HEADER_KEY, truncatedTraceHeader);
169+
170+
// Ensure baggage is propagated with any modifications
171+
W3CBaggagePropagator.getInstance().inject(context.with(baggage), carrier, setter);
155172
}
156173

157174
@Override
@@ -245,12 +262,15 @@ private static <C> Context getContextFromHeader(
245262
logger.finest("Both traceId and spanId are required to extract a valid span context. ");
246263
}
247264

265+
SpanContext upstreamSpanContext = Span.fromContext(context).getSpanContext();
248266
SpanContext spanContext =
249267
SpanContext.createFromRemoteParent(
250268
StringUtils.padLeft(traceId, TraceId.getLength()),
251269
spanId,
252270
isSampled ? TraceFlags.getSampled() : TraceFlags.getDefault(),
253-
TraceState.getDefault());
271+
upstreamSpanContext.isValid()
272+
? upstreamSpanContext.getTraceState()
273+
: TraceState.getDefault());
254274

255275
if (spanContext.isValid()) {
256276
context = context.with(Span.wrap(spanContext));

aws-xray/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies {
1111
api("io.opentelemetry:opentelemetry-sdk-trace")
1212

1313
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
14+
implementation("io.opentelemetry.semconv:opentelemetry-semconv:1.37.0")
1415

1516
implementation("com.squareup.okhttp3:okhttp")
1617
implementation("io.opentelemetry.semconv:opentelemetry-semconv")
@@ -25,6 +26,7 @@ dependencies {
2526

2627
implementation("com.fasterxml.jackson.core:jackson-core")
2728
implementation("com.fasterxml.jackson.core:jackson-databind")
29+
implementation("com.github.ben-manes.caffeine:caffeine:2.9.3")
2830

2931
testImplementation("com.linecorp.armeria:armeria-junit5")
3032
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
@@ -40,7 +42,7 @@ testing {
4042
dependencies {
4143
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
4244
implementation("io.opentelemetry:opentelemetry-sdk-testing")
43-
implementation("org.testcontainers:junit-jupiter")
45+
implementation("org.testcontainers:testcontainers-junit-jupiter")
4446
runtimeOnly("org.slf4j:slf4j-simple")
4547
}
4648
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.awsxray;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.trace.TraceState;
10+
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
11+
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
12+
import javax.annotation.Nullable;
13+
14+
final class AwsSamplingResult implements SamplingResult {
15+
16+
// OTel trace state is a space shared with other vendors with a 256 character limit
17+
// We keep the key and values as short as possible while still identifiable
18+
public static final String AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY = "xrsr";
19+
20+
private final SamplingDecision decision;
21+
private final Attributes attributes;
22+
@Nullable private final String samplingRuleName;
23+
24+
private AwsSamplingResult(
25+
SamplingDecision decision, Attributes attributes, @Nullable String samplingRuleName) {
26+
this.decision = decision;
27+
this.attributes = attributes;
28+
this.samplingRuleName = samplingRuleName;
29+
}
30+
31+
static AwsSamplingResult create(
32+
SamplingDecision decision, Attributes attributes, @Nullable String samplingRuleName) {
33+
return new AwsSamplingResult(decision, attributes, samplingRuleName);
34+
}
35+
36+
@Override
37+
public SamplingDecision getDecision() {
38+
return decision;
39+
}
40+
41+
@Override
42+
public Attributes getAttributes() {
43+
return attributes;
44+
}
45+
46+
@Override
47+
public TraceState getUpdatedTraceState(TraceState parentTraceState) {
48+
if (parentTraceState.get(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY) == null
49+
&& this.samplingRuleName != null) {
50+
return parentTraceState.toBuilder()
51+
.put(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY, samplingRuleName)
52+
.build();
53+
}
54+
return parentTraceState;
55+
}
56+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.awsxray;
7+
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
import com.fasterxml.jackson.annotation.JsonValue;
11+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
12+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
13+
import com.google.auto.value.AutoValue;
14+
import java.util.List;
15+
import javax.annotation.Nullable;
16+
17+
@AutoValue
18+
@JsonSerialize(as = AwsXrayAdaptiveSamplingConfig.class)
19+
@JsonDeserialize(builder = AutoValue_AwsXrayAdaptiveSamplingConfig.Builder.class)
20+
public abstract class AwsXrayAdaptiveSamplingConfig {
21+
22+
@JsonProperty("version")
23+
public abstract double getVersion();
24+
25+
@JsonProperty("anomalyConditions")
26+
@Nullable
27+
public abstract List<AnomalyConditions> getAnomalyConditions();
28+
29+
@JsonProperty("anomalyCaptureLimit")
30+
@Nullable
31+
public abstract AnomalyCaptureLimit getAnomalyCaptureLimit();
32+
33+
public static Builder builder() {
34+
return new AutoValue_AwsXrayAdaptiveSamplingConfig.Builder();
35+
}
36+
37+
@AutoValue.Builder
38+
public abstract static class Builder {
39+
@JsonProperty("version")
40+
public abstract Builder setVersion(double value);
41+
42+
@JsonProperty("anomalyConditions")
43+
public abstract Builder setAnomalyConditions(List<AnomalyConditions> value);
44+
45+
@JsonProperty("anomalyCaptureLimit")
46+
public abstract Builder setAnomalyCaptureLimit(AnomalyCaptureLimit value);
47+
48+
public abstract AwsXrayAdaptiveSamplingConfig build();
49+
}
50+
51+
@AutoValue
52+
@JsonDeserialize(
53+
builder = AutoValue_AwsXrayAdaptiveSamplingConfig_AnomalyConditions.Builder.class)
54+
public abstract static class AnomalyConditions {
55+
@JsonProperty("errorCodeRegex")
56+
@Nullable
57+
public abstract String getErrorCodeRegex();
58+
59+
@JsonProperty("operations")
60+
@Nullable
61+
public abstract List<String> getOperations();
62+
63+
@JsonProperty("highLatencyMs")
64+
@Nullable
65+
public abstract Long getHighLatencyMs();
66+
67+
@JsonProperty("usage")
68+
@Nullable
69+
public abstract UsageType getUsage();
70+
71+
public static Builder builder() {
72+
return new AutoValue_AwsXrayAdaptiveSamplingConfig_AnomalyConditions.Builder();
73+
}
74+
75+
@AutoValue.Builder
76+
public abstract static class Builder {
77+
@JsonProperty("errorCodeRegex")
78+
public abstract Builder setErrorCodeRegex(String value);
79+
80+
@JsonProperty("operations")
81+
public abstract Builder setOperations(List<String> value);
82+
83+
@JsonProperty("highLatencyMs")
84+
public abstract Builder setHighLatencyMs(Long value);
85+
86+
@JsonProperty("usage")
87+
public abstract Builder setUsage(UsageType value);
88+
89+
public abstract AnomalyConditions build();
90+
}
91+
}
92+
93+
public enum UsageType {
94+
BOTH("both"),
95+
SAMPLING_BOOST("sampling-boost"),
96+
ANOMALY_TRACE_CAPTURE("anomaly-trace-capture"),
97+
NEITHER("neither"); // Not meant to be used by customers
98+
99+
private final String value;
100+
101+
UsageType(String value) {
102+
this.value = value;
103+
}
104+
105+
@JsonValue
106+
public String getValue() {
107+
return value;
108+
}
109+
110+
@JsonCreator
111+
public static UsageType fromValue(String value) {
112+
for (UsageType type : values()) {
113+
if (type.value.equals(value)) {
114+
return type;
115+
}
116+
}
117+
throw new IllegalArgumentException("Invalid usage value: " + value);
118+
}
119+
120+
public static boolean isUsedForBoost(UsageType usage) {
121+
return BOTH.equals(usage) || SAMPLING_BOOST.equals(usage);
122+
}
123+
124+
public static boolean isUsedForAnomalyTraceCapture(UsageType usage) {
125+
return BOTH.equals(usage) || ANOMALY_TRACE_CAPTURE.equals(usage);
126+
}
127+
}
128+
129+
@AutoValue
130+
@JsonDeserialize(
131+
builder = AutoValue_AwsXrayAdaptiveSamplingConfig_AnomalyCaptureLimit.Builder.class)
132+
public abstract static class AnomalyCaptureLimit {
133+
@JsonProperty("anomalyTracesPerSecond")
134+
public abstract int getAnomalyTracesPerSecond();
135+
136+
public static Builder builder() {
137+
return new AutoValue_AwsXrayAdaptiveSamplingConfig_AnomalyCaptureLimit.Builder();
138+
}
139+
140+
@AutoValue.Builder
141+
public abstract static class Builder {
142+
@JsonProperty("anomalyTracesPerSecond")
143+
public abstract Builder setAnomalyTracesPerSecond(int value);
144+
145+
public abstract AnomalyCaptureLimit build();
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)