-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d1f243
commit 1c3e4ea
Showing
7 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# OpenTelemetry Baggage Span Processor | ||
|
||
The BaggageActivityProcessor reads entries stored in Baggage from the parent context | ||
and adds the baggage keys and values to the `Activity` as tags(attributes) on start. | ||
|
||
Add this activity processor to a tracer provider. | ||
|
||
Warning! | ||
|
||
To repeat: a consequence of adding data to Baggage is that the keys and values | ||
will appear in all outgoing trace context headers from the application. | ||
|
||
Do not put sensitive information in Baggage. | ||
|
||
## Component owners | ||
|
||
- [Mike Golsmith](https://github.com/MikeGoldsmith), Honeycomb | ||
|
||
Learn more about component owners in [component_owners.yml](../.github/component_owners.yml). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id("otel.java-conventions") | ||
|
||
id("otel.publish-conventions") | ||
} | ||
|
||
description = "OpenTelemetry Baggage Span Processor" | ||
otelJava.moduleName.set("io.opentelemetry.contrib.baggage.processor") | ||
|
||
dependencies { | ||
api("io.opentelemetry:opentelemetry-api") | ||
api("io.opentelemetry:opentelemetry-sdk") | ||
api("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi") | ||
|
||
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# TODO: uncomment when ready to mark as stable | ||
# otel.stable=true |
37 changes: 37 additions & 0 deletions
37
...cessor/src/main/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.baggage.processor; | ||
|
||
import io.opentelemetry.api.baggage.Baggage; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import io.opentelemetry.sdk.trace.SpanProcessor; | ||
|
||
/** | ||
* This span processor copies attributes stored in {@link Baggage} into each newly created {@link | ||
* io.opentelemetry.api.trace.Span}. | ||
*/ | ||
public class BaggageSpanProcessor implements SpanProcessor { | ||
@Override | ||
public void onStart(Context parentContext, ReadWriteSpan span) { | ||
Baggage.fromContext(parentContext) | ||
.forEach((s, baggageEntry) -> span.setAttribute(s, baggageEntry.getValue())); | ||
} | ||
|
||
@Override | ||
public boolean isStartRequired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onEnd(ReadableSpan span) {} | ||
|
||
@Override | ||
public boolean isEndRequired() { | ||
return false; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...or/src/test/java/io/opentelemetry/contrib/baggage/processor/BaggageSpanProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.baggage.processor; | ||
|
||
import io.opentelemetry.api.baggage.Baggage; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class BaggageSpanProcessorTest { | ||
|
||
@Test | ||
public void test_baggageSpanProcessor_adds_attributes_to_spans(@Mock ReadWriteSpan span) { | ||
try (BaggageSpanProcessor processor = new BaggageSpanProcessor()) { | ||
try (Scope ignore = Baggage.current().toBuilder().put("key", "value").build().makeCurrent()) { | ||
processor.onStart(Context.current(), span); | ||
Mockito.verify(span).setAttribute("key", "value"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters