From 2586d25876f2d490a530fb61ce301eaa041cc7e3 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 11:19:41 +0200 Subject: [PATCH 01/16] delegate to IncludeExcludePredicate --- .../baggage/processor/BaggageLogRecordProcessor.java | 8 -------- .../baggage/processor/BaggageProcessorCustomizer.java | 11 +++-------- .../baggage/processor/BaggageSpanProcessor.java | 8 -------- .../baggage/processor/BaggageSpanProcessorTest.java | 2 +- 4 files changed, 4 insertions(+), 25 deletions(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index 474f4caeff..cf852dbc80 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -28,14 +28,6 @@ public BaggageLogRecordProcessor(Predicate baggageKeyPredicate) { this.baggageKeyPredicate = baggageKeyPredicate; } - /** - * Creates a new {@link BaggageLogRecordProcessor} that copies all baggage entries into the newly - * created log record. - */ - public static BaggageLogRecordProcessor allowAllBaggageKeys() { - return new BaggageLogRecordProcessor(baggageKey -> true); - } - @Override public void onEmit(Context context, ReadWriteLogRecord logRecord) { Baggage.fromContext(context) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java index 2e07722e6b..bebd7cc6e2 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java @@ -9,6 +9,7 @@ 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.common.internal.IncludeExcludePredicate; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; import java.util.List; @@ -44,10 +45,7 @@ private static void addSpanProcessor( } static BaggageSpanProcessor createBaggageSpanProcessor(List keys) { - if (keys.size() == 1 && keys.get(0).equals("*")) { - return BaggageSpanProcessor.allowAllBaggageKeys(); - } - return new BaggageSpanProcessor(keys::contains); + return new BaggageSpanProcessor(IncludeExcludePredicate.createPatternMatching(keys, null)); } private static void addLogRecordProcessor( @@ -64,9 +62,6 @@ private static void addLogRecordProcessor( } static BaggageLogRecordProcessor createBaggageLogRecordProcessor(List keys) { - if (keys.size() == 1 && keys.get(0).equals("*")) { - return BaggageLogRecordProcessor.allowAllBaggageKeys(); - } - return new BaggageLogRecordProcessor(keys::contains); + return new BaggageLogRecordProcessor(IncludeExcludePredicate.createPatternMatching(keys, null)); } } diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index 1ba62b19d0..ffa735fa68 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -27,14 +27,6 @@ public BaggageSpanProcessor(Predicate baggageKeyPredicate) { this.baggageKeyPredicate = baggageKeyPredicate; } - /** - * Creates a new {@link BaggageSpanProcessor} that copies all baggage entries into the newly - * created {@link io.opentelemetry.api.trace.Span}. - */ - public static BaggageSpanProcessor allowAllBaggageKeys() { - return new BaggageSpanProcessor(baggageKey -> true); - } - @Override public void onStart(Context parentContext, ReadWriteSpan span) { Baggage.fromContext(parentContext) diff --git a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java index dd7ea38269..2c6272757a 100644 --- a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java +++ b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java @@ -21,7 +21,7 @@ class BaggageSpanProcessorTest { @Test void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span) { - try (BaggageSpanProcessor processor = BaggageSpanProcessor.allowAllBaggageKeys()) { + try (BaggageSpanProcessor processor = new BaggageSpanProcessor(baggageKey -> true)) { try (Scope ignore = Baggage.current().toBuilder().put("key", "value").build().makeCurrent()) { processor.onStart(Context.current(), span); Mockito.verify(span).setAttribute("key", "value"); From 53610d205481fb1a02e2650eaf074b387415708f Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 11:57:05 +0200 Subject: [PATCH 02/16] yolo refactor more --- .../BaggageLogRecordComponentProvider.java | 6 ++-- .../processor/BaggageLogRecordProcessor.java | 16 ++++++--- .../processor/BaggageProcessorCustomizer.java | 13 ++----- .../BaggageSpanComponentProvider.java | 6 ++-- .../processor/BaggageSpanProcessor.java | 17 ++++++--- .../BaggageProcessorCustomizerTest.java | 36 +++++++++++++------ .../processor/BaggageSpanProcessorTest.java | 16 ++++----- 7 files changed, 65 insertions(+), 45 deletions(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordComponentProvider.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordComponentProvider.java index 34930eb6b6..693e6a7fee 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordComponentProvider.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordComponentProvider.java @@ -8,7 +8,6 @@ import com.google.auto.service.AutoService; import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.common.internal.IncludeExcludePredicate; import io.opentelemetry.sdk.logs.LogRecordProcessor; @AutoService(ComponentProvider.class) @@ -21,9 +20,8 @@ public String getName() { @Override public LogRecordProcessor create(DeclarativeConfigProperties config) { return new BaggageLogRecordProcessor( - IncludeExcludePredicate.createPatternMatching( - config.getScalarList("included", String.class), - config.getScalarList("excluded", String.class))); + config.getScalarList("included", String.class), + config.getScalarList("excluded", String.class)); } @Override diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index cf852dbc80..77e546c0c2 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -8,9 +8,12 @@ import io.opentelemetry.api.baggage.Baggage; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.common.internal.IncludeExcludePredicate; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.ReadWriteLogRecord; +import java.util.Collection; import java.util.function.Predicate; +import javax.annotation.Nullable; /** * This log record processor copies attributes stored in {@link Baggage} into each newly created log @@ -21,11 +24,16 @@ public final class BaggageLogRecordProcessor implements LogRecordProcessor { private final Predicate baggageKeyPredicate; /** - * Creates a new {@link BaggageLogRecordProcessor} that copies only baggage entries with keys that - * pass the provided filter into the newly created log record. + * Creates a new {@link BaggageLogRecordProcessor} that copies baggage entries with keys that pass + * the provided include/exclude filtering into the newly created log record, when both arguments + * are null or empty all baggage are included. + * + * @param included list of included attribute patterns to include + * @param excluded list of excluded attribute patterns to exclude */ - public BaggageLogRecordProcessor(Predicate baggageKeyPredicate) { - this.baggageKeyPredicate = baggageKeyPredicate; + public BaggageLogRecordProcessor( + @Nullable Collection included, @Nullable Collection excluded) { + this.baggageKeyPredicate = IncludeExcludePredicate.createPatternMatching(included, excluded); } @Override diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java index bebd7cc6e2..069adfc42b 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizer.java @@ -9,7 +9,6 @@ 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.common.internal.IncludeExcludePredicate; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; import java.util.List; @@ -41,11 +40,7 @@ private static void addSpanProcessor( } // need to add before the batch span processor - sdkTracerProviderBuilder.addSpanProcessorFirst(createBaggageSpanProcessor(keys)); - } - - static BaggageSpanProcessor createBaggageSpanProcessor(List keys) { - return new BaggageSpanProcessor(IncludeExcludePredicate.createPatternMatching(keys, null)); + sdkTracerProviderBuilder.addSpanProcessorFirst(new BaggageSpanProcessor(keys, null)); } private static void addLogRecordProcessor( @@ -58,10 +53,6 @@ private static void addLogRecordProcessor( } // need to add before the batch log processor - sdkLoggerProviderBuilder.addLogRecordProcessorFirst(createBaggageLogRecordProcessor(keys)); - } - - static BaggageLogRecordProcessor createBaggageLogRecordProcessor(List keys) { - return new BaggageLogRecordProcessor(IncludeExcludePredicate.createPatternMatching(keys, null)); + sdkLoggerProviderBuilder.addLogRecordProcessorFirst(new BaggageLogRecordProcessor(keys, null)); } } diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanComponentProvider.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanComponentProvider.java index dc294a925e..5786d8b9c4 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanComponentProvider.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanComponentProvider.java @@ -8,7 +8,6 @@ import com.google.auto.service.AutoService; import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.common.internal.IncludeExcludePredicate; import io.opentelemetry.sdk.trace.SpanProcessor; @AutoService(ComponentProvider.class) @@ -21,9 +20,8 @@ public String getName() { @Override public SpanProcessor create(DeclarativeConfigProperties config) { return new BaggageSpanProcessor( - IncludeExcludePredicate.createPatternMatching( - config.getScalarList("included", String.class), - config.getScalarList("excluded", String.class))); + config.getScalarList("included", String.class), + config.getScalarList("excluded", String.class)); } @Override diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index ffa735fa68..ac6835a52f 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -7,10 +7,13 @@ import io.opentelemetry.api.baggage.Baggage; import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.common.internal.IncludeExcludePredicate; import io.opentelemetry.sdk.trace.ReadWriteSpan; import io.opentelemetry.sdk.trace.ReadableSpan; import io.opentelemetry.sdk.trace.SpanProcessor; +import java.util.Collection; import java.util.function.Predicate; +import javax.annotation.Nullable; /** * This span processor copies attributes stored in {@link Baggage} into each newly created {@link @@ -20,11 +23,17 @@ public final class BaggageSpanProcessor implements SpanProcessor { private final Predicate baggageKeyPredicate; /** - * Creates a new {@link BaggageSpanProcessor} that copies only baggage entries with keys that pass - * the provided filter into the newly created {@link io.opentelemetry.api.trace.Span}. + * Creates a new {@link BaggageSpanProcessor} that copies baggage entries with keys that pass the + * provided include/exclude filtering into the newly created {@link + * io.opentelemetry.api.trace.Span}, when both arguments are null or empty all baggage are + * included. + * + * @param included list of included attribute patterns to include + * @param excluded list of excluded attribute patterns to exclude */ - public BaggageSpanProcessor(Predicate baggageKeyPredicate) { - this.baggageKeyPredicate = baggageKeyPredicate; + public BaggageSpanProcessor( + @Nullable Collection included, @Nullable Collection excluded) { + this.baggageKeyPredicate = IncludeExcludePredicate.createPatternMatching(included, excluded); } @Override diff --git a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java index 645ff53343..82f0b5fd91 100644 --- a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java +++ b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java @@ -6,6 +6,7 @@ package io.opentelemetry.contrib.baggage.processor; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static java.util.Collections.singletonList; import static org.awaitility.Awaitility.await; import static org.mockito.Mockito.verify; @@ -122,7 +123,7 @@ private static OpenTelemetrySdk getOpenTelemetrySdk( @Override public List load(Class spiClass) { if (spiClass.equals(ConfigurableSpanExporterProvider.class)) { - return Collections.singletonList( + return singletonList( spiClass.cast( new ConfigurableSpanExporterProvider() { @Override @@ -137,7 +138,7 @@ public String getName() { } })); } else if (spiClass.equals(ConfigurableLogRecordExporterProvider.class)) { - return Collections.singletonList( + return singletonList( spiClass.cast( new ConfigurableLogRecordExporterProvider() { @Override @@ -160,8 +161,7 @@ public String getName() { @Test void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span) { - try (BaggageSpanProcessor processor = - BaggageProcessorCustomizer.createBaggageSpanProcessor(Collections.singletonList("*"))) { + try (BaggageSpanProcessor processor = new BaggageSpanProcessor(singletonList("*"), null)) { try (Scope ignore = Baggage.current().toBuilder().put("key", "value").build().makeCurrent()) { processor.onStart(Context.current(), span); verify(span).setAttribute("key", "value"); @@ -172,8 +172,7 @@ void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span @Test void test_baggageSpanProcessor_adds_attributes_to_spans_when_key_filter_matches( @Mock ReadWriteSpan span) { - try (BaggageSpanProcessor processor = - BaggageProcessorCustomizer.createBaggageSpanProcessor(Collections.singletonList("key"))) { + try (BaggageSpanProcessor processor = new BaggageSpanProcessor(singletonList("key"), null)) { try (Scope ignore = Baggage.current().toBuilder() .put("key", "value") @@ -191,8 +190,7 @@ void test_baggageSpanProcessor_adds_attributes_to_spans_when_key_filter_matches( void test_baggageLogRecordProcessor_adds_attributes_to_logRecord( @Mock ReadWriteLogRecord logRecord) { try (BaggageLogRecordProcessor processor = - BaggageProcessorCustomizer.createBaggageLogRecordProcessor( - Collections.singletonList("*"))) { + new BaggageLogRecordProcessor(singletonList("*"), null)) { try (Scope ignore = Baggage.current().toBuilder().put("key", "value").build().makeCurrent()) { processor.onEmit(Context.current(), logRecord); verify(logRecord).setAttribute(AttributeKey.stringKey("key"), "value"); @@ -204,8 +202,7 @@ void test_baggageLogRecordProcessor_adds_attributes_to_logRecord( void test_baggageLogRecordProcessor_adds_attributes_to_spans_when_key_filter_matches( @Mock ReadWriteLogRecord logRecord) { try (BaggageLogRecordProcessor processor = - BaggageProcessorCustomizer.createBaggageLogRecordProcessor( - Collections.singletonList("key"))) { + new BaggageLogRecordProcessor(singletonList("k*"), null)) { try (Scope ignore = Baggage.current().toBuilder() .put("key", "value") @@ -218,4 +215,23 @@ void test_baggageLogRecordProcessor_adds_attributes_to_spans_when_key_filter_mat } } } + + @Test + void test_baggageLogRecordProcessor_adds_attributes_to_spans_include_exclude( + @Mock ReadWriteLogRecord logRecord) { + try (BaggageLogRecordProcessor processor = + new BaggageLogRecordProcessor(singletonList("key*"), singletonList("*excluded"))) { + try (Scope ignore = + Baggage.current().toBuilder() + .put("key", "value") + .put("key_is_excluded", "value") + .build() + .makeCurrent()) { + processor.onEmit(Context.current(), logRecord); + verify(logRecord).setAttribute(AttributeKey.stringKey("key"), "value"); + verify(logRecord, Mockito.never()) + .setAttribute(AttributeKey.stringKey("key_is_excluded"), "value"); + } + } + } } diff --git a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java index 2c6272757a..f3d153c9ae 100644 --- a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java +++ b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java @@ -5,11 +5,12 @@ package io.opentelemetry.contrib.baggage.processor; +import static java.util.Collections.singletonList; + import io.opentelemetry.api.baggage.Baggage; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; import io.opentelemetry.sdk.trace.ReadWriteSpan; -import java.util.regex.Pattern; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -21,7 +22,7 @@ class BaggageSpanProcessorTest { @Test void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span) { - try (BaggageSpanProcessor processor = new BaggageSpanProcessor(baggageKey -> true)) { + try (BaggageSpanProcessor processor = new BaggageSpanProcessor(null, null)) { try (Scope ignore = Baggage.current().toBuilder().put("key", "value").build().makeCurrent()) { processor.onStart(Context.current(), span); Mockito.verify(span).setAttribute("key", "value"); @@ -32,7 +33,7 @@ void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span @Test void test_baggageSpanProcessor_adds_attributes_to_spans_when_key_filter_matches( @Mock ReadWriteSpan span) { - try (BaggageSpanProcessor processor = new BaggageSpanProcessor(key -> key.startsWith("k"))) { + try (BaggageSpanProcessor processor = new BaggageSpanProcessor(singletonList("k*"), null)) { try (Scope ignore = Baggage.current().toBuilder() .put("key", "value") @@ -47,20 +48,19 @@ void test_baggageSpanProcessor_adds_attributes_to_spans_when_key_filter_matches( } @Test - void test_baggageSpanProcessor_adds_attributes_to_spans_when_key_filter_matches_regex( + void test_baggageSpanProcessor_adds_attributes_to_spans_include_exclude( @Mock ReadWriteSpan span) { - Pattern pattern = Pattern.compile("k.*"); try (BaggageSpanProcessor processor = - new BaggageSpanProcessor(key -> pattern.matcher(key).matches())) { + new BaggageSpanProcessor(singletonList("k*"), singletonList("*ignored"))) { try (Scope ignore = Baggage.current().toBuilder() .put("key", "value") - .put("other", "value") + .put("key_is_ignored", "value") .build() .makeCurrent()) { processor.onStart(Context.current(), span); Mockito.verify(span).setAttribute("key", "value"); - Mockito.verify(span, Mockito.never()).setAttribute("other", "value"); + Mockito.verify(span, Mockito.never()).setAttribute("key_is_ignored", "value"); } } } From f5fc44c01a17d3611b1080906769f0ecff000299 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 12:01:20 +0200 Subject: [PATCH 03/16] update documentation --- baggage-processor/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/baggage-processor/README.md b/baggage-processor/README.md index f788ea5e24..f5c5790c3d 100644 --- a/baggage-processor/README.md +++ b/baggage-processor/README.md @@ -20,10 +20,10 @@ Do not put sensitive information in Baggage. If you are using the OpenTelemetry SDK auto-configuration, you can add the span and log baggage processors through configuration. -| Property | Description | -|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| -| `otel.java.experimental.span-attributes.copy-from-baggage.include` | Add baggage entries as span attributes, e.g. `key1,key2` or `*` to add all baggage items as keys. | -| `otel.java.experimental.log-attributes.copy-from-baggage.include` | Add baggage entries as log attributes, e.g. `key1,key2` or `*` to add all baggage items as keys. | +| Property | Description | +|--------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `otel.java.experimental.span-attributes.copy-from-baggage.include` | Add baggage entries as span attributes, e.g. `key1,key*`, [wildcard pattern matching](https://github.com/open-telemetry/opentelemetry-configuration/blob/main/CONTRIBUTING.md#properties-requiring-pattern-matching) is supported. | +| `otel.java.experimental.log-attributes.copy-from-baggage.include` | Add baggage entries as log attributes, e.g. `key1,key*`, [wildcard pattern matching](https://github.com/open-telemetry/opentelemetry-configuration/blob/main/CONTRIBUTING.md#properties-requiring-pattern-matching) is supported. | ### Usage with declarative configuration From bd5a55981cd40bbba5d28c34142c5a66115210ff Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 12:11:54 +0200 Subject: [PATCH 04/16] keep deprecated constructors for now --- .../baggage/processor/BaggageLogRecordProcessor.java | 8 ++++++++ .../contrib/baggage/processor/BaggageSpanProcessor.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index 77e546c0c2..96f04b5d52 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -23,6 +23,14 @@ public final class BaggageLogRecordProcessor implements LogRecordProcessor { private final Predicate baggageKeyPredicate; + /** + * @deprecated Use {@link #BaggageLogRecordProcessor(Collection, Collection)} instead. + */ + @Deprecated + public BaggageLogRecordProcessor(Predicate baggageKeyPredicate) { + this.baggageKeyPredicate = baggageKeyPredicate; + } + /** * Creates a new {@link BaggageLogRecordProcessor} that copies baggage entries with keys that pass * the provided include/exclude filtering into the newly created log record, when both arguments diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index ac6835a52f..ecd416c7c1 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -22,6 +22,14 @@ public final class BaggageSpanProcessor implements SpanProcessor { private final Predicate baggageKeyPredicate; + /** + * @deprecated Use {@link #BaggageSpanProcessor(Collection, Collection)} instead. + */ + @Deprecated + public BaggageSpanProcessor(Predicate baggageKeyPredicate) { + this.baggageKeyPredicate = baggageKeyPredicate; + } + /** * Creates a new {@link BaggageSpanProcessor} that copies baggage entries with keys that pass the * provided include/exclude filtering into the newly created {@link From 53862b8629572fb380b035b46dc8073c33ac9424 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 12:22:22 +0200 Subject: [PATCH 05/16] preserve exisiting api compatibility --- baggage-processor/README.md | 21 +++++++------------ .../processor/BaggageLogRecordProcessor.java | 10 +++++++++ .../processor/BaggageSpanProcessor.java | 9 ++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/baggage-processor/README.md b/baggage-processor/README.md index f5c5790c3d..11fb7950a1 100644 --- a/baggage-processor/README.md +++ b/baggage-processor/README.md @@ -63,32 +63,25 @@ To configure the span and log processors to copy all baggage entries during conf ```java import io.opentelemetry.contrib.baggage.processor; + // ... TracerProvider tracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(BaggageSpanProcessor.allowAllBaggageKeys()) + .addSpanProcessor(new BaggageSpanProcessor(Collections.singletonList("*"), null)) .build(); LoggerProvider loggerProvider = SdkLoggerProvider.builder() - .addLogRecordProcessor(BaggageLogRecordProcessor.allowAllBaggageKeys()) + .addLogProcessor(new BaggageLogProcessor(Collections.singletonList("*"), null)) .build(); ``` -Alternatively, you can provide a custom baggage key predicate to select which baggage keys you want to copy. - -For example, to only copy baggage entries that start with `my-key`: - -```java -new BaggageSpanProcessor(baggageKey -> baggageKey.startsWith("my-key")); -new BaggageLogRecordProcessor(baggageKey -> baggageKey.startsWith("my-key")); -``` +Alternatively, you can provide a custom baggage key wildcard to select which baggage keys you want to copy. -For example, to only copy baggage entries that match the regex `^key.+`: +For example, to only copy baggage entries that start with `my-key` and ignore keys that end with `*-ignored` ```java -Pattern pattern = Pattern.compile("^key.+"); -new BaggageSpanProcessor(baggageKey -> pattern.matcher(baggageKey).matches()); -new BaggageLogRecordProcessor(baggageKey -> pattern.matcher(baggageKey).matches()); +new BaggageSpanProcessor(singletonList("my-key*"), singletonList("*-ignored")); +new BaggageLogRecordProcessor(singletonList("my-key*"), singletonList("*-ignored")); ``` ## Component owners diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index 96f04b5d52..e009fbc4ec 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -44,6 +44,16 @@ public BaggageLogRecordProcessor( this.baggageKeyPredicate = IncludeExcludePredicate.createPatternMatching(included, excluded); } + /** + * @deprecated use {@code new BaggageLogRecordProcessor(Collections.singletonList("*),null)} + * instead + * @return baggage log processor including all attributes + */ + @Deprecated + public static BaggageLogRecordProcessor allowAllBaggageKeys() { + return new BaggageLogRecordProcessor(excluded -> true); + } + @Override public void onEmit(Context context, ReadWriteLogRecord logRecord) { Baggage.fromContext(context) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index ecd416c7c1..a52e94a025 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -44,6 +44,15 @@ public BaggageSpanProcessor( this.baggageKeyPredicate = IncludeExcludePredicate.createPatternMatching(included, excluded); } + /** + * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*),null)} instead + * @return baggage span processor including all attributes + */ + @Deprecated + public static BaggageSpanProcessor allowAllBaggageKeys() { + return new BaggageSpanProcessor(baggageKey -> true); + } + @Override public void onStart(Context parentContext, ReadWriteSpan span) { Baggage.fromContext(parentContext) From df3d46c460955be2faee116c5aafe0bd07b8dc8d Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 12:43:24 +0200 Subject: [PATCH 06/16] add missing javadoc --- .../contrib/baggage/processor/BaggageLogRecordProcessor.java | 5 ++++- .../contrib/baggage/processor/BaggageSpanProcessor.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index e009fbc4ec..cd77da1545 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -45,9 +45,12 @@ public BaggageLogRecordProcessor( } /** + * Creates a new {@link BaggageLogRecordProcessor} that copies all baggage entries into the newly + * created log record. + * + * @return baggage log processor including all attributes * @deprecated use {@code new BaggageLogRecordProcessor(Collections.singletonList("*),null)} * instead - * @return baggage log processor including all attributes */ @Deprecated public static BaggageLogRecordProcessor allowAllBaggageKeys() { diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index a52e94a025..86a21dc723 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -45,8 +45,11 @@ public BaggageSpanProcessor( } /** - * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*),null)} instead + * Creates a new {@link BaggageLogRecordProcessor} that copies all baggage entries into the newly + * created span. + * * @return baggage span processor including all attributes + * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*),null)} instead */ @Deprecated public static BaggageSpanProcessor allowAllBaggageKeys() { From 37e73f87638932fa46ebbd5d5ec2052c80b40cbe Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 13:44:21 +0200 Subject: [PATCH 07/16] add clarification about the include/exclude in readme --- baggage-processor/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/baggage-processor/README.md b/baggage-processor/README.md index 11fb7950a1..4934f6df55 100644 --- a/baggage-processor/README.md +++ b/baggage-processor/README.md @@ -55,6 +55,10 @@ This will configure the respective processor to include baggage keys listed in ` exclude those in `excluded` as explained in [Properties requiring pattern matching](https://github.com/open-telemetry/opentelemetry-configuration/blob/main/CONTRIBUTING.md#properties-requiring-pattern-matching). +When both `included` and `excluded` are empty or not set, all the baggage entries will be copied. +When only `included` is set, only the baggage entries matching the patterns in `included` will be copied (opt-in). +When only `excluded` is set, all baggage entries except those matching the patterns in `excluded` will be copied (opt-out). + ### Usage through programmatic activation Add the span and log processor when configuring the tracer and logger providers. From 8e14b331c6e7854d9d56c13269ee18f9f63b56c1 Mon Sep 17 00:00:00 2001 From: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 13:47:39 +0200 Subject: [PATCH 08/16] Update baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../contrib/baggage/processor/BaggageSpanProcessor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index d7a0304299..46803e9731 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -45,11 +45,12 @@ public BaggageSpanProcessor( } /** - * Creates a new {@link BaggageLogRecordProcessor} that copies all baggage entries into the newly + * Creates a new {@link BaggageSpanProcessor} that copies all baggage entries into the newly * created span. * * @return baggage span processor including all attributes - * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*),null)} instead + * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*"), null)} + * instead */ @Deprecated public static BaggageSpanProcessor allowAllBaggageKeys() { From d7946adb9f7c507a3670e3bbb89f8a4f0e2a3741 Mon Sep 17 00:00:00 2001 From: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 13:47:53 +0200 Subject: [PATCH 09/16] Update baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../contrib/baggage/processor/BaggageLogRecordProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index 5be75985aa..a3fd8264f8 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -49,7 +49,7 @@ public BaggageLogRecordProcessor( * created log record. * * @return baggage log processor including all attributes - * @deprecated use {@code new BaggageLogRecordProcessor(Collections.singletonList("*),null)} + * @deprecated use {@code new BaggageLogRecordProcessor(Collections.singletonList("*"), null)} * instead */ @Deprecated From ba60212b9f8339775c584921b43ff9f6b20d7f51 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 13:49:16 +0200 Subject: [PATCH 10/16] enhance readme --- baggage-processor/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/baggage-processor/README.md b/baggage-processor/README.md index 4934f6df55..4ebcbf9a7d 100644 --- a/baggage-processor/README.md +++ b/baggage-processor/README.md @@ -66,7 +66,8 @@ Add the span and log processor when configuring the tracer and logger providers. To configure the span and log processors to copy all baggage entries during configuration: ```java -import io.opentelemetry.contrib.baggage.processor; +import io.opentelemetry.contrib.baggage.processor.BaggageSpanProcessor; +import io.opentelemetry.contrib.baggage.processor.BaggageLogProcessor; // ... @@ -84,8 +85,8 @@ Alternatively, you can provide a custom baggage key wildcard to select which bag For example, to only copy baggage entries that start with `my-key` and ignore keys that end with `*-ignored` ```java -new BaggageSpanProcessor(singletonList("my-key*"), singletonList("*-ignored")); -new BaggageLogRecordProcessor(singletonList("my-key*"), singletonList("*-ignored")); +new BaggageSpanProcessor(Collections.singletonList("my-key*"), Collections.singletonList("*-ignored")); +new BaggageLogRecordProcessor(Collections.singletonList("my-key*"), Collections.singletonList("*-ignored")); ``` ## Component owners From 9ea208ecda594b1dd1c7a1debac92fadd509ec62 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 29 Apr 2026 13:49:57 +0200 Subject: [PATCH 11/16] spotless --- .../contrib/baggage/processor/BaggageSpanProcessor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index 46803e9731..57b1c75b4c 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -49,8 +49,7 @@ public BaggageSpanProcessor( * created span. * * @return baggage span processor including all attributes - * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*"), null)} - * instead + * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*"), null)} instead */ @Deprecated public static BaggageSpanProcessor allowAllBaggageKeys() { From a6d16caaf4b4f65a77d053d5997b1a87c5829167 Mon Sep 17 00:00:00 2001 From: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 4 May 2026 19:22:49 +0200 Subject: [PATCH 12/16] Apply suggestions from code review Co-authored-by: Mike Goldsmith --- .../baggage/processor/BaggageLogRecordProcessor.java | 6 +++--- .../contrib/baggage/processor/BaggageSpanProcessor.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index a3fd8264f8..5d78727653 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -36,8 +36,8 @@ public BaggageLogRecordProcessor(Predicate baggageKeyPredicate) { * the provided include/exclude filtering into the newly created log record, when both arguments * are null or empty all baggage are included. * - * @param included list of included attribute patterns to include - * @param excluded list of excluded attribute patterns to exclude + * @param included list of included baggage key patterns to include + * @param excluded list of excluded baggage key patterns to exclude */ public BaggageLogRecordProcessor( @Nullable Collection included, @Nullable Collection excluded) { @@ -54,7 +54,7 @@ public BaggageLogRecordProcessor( */ @Deprecated public static BaggageLogRecordProcessor allowAllBaggageKeys() { - return new BaggageLogRecordProcessor(excluded -> true); + return new BaggageLogRecordProcessor(baggageKey -> true); } @Override diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index 57b1c75b4c..439a30ae6c 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -36,8 +36,8 @@ public BaggageSpanProcessor(Predicate baggageKeyPredicate) { * io.opentelemetry.api.trace.Span}, when both arguments are null or empty all baggage are * included. * - * @param included list of included attribute patterns to include - * @param excluded list of excluded attribute patterns to exclude + * @param included list of included baggage key patterns to include + * @param excluded list of excluded baggage key patterns to exclude */ public BaggageSpanProcessor( @Nullable Collection included, @Nullable Collection excluded) { From 97844ff27ce06917598810c542752c9d6e2ee8e2 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 May 2026 13:53:15 +0200 Subject: [PATCH 13/16] apply code review suggestions --- baggage-processor/README.md | 7 ++++--- .../baggage/processor/BaggageLogRecordProcessor.java | 5 +---- .../contrib/baggage/processor/BaggageSpanProcessor.java | 4 +--- .../baggage/processor/BaggageProcessorCustomizerTest.java | 2 +- .../baggage/processor/BaggageSpanProcessorTest.java | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/baggage-processor/README.md b/baggage-processor/README.md index ba88d1bbe1..f22cb3e328 100644 --- a/baggage-processor/README.md +++ b/baggage-processor/README.md @@ -61,6 +61,7 @@ exclude those in `excluded` as explained in When both `included` and `excluded` are empty or not set, all the baggage entries will be copied. When only `included` is set, only the baggage entries matching the patterns in `included` will be copied (opt-in). When only `excluded` is set, all baggage entries except those matching the patterns in `excluded` will be copied (opt-out). +When a value matches both `included` and `excluded`, then it is excluded. ### Usage through programmatic activation @@ -75,15 +76,15 @@ import io.opentelemetry.contrib.baggage.processor.BaggageLogProcessor; // ... TracerProvider tracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(new BaggageSpanProcessor(Collections.singletonList("*"), null)) + .addSpanProcessor(BaggageSpanProcessor.allowAllBaggageKeys()) .build(); LoggerProvider loggerProvider = SdkLoggerProvider.builder() - .addLogProcessor(new BaggageLogProcessor(Collections.singletonList("*"), null)) + .addLogProcessor(BaggageLogRecordProcessor.allowAllBaggageKeys()) .build(); ``` -Alternatively, you can provide a custom baggage key wildcard to select which baggage keys you want to copy. +Alternatively, you can provide a custom baggage key wildcards to select which baggage keys you want to include/exclude for copy. For example, to only copy baggage entries that start with `my-key` and ignore keys that end with `*-ignored` diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index 5d78727653..7a0a115d71 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -49,12 +49,9 @@ public BaggageLogRecordProcessor( * created log record. * * @return baggage log processor including all attributes - * @deprecated use {@code new BaggageLogRecordProcessor(Collections.singletonList("*"), null)} - * instead */ - @Deprecated public static BaggageLogRecordProcessor allowAllBaggageKeys() { - return new BaggageLogRecordProcessor(baggageKey -> true); + return new BaggageLogRecordProcessor(null, null); } @Override diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index 439a30ae6c..66742a1fd3 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -49,11 +49,9 @@ public BaggageSpanProcessor( * created span. * * @return baggage span processor including all attributes - * @deprecated use {@code new BaggageSpanProcessor(Collections.singletonList("*"), null)} instead */ - @Deprecated public static BaggageSpanProcessor allowAllBaggageKeys() { - return new BaggageSpanProcessor(baggageKey -> true); + return new BaggageSpanProcessor(null, null); } @Override diff --git a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java index 82f0b5fd91..23762b787d 100644 --- a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java +++ b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageProcessorCustomizerTest.java @@ -161,7 +161,7 @@ public String getName() { @Test void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span) { - try (BaggageSpanProcessor processor = new BaggageSpanProcessor(singletonList("*"), null)) { + try (BaggageSpanProcessor processor = BaggageSpanProcessor.allowAllBaggageKeys()) { try (Scope ignore = Baggage.current().toBuilder().put("key", "value").build().makeCurrent()) { processor.onStart(Context.current(), span); verify(span).setAttribute("key", "value"); diff --git a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java index f3d153c9ae..8de35e5866 100644 --- a/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java +++ b/baggage-processor/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java @@ -22,7 +22,7 @@ class BaggageSpanProcessorTest { @Test void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span) { - try (BaggageSpanProcessor processor = new BaggageSpanProcessor(null, null)) { + try (BaggageSpanProcessor processor = BaggageSpanProcessor.allowAllBaggageKeys()) { try (Scope ignore = Baggage.current().toBuilder().put("key", "value").build().makeCurrent()) { processor.onStart(Context.current(), span); Mockito.verify(span).setAttribute("key", "value"); From 61ef1cbc69ed068b5404b186a38c70c6044d31f8 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 May 2026 14:01:02 +0200 Subject: [PATCH 14/16] add deprecated note to clarify intent --- .../contrib/baggage/processor/BaggageLogRecordProcessor.java | 4 +++- .../contrib/baggage/processor/BaggageSpanProcessor.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java index 7a0a115d71..d0ac2f3c29 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageLogRecordProcessor.java @@ -24,7 +24,9 @@ public final class BaggageLogRecordProcessor implements LogRecordProcessor { private final Predicate baggageKeyPredicate; /** - * @deprecated Use {@link #BaggageLogRecordProcessor(Collection, Collection)} instead. + * @deprecated Use {@link #BaggageLogRecordProcessor(Collection, Collection)} instead. Most usages + * of this method should be replaceable with glob patterns, but not all thus this method is + * kept to preserve compatibility. */ @Deprecated public BaggageLogRecordProcessor(Predicate baggageKeyPredicate) { diff --git a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java index 66742a1fd3..dd3a390332 100644 --- a/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java +++ b/baggage-processor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java @@ -23,7 +23,9 @@ public final class BaggageSpanProcessor implements SpanProcessor { private final Predicate baggageKeyPredicate; /** - * @deprecated Use {@link #BaggageSpanProcessor(Collection, Collection)} instead. + * @deprecated Use {@link #BaggageSpanProcessor(Collection, Collection)} instead. Most usages of + * this method should be replaceable with glob patterns, but not all thus this method is kept + * to preserve compatibility. */ @Deprecated public BaggageSpanProcessor(Predicate baggageKeyPredicate) { From 6048aa023bcd74a32f393de35d337c304807c404 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 May 2026 14:13:44 +0200 Subject: [PATCH 15/16] fix table formatting --- baggage-processor/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/baggage-processor/README.md b/baggage-processor/README.md index f22cb3e328..93f9a7133e 100644 --- a/baggage-processor/README.md +++ b/baggage-processor/README.md @@ -22,10 +22,12 @@ Do not put sensitive information in Baggage. If you are using the OpenTelemetry SDK auto-configuration, you can add the span and log baggage processors through configuration. -| Property | Description | -|--------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `otel.java.experimental.span-attributes.copy-from-baggage.include` | Add baggage entries as span attributes, e.g. `key1,key*`, [wildcard pattern matching](https://github.com/open-telemetry/opentelemetry-configuration/blob/main/CONTRIBUTING.md#properties-requiring-pattern-matching) is supported. | -| `otel.java.experimental.log-attributes.copy-from-baggage.include` | Add baggage entries as log attributes, e.g. `key1,key*`, [wildcard pattern matching](https://github.com/open-telemetry/opentelemetry-configuration/blob/main/CONTRIBUTING.md#properties-requiring-pattern-matching) is supported. | +| Property | Description | +|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------| +| `otel.java.experimental.span-attributes.copy-from-baggage.include` | Add baggage entries as span attributes, e.g. `key1,key*`, wildcard pattern mathinc is supported. | +| `otel.java.experimental.log-attributes.copy-from-baggage.include` | Add baggage entries as log attributes, e.g. `key1,key*`, wildcard pattern mathinc is supported. | + +[Wildcard pattern matching]([wildcard pattern matching](https://github.com/open-telemetry/opentelemetry-configuration/blob/main/CONTRIBUTING.md#properties-requiring-pattern-matching)) is supported for both properties. ### Usage with declarative configuration From 13e517d21e4c7c63ce2e3a5f73508447b1047bd4 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 May 2026 15:15:58 +0200 Subject: [PATCH 16/16] please the lint gods --- baggage-processor/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/baggage-processor/README.md b/baggage-processor/README.md index 93f9a7133e..0ef984c4a4 100644 --- a/baggage-processor/README.md +++ b/baggage-processor/README.md @@ -23,7 +23,7 @@ If you are using the OpenTelemetry SDK auto-configuration, you can add the span processors through configuration. | Property | Description | -|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------| +| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | | `otel.java.experimental.span-attributes.copy-from-baggage.include` | Add baggage entries as span attributes, e.g. `key1,key*`, wildcard pattern mathinc is supported. | | `otel.java.experimental.log-attributes.copy-from-baggage.include` | Add baggage entries as log attributes, e.g. `key1,key*`, wildcard pattern mathinc is supported. | @@ -86,7 +86,8 @@ LoggerProvider loggerProvider = SdkLoggerProvider.builder() .build(); ``` -Alternatively, you can provide a custom baggage key wildcards to select which baggage keys you want to include/exclude for copy. +Alternatively, you can provide a custom baggage key wildcards to select which baggage keys you want to include/exclude + for copy. For example, to only copy baggage entries that start with `my-key` and ignore keys that end with `*-ignored`