Skip to content

Commit 8858220

Browse files
author
Sergei Malafeev
authored
Rename 'HttpTextFormat' to 'TextMapPropagator' (open-telemetry#1586)
* open-telemetry#1581 Rename 'HttpTextFormat' to 'TextMapPropagator' Signed-off-by: Sergei Malafeev <sergei@malafeev.org> * fix long line Signed-off-by: Sergei Malafeev <sergei@malafeev.org> * add change log entry Signed-off-by: Sergei Malafeev <sergei@malafeev.org> * add change log entry Signed-off-by: Sergei Malafeev <sergei@malafeev.org>
1 parent 20669f4 commit 8858220

33 files changed

Lines changed: 172 additions & 168 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- BREAKING CHANGE: Renamed HttpTextFormat to TextMapPropagator and implementations
45

56
## 0.7.0 - 2020-08-02
67

QUICKSTART.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ The following presents an example of an outgoing HTTP request using `HttpURLConn
178178

179179
```java
180180
// Tell OpenTelemetry to inject the context in the HTTP headers
181-
HttpTextFormat.Setter<HttpURLConnection> setter =
182-
new HttpTextFormat.Setter<HttpURLConnection>() {
181+
TextMapPropagator.Setter<HttpURLConnection> setter =
182+
new TextMapPropagator.Setter<HttpURLConnection>() {
183183
@Override
184184
public void put(HttpURLConnection carrier, String key, String value) {
185185
// Insert the context as Header
@@ -196,7 +196,7 @@ try (Scope scope = tracer.withSpan(outGoing)) {
196196
outGoing.setAttribute("http.url", url.toString());
197197
HttpURLConnection transportLayer = (HttpURLConnection) url.openConnection();
198198
// Inject the request with the *current* Context, which contains our current Span.
199-
OpenTelemetry.getPropagators().getHttpTextFormat().inject(Context.current(), transportLayer, setter);
199+
OpenTelemetry.getPropagators().getTextMapPropagator().inject(Context.current(), transportLayer, setter);
200200
// Make outgoing call
201201
} finally {
202202
outGoing.end();
@@ -209,8 +209,8 @@ The following presents an example of processing an incoming HTTP request using
209209
[HttpExchange](https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpExchange.html).
210210

211211
```java
212-
HttpTextFormat.Getter<HttpExchange> getter =
213-
new HttpTextFormat.Getter<HttpExchange>() {
212+
TextMapPropagator.Getter<HttpExchange> getter =
213+
new TextMapPropagator.Getter<HttpExchange>() {
214214
@Override
215215
public String get(HttpExchange carrier, String key) {
216216
if (carrier.getRequestHeaders().containsKey(key)) {
@@ -222,7 +222,7 @@ HttpTextFormat.Getter<HttpExchange> getter =
222222
...
223223
public void handle(HttpExchange httpExchange) {
224224
// Extract the SpanContext and other elements from the request.
225-
Context extractedContext = OpenTelemetry.getPropagators().getHttpTextFormat()
225+
Context extractedContext = OpenTelemetry.getPropagators().getTextMapPropagator()
226226
.extract(Context.current(), httpExchange, getter);
227227
Span serverSpan = null;
228228
try (Scope scope = ContextUtils.withScopedContext(extractedContext)) {

api/src/jmh/java/io/opentelemetry/trace/propagation/HttpTraceContextExtractBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package io.opentelemetry.trace.propagation;
1818

1919
import io.grpc.Context;
20-
import io.opentelemetry.context.propagation.HttpTextFormat.Getter;
20+
import io.opentelemetry.context.propagation.TextMapPropagator.Getter;
2121
import java.util.ArrayList;
2222
import java.util.Arrays;
2323
import java.util.HashMap;

api/src/jmh/java/io/opentelemetry/trace/propagation/HttpTraceContextInjectBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package io.opentelemetry.trace.propagation;
1818

1919
import io.grpc.Context;
20-
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
20+
import io.opentelemetry.context.propagation.TextMapPropagator.Setter;
2121
import io.opentelemetry.trace.DefaultSpan;
2222
import io.opentelemetry.trace.SpanContext;
2323
import io.opentelemetry.trace.SpanId;

api/src/main/java/io/opentelemetry/OpenTelemetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final class OpenTelemetry {
5757
private final CorrelationContextManager contextManager;
5858

5959
private volatile ContextPropagators propagators =
60-
DefaultContextPropagators.builder().addHttpTextFormat(new HttpTraceContext()).build();
60+
DefaultContextPropagators.builder().addTextMapPropagator(new HttpTraceContext()).build();
6161

6262
/**
6363
* Returns a singleton {@link TracerProvider}.

api/src/main/java/io/opentelemetry/trace/propagation/HttpTraceContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static io.opentelemetry.internal.Utils.checkNotNull;
2121

2222
import io.grpc.Context;
23-
import io.opentelemetry.context.propagation.HttpTextFormat;
23+
import io.opentelemetry.context.propagation.TextMapPropagator;
2424
import io.opentelemetry.internal.TemporaryBuffers;
2525
import io.opentelemetry.trace.DefaultSpan;
2626
import io.opentelemetry.trace.Span;
@@ -42,7 +42,7 @@
4242
* href=https://github.com/w3c/distributed-tracing>w3c/distributed-tracing</a>.
4343
*/
4444
@Immutable
45-
public class HttpTraceContext implements HttpTextFormat {
45+
public class HttpTraceContext implements TextMapPropagator {
4646
private static final Logger logger = Logger.getLogger(HttpTraceContext.class.getName());
4747

4848
private static final TraceState TRACE_STATE_DEFAULT = TraceState.builder().build();

api/src/test/java/io/opentelemetry/trace/propagation/HttpTraceContextTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import static org.assertj.core.api.Assertions.entry;
2323

2424
import io.grpc.Context;
25-
import io.opentelemetry.context.propagation.HttpTextFormat.Getter;
26-
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
25+
import io.opentelemetry.context.propagation.TextMapPropagator.Getter;
26+
import io.opentelemetry.context.propagation.TextMapPropagator.Setter;
2727
import io.opentelemetry.trace.DefaultSpan;
2828
import io.opentelemetry.trace.SpanContext;
2929
import io.opentelemetry.trace.SpanId;

context_prop/src/main/java/io/opentelemetry/context/propagation/ContextPropagators.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
* void onSendRequest() {
3535
* try (Scope scope = tracer.withSpan(span)) {
3636
* ContextPropagators propagators = OpenTelemetry.getPropagators();
37-
* HttpTextFormat textFormat = propagators.getHttpTextFormat();
37+
* TextMapPropagator textMapPropagator = propagators.getTextMapPropagator();
3838
*
3939
* // Inject the span's SpanContext and other available concerns (such as correlations)
4040
* // contained in the specified Context.
4141
* Map<String, String> map = new HashMap<>();
42-
* httpTextFormat.inject(Context.current(), map, new Setter<String, String>() {
42+
* textMapPropagator.inject(Context.current(), map, new Setter<String, String>() {
4343
* public void put(Map<String, String> map, String key, String value) {
4444
* map.put(key, value);
4545
* }
@@ -55,15 +55,17 @@
5555
* private static final Tracer tracer = OpenTelemetry.getTracer();
5656
* void onRequestReceived() {
5757
* ContextPropagators propagators = OpenTelemetry.getPropagators();
58-
* HttpTextFormat textFormat = propagators.getHttpTextFormat();
58+
* TextMapPropagator textMapPropagator = propagators.getTextMapPropagator();
5959
*
6060
* // Extract and store the propagated span's SpanContext and other available concerns
6161
* // in the specified Context.
62-
* Context context = textFormat.extract(Context.current(), request, new Getter<String, String>() {
63-
* public String get(Object request, String key) {
64-
* // Return the value associated to the key, if available.
62+
* Context context = textMapPropagator.extract(Context.current(), request,
63+
* new Getter<String, String>() {
64+
* public String get(Object request, String key) {
65+
* // Return the value associated to the key, if available.
66+
* }
6567
* }
66-
* });
68+
* );
6769
* Span span = tracer.spanBuilder("MyRequest")
6870
* .setParent(context)
6971
* .setSpanKind(Span.Kind.SERVER).startSpan();
@@ -81,14 +83,14 @@
8183
public interface ContextPropagators {
8284

8385
/**
84-
* Returns a {@link HttpTextFormat} propagator.
86+
* Returns a {@link TextMapPropagator} propagator.
8587
*
8688
* <p>The returned value will be a composite instance containing all the registered {@link
87-
* HttpTextFormat} propagators. If none is registered, the returned value will be a no-op
89+
* TextMapPropagator} propagators. If none is registered, the returned value will be a no-op
8890
* instance.
8991
*
90-
* @return the {@link HttpTextFormat} propagator to inject and extract data.
92+
* @return the {@link TextMapPropagator} propagator to inject and extract data.
9193
* @since 0.3.0
9294
*/
93-
HttpTextFormat getHttpTextFormat();
95+
TextMapPropagator getTextMapPropagator();
9496
}

context_prop/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
* @since 0.3.0
3232
*/
3333
public final class DefaultContextPropagators implements ContextPropagators {
34-
private final HttpTextFormat textFormat;
34+
private final TextMapPropagator textMapPropagator;
3535

3636
@Override
37-
public HttpTextFormat getHttpTextFormat() {
38-
return textFormat;
37+
public TextMapPropagator getTextMapPropagator() {
38+
return textMapPropagator;
3939
}
4040

4141
/**
@@ -49,8 +49,8 @@ public static Builder builder() {
4949
return new Builder();
5050
}
5151

52-
private DefaultContextPropagators(HttpTextFormat textFormat) {
53-
this.textFormat = textFormat;
52+
private DefaultContextPropagators(TextMapPropagator textMapPropagator) {
53+
this.textMapPropagator = textMapPropagator;
5454
}
5555

5656
/**
@@ -61,34 +61,34 @@ private DefaultContextPropagators(HttpTextFormat textFormat) {
6161
*
6262
* <pre>{@code
6363
* ContextPropagators propagators = DefaultContextPropagators.builder()
64-
* .addHttpTextFormat(new HttpTraceContext())
65-
* .addHttpTextFormat(new HttpCorrelationContext())
66-
* .addHttpTextFormat(new MyCustomContextPropagator())
64+
* .addTextMapPropagator(new HttpTraceContext())
65+
* .addTextMapPropagator(new HttpCorrelationContext())
66+
* .addTextMapPropagator(new MyCustomContextPropagator())
6767
* .build();
6868
* }</pre>
6969
*
7070
* @since 0.3.0
7171
*/
7272
public static final class Builder {
73-
List<HttpTextFormat> textPropagators = new ArrayList<>();
73+
List<TextMapPropagator> textPropagators = new ArrayList<>();
7474

7575
/**
76-
* Adds a {@link HttpTextFormat} propagator.
76+
* Adds a {@link TextMapPropagator} propagator.
7777
*
7878
* <p>One propagator per concern (traces, correlations, etc) should be added if this format is
7979
* supported.
8080
*
81-
* @param textFormat the propagator to be added.
81+
* @param textMapPropagator the propagator to be added.
8282
* @return this.
83-
* @throws NullPointerException if {@code textFormat} is {@code null}.
83+
* @throws NullPointerException if {@code textMapPropagator} is {@code null}.
8484
* @since 0.3.0
8585
*/
86-
public Builder addHttpTextFormat(HttpTextFormat textFormat) {
87-
if (textFormat == null) {
88-
throw new NullPointerException("textFormat");
86+
public Builder addTextMapPropagator(TextMapPropagator textMapPropagator) {
87+
if (textMapPropagator == null) {
88+
throw new NullPointerException("textMapPropagator");
8989
}
9090

91-
textPropagators.add(textFormat);
91+
textPropagators.add(textMapPropagator);
9292
return this;
9393
}
9494

@@ -100,19 +100,19 @@ public Builder addHttpTextFormat(HttpTextFormat textFormat) {
100100
*/
101101
public ContextPropagators build() {
102102
if (textPropagators.isEmpty()) {
103-
return new DefaultContextPropagators(NoopHttpTextFormat.INSTANCE);
103+
return new DefaultContextPropagators(NoopTextMapPropagator.INSTANCE);
104104
}
105105

106-
return new DefaultContextPropagators(new MultiHttpTextFormat(textPropagators));
106+
return new DefaultContextPropagators(new MultiTextMapPropagator(textPropagators));
107107
}
108108
}
109109

110-
private static final class MultiHttpTextFormat implements HttpTextFormat {
111-
private final HttpTextFormat[] textPropagators;
110+
private static final class MultiTextMapPropagator implements TextMapPropagator {
111+
private final TextMapPropagator[] textPropagators;
112112
private final List<String> allFields;
113113

114-
private MultiHttpTextFormat(List<HttpTextFormat> textPropagators) {
115-
this.textPropagators = new HttpTextFormat[textPropagators.size()];
114+
private MultiTextMapPropagator(List<TextMapPropagator> textPropagators) {
115+
this.textPropagators = new TextMapPropagator[textPropagators.size()];
116116
textPropagators.toArray(this.textPropagators);
117117
this.allFields = getAllFields(this.textPropagators);
118118
}
@@ -122,7 +122,7 @@ public List<String> fields() {
122122
return allFields;
123123
}
124124

125-
private static List<String> getAllFields(HttpTextFormat[] textPropagators) {
125+
private static List<String> getAllFields(TextMapPropagator[] textPropagators) {
126126
List<String> fields = new ArrayList<>();
127127
for (int i = 0; i < textPropagators.length; i++) {
128128
fields.addAll(textPropagators[i].fields());
@@ -147,8 +147,8 @@ public <C> Context extract(Context context, C carrier, Getter<C> getter) {
147147
}
148148
}
149149

150-
private static final class NoopHttpTextFormat implements HttpTextFormat {
151-
private static final NoopHttpTextFormat INSTANCE = new NoopHttpTextFormat();
150+
private static final class NoopTextMapPropagator implements TextMapPropagator {
151+
private static final NoopTextMapPropagator INSTANCE = new NoopTextMapPropagator();
152152

153153
@Override
154154
public List<String> fields() {

context_prop/src/main/java/io/opentelemetry/context/propagation/HttpTextFormat.java renamed to context_prop/src/main/java/io/opentelemetry/context/propagation/TextMapPropagator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*
3737
* <pre>{@code
3838
* public static final Context.Key CONCERN_KEY = Context.key("my-concern-key");
39-
* public MyConcernPropagator implements HttpTextFormat {
39+
* public MyConcernPropagator implements TextMapPropagator {
4040
* public <C> void inject(Context context, C carrier, Setter<C> setter) {
4141
* Object concern = CONCERN_KEY.get(context);
4242
* // Use concern in the specified context to propagate data.
@@ -51,7 +51,7 @@
5151
* @since 0.1.0
5252
*/
5353
@ThreadSafe
54-
public interface HttpTextFormat {
54+
public interface TextMapPropagator {
5555
/**
5656
* The propagation fields defined. If your carrier is reused, you should delete the fields here
5757
* before calling {@link #inject(Context, Object, Setter)} )}.
@@ -82,7 +82,7 @@ public interface HttpTextFormat {
8282
<C> void inject(Context context, @Nullable C carrier, Setter<C> setter);
8383

8484
/**
85-
* Class that allows a {@code HttpTextFormat} to set propagated fields into a carrier.
85+
* Class that allows a {@code TextMapPropagator} to set propagated fields into a carrier.
8686
*
8787
* <p>{@code Setter} is stateless and allows to be saved as a constant to avoid runtime
8888
* allocations.
@@ -124,7 +124,7 @@ interface Setter<C> {
124124
<C> Context extract(Context context, C carrier, Getter<C> getter);
125125

126126
/**
127-
* Interface that allows a {@code HttpTextFormat} to read propagated fields from a carrier.
127+
* Interface that allows a {@code TextMapPropagator} to read propagated fields from a carrier.
128128
*
129129
* <p>{@code Getter} is stateless and allows to be saved as a constant to avoid runtime
130130
* allocations.

0 commit comments

Comments
 (0)