Rename CorrelationContext with Baggage (#1691)
* Rename CorrelationContext with Baggage Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com> * Fix review comments Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com> * Rename contextBuildet to baggageBuilder Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
12af6d9fdf
commit
840ae850ec
|
|
@ -21,8 +21,8 @@ def subprojects = [
|
||||||
project(':opentelemetry-integration-tests'),
|
project(':opentelemetry-integration-tests'),
|
||||||
project(':opentelemetry-integration-tests-tracecontext'),
|
project(':opentelemetry-integration-tests-tracecontext'),
|
||||||
project(':opentelemetry-opentracing-shim'),
|
project(':opentelemetry-opentracing-shim'),
|
||||||
|
project(':opentelemetry-sdk-baggage'),
|
||||||
project(':opentelemetry-sdk-common'),
|
project(':opentelemetry-sdk-common'),
|
||||||
project(':opentelemetry-sdk-correlation-context'),
|
|
||||||
project(':opentelemetry-sdk-metrics'),
|
project(':opentelemetry-sdk-metrics'),
|
||||||
project(':opentelemetry-sdk-tracing'),
|
project(':opentelemetry-sdk-tracing'),
|
||||||
project(':opentelemetry-sdk'),
|
project(':opentelemetry-sdk'),
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
package io.opentelemetry;
|
package io.opentelemetry;
|
||||||
|
|
||||||
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
|
import io.opentelemetry.baggage.DefaultBaggageManager;
|
||||||
|
import io.opentelemetry.baggage.spi.BaggageManagerFactory;
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.context.propagation.DefaultContextPropagators;
|
import io.opentelemetry.context.propagation.DefaultContextPropagators;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
|
||||||
import io.opentelemetry.correlationcontext.DefaultCorrelationContextManager;
|
|
||||||
import io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory;
|
|
||||||
import io.opentelemetry.internal.Obfuscated;
|
import io.opentelemetry.internal.Obfuscated;
|
||||||
import io.opentelemetry.internal.Utils;
|
import io.opentelemetry.internal.Utils;
|
||||||
import io.opentelemetry.metrics.DefaultMeterProvider;
|
import io.opentelemetry.metrics.DefaultMeterProvider;
|
||||||
|
|
@ -38,13 +38,13 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a static global accessor for telemetry objects {@link Tracer}, {@link Meter}
|
* This class provides a static global accessor for telemetry objects {@link Tracer}, {@link Meter}
|
||||||
* and {@link CorrelationContextManager}.
|
* and {@link BaggageManager}.
|
||||||
*
|
*
|
||||||
* <p>The telemetry objects are lazy-loaded singletons resolved via {@link ServiceLoader} mechanism.
|
* <p>The telemetry objects are lazy-loaded singletons resolved via {@link ServiceLoader} mechanism.
|
||||||
*
|
*
|
||||||
* @see TracerProvider
|
* @see TracerProvider
|
||||||
* @see MeterProviderFactory
|
* @see MeterProviderFactory
|
||||||
* @see CorrelationContextManagerFactory
|
* @see BaggageManagerFactory
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
public final class OpenTelemetry {
|
public final class OpenTelemetry {
|
||||||
|
|
@ -54,7 +54,7 @@ public final class OpenTelemetry {
|
||||||
|
|
||||||
private final TracerProvider tracerProvider;
|
private final TracerProvider tracerProvider;
|
||||||
private final MeterProvider meterProvider;
|
private final MeterProvider meterProvider;
|
||||||
private final CorrelationContextManager contextManager;
|
private final BaggageManager contextManager;
|
||||||
|
|
||||||
private volatile ContextPropagators propagators = DefaultContextPropagators.builder().build();
|
private volatile ContextPropagators propagators = DefaultContextPropagators.builder().build();
|
||||||
|
|
||||||
|
|
@ -144,15 +144,14 @@ public final class OpenTelemetry {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a singleton {@link CorrelationContextManager}.
|
* Returns a singleton {@link BaggageManager}.
|
||||||
*
|
*
|
||||||
* @return registered manager or default via {@link
|
* @return registered manager or default via {@link DefaultBaggageManager#getInstance()}.
|
||||||
* DefaultCorrelationContextManager#getInstance()}.
|
|
||||||
* @throws IllegalStateException if a specified manager (via system properties) could not be
|
* @throws IllegalStateException if a specified manager (via system properties) could not be
|
||||||
* found.
|
* found.
|
||||||
* @since 0.1.0
|
* @since 0.1.0
|
||||||
*/
|
*/
|
||||||
public static CorrelationContextManager getCorrelationContextManager() {
|
public static BaggageManager getBaggageManager() {
|
||||||
return getInstance().contextManager;
|
return getInstance().contextManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,12 +208,11 @@ public final class OpenTelemetry {
|
||||||
meterProviderFactory != null
|
meterProviderFactory != null
|
||||||
? meterProviderFactory.create()
|
? meterProviderFactory.create()
|
||||||
: DefaultMeterProvider.getInstance();
|
: DefaultMeterProvider.getInstance();
|
||||||
CorrelationContextManagerFactory contextManagerProvider =
|
BaggageManagerFactory contextManagerProvider = loadSpi(BaggageManagerFactory.class);
|
||||||
loadSpi(CorrelationContextManagerFactory.class);
|
|
||||||
contextManager =
|
contextManager =
|
||||||
contextManagerProvider != null
|
contextManagerProvider != null
|
||||||
? contextManagerProvider.create()
|
? contextManagerProvider.create()
|
||||||
: DefaultCorrelationContextManager.getInstance();
|
: DefaultBaggageManager.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
import io.grpc.Context;
|
import io.grpc.Context;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -25,19 +25,19 @@ import javax.annotation.concurrent.Immutable;
|
||||||
* A map from {@link String} to {@link String} and {@link EntryMetadata} that can be used to label
|
* A map from {@link String} to {@link String} and {@link EntryMetadata} that can be used to label
|
||||||
* anything that is associated with a specific operation.
|
* anything that is associated with a specific operation.
|
||||||
*
|
*
|
||||||
* <p>For example, {@code CorrelationContext}s can be used to label stats, log messages, or
|
* <p>For example, {@code Baggage}s can be used to label stats, log messages, or debugging
|
||||||
* debugging information.
|
* information.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
public interface CorrelationContext {
|
public interface Baggage {
|
||||||
/**
|
/**
|
||||||
* Returns an immutable collection of the entries in this {@code CorrelationContext}. Order of
|
* Returns an immutable collection of the entries in this {@code Baggage}. Order of entries is not
|
||||||
* entries is not guaranteed.
|
* guaranteed.
|
||||||
*
|
*
|
||||||
* @return an immutable collection of the entries in this {@code CorrelationContext}.
|
* @return an immutable collection of the entries in this {@code Baggage}.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
Collection<Entry> getEntries();
|
Collection<Entry> getEntries();
|
||||||
|
|
||||||
|
|
@ -46,47 +46,45 @@ public interface CorrelationContext {
|
||||||
*
|
*
|
||||||
* @param entryKey entry key to return the value for.
|
* @param entryKey entry key to return the value for.
|
||||||
* @return the value associated with the given key, or {@code null} if no {@code Entry} with the
|
* @return the value associated with the given key, or {@code null} if no {@code Entry} with the
|
||||||
* given {@code entryKey} is in this {@code CorrelationContext}.
|
* given {@code entryKey} is in this {@code Baggage}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String getEntryValue(String entryKey);
|
String getEntryValue(String entryKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for the {@link CorrelationContext} class.
|
* Builder for the {@link Baggage} class.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
interface Builder {
|
interface Builder {
|
||||||
/**
|
/**
|
||||||
* Sets the parent {@link CorrelationContext} to use. If no parent is provided, the value of
|
* Sets the parent {@link Baggage} to use. If no parent is provided, the value of {@link
|
||||||
* {@link CorrelationContextManager#getCurrentContext()} at {@link #build()} time will be used
|
* BaggageManager#getCurrentBaggage()} at {@link #build()} time will be used as parent, unless
|
||||||
* as parent, unless {@link #setNoParent()} was called.
|
* {@link #setNoParent()} was called.
|
||||||
*
|
*
|
||||||
* <p>This <b>must</b> be used to create a {@link CorrelationContext} when manual Context
|
* <p>This <b>must</b> be used to create a {@link Baggage} when manual Context propagation is
|
||||||
* propagation is used.
|
* used.
|
||||||
*
|
*
|
||||||
* <p>If called multiple times, only the last specified value will be used.
|
* <p>If called multiple times, only the last specified value will be used.
|
||||||
*
|
*
|
||||||
* @param parent the {@link CorrelationContext} used as parent, not null.
|
* @param parent the {@link Baggage} used as parent, not null.
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws NullPointerException if {@code parent} is {@code null}.
|
* @throws NullPointerException if {@code parent} is {@code null}.
|
||||||
* @see #setNoParent()
|
* @see #setNoParent()
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
Builder setParent(CorrelationContext parent);
|
Builder setParent(Baggage parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the parent {@link CorrelationContext} to use from the specified {@code Context}. If no
|
* Sets the parent {@link Baggage} to use from the specified {@code Context}. If no parent
|
||||||
* parent {@link CorrelationContext} is provided, the value of {@link
|
* {@link Baggage} is provided, the value of {@link BaggageManager#getCurrentBaggage()} at
|
||||||
* CorrelationContextManager#getCurrentContext()} at {@link #build()} time will be used as
|
* {@link #build()} time will be used as parent, unless {@link #setNoParent()} was called.
|
||||||
* parent, unless {@link #setNoParent()} was called.
|
|
||||||
*
|
*
|
||||||
* <p>If no parent {@link CorrelationContext} is available in the specified {@code Context}, the
|
* <p>If no parent {@link Baggage} is available in the specified {@code Context}, the resulting
|
||||||
* resulting {@link CorrelationContext} will become a root instance, as if {@link
|
* {@link Baggage} will become a root instance, as if {@link #setNoParent()} had been called.
|
||||||
* #setNoParent()} had been called.
|
|
||||||
*
|
*
|
||||||
* <p>This <b>must</b> be used to create a {@link CorrelationContext} when manual Context
|
* <p>This <b>must</b> be used to create a {@link Baggage} when manual Context propagation is
|
||||||
* propagation is used.
|
* used.
|
||||||
*
|
*
|
||||||
* <p>If called multiple times, only the last specified value will be used.
|
* <p>If called multiple times, only the last specified value will be used.
|
||||||
*
|
*
|
||||||
|
|
@ -94,18 +92,17 @@ public interface CorrelationContext {
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws NullPointerException if {@code context} is {@code null}.
|
* @throws NullPointerException if {@code context} is {@code null}.
|
||||||
* @see #setNoParent()
|
* @see #setNoParent()
|
||||||
* @since 0.7.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
Builder setParent(Context context);
|
Builder setParent(Context context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the option to become a root {@link CorrelationContext} with no parent. If <b>not</b>
|
* Sets the option to become a root {@link Baggage} with no parent. If <b>not</b> called, the
|
||||||
* called, the value provided using {@link #setParent(CorrelationContext)} or otherwise {@link
|
* value provided using {@link #setParent(Baggage)} or otherwise {@link
|
||||||
* CorrelationContextManager#getCurrentContext()} at {@link #build()} time will be used as
|
* BaggageManager#getCurrentBaggage()} at {@link #build()} time will be used as parent.
|
||||||
* parent.
|
|
||||||
*
|
*
|
||||||
* @return this.
|
* @return this.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
Builder setNoParent();
|
Builder setNoParent();
|
||||||
|
|
||||||
|
|
@ -116,7 +113,7 @@ public interface CorrelationContext {
|
||||||
* @param value the {@code String} value to set for the given key.
|
* @param value the {@code String} value to set for the given key.
|
||||||
* @param entryMetadata the {@code EntryMetadata} associated with this {@link Entry}.
|
* @param entryMetadata the {@code EntryMetadata} associated with this {@link Entry}.
|
||||||
* @return this
|
* @return this
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
Builder put(String key, String value, EntryMetadata entryMetadata);
|
Builder put(String key, String value, EntryMetadata entryMetadata);
|
||||||
|
|
||||||
|
|
@ -125,16 +122,16 @@ public interface CorrelationContext {
|
||||||
*
|
*
|
||||||
* @param key the {@code String} key which will be removed.
|
* @param key the {@code String} key which will be removed.
|
||||||
* @return this
|
* @return this
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
Builder remove(String key);
|
Builder remove(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code CorrelationContext} from this builder.
|
* Creates a {@code Baggage} from this builder.
|
||||||
*
|
*
|
||||||
* @return a {@code CorrelationContext} with the same entries as this builder.
|
* @return a {@code Baggage} with the same entries as this builder.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
CorrelationContext build();
|
Baggage build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019, OpenTelemetry Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
|
import io.opentelemetry.context.Scope;
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object for creating new {@link Baggage}s and {@code Baggage}s based on the current context.
|
||||||
|
*
|
||||||
|
* <p>This class returns {@link Baggage.Builder builders} that can be used to create the
|
||||||
|
* implementation-dependent {@link Baggage}s.
|
||||||
|
*
|
||||||
|
* <p>Implementations may have different constraints and are free to convert entry contexts to their
|
||||||
|
* own subtypes. This means callers cannot assume the {@link #getCurrentBaggage() current context}
|
||||||
|
* is the same instance as the one {@link #withContext(Baggage) placed into scope}.
|
||||||
|
*
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
public interface BaggageManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current {@code Baggage}.
|
||||||
|
*
|
||||||
|
* @return the current {@code Baggage}.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
Baggage getCurrentBaggage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link Baggage.Builder}.
|
||||||
|
*
|
||||||
|
* @return a new {@code Baggage.Builder}.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
Baggage.Builder baggageBuilder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enters the scope of code where the given {@code Baggage} is in the current context (replacing
|
||||||
|
* the previous {@code Baggage}) and returns an object that represents that scope. The scope is
|
||||||
|
* exited when the returned object is closed.
|
||||||
|
*
|
||||||
|
* @param distContext the {@code Baggage} to be set as the current context.
|
||||||
|
* @return an object that defines a scope where the given {@code Baggage} is set as the current
|
||||||
|
* context.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
Scope withContext(Baggage distContext);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019, OpenTelemetry Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
|
import io.grpc.Context;
|
||||||
|
import io.opentelemetry.context.ContextUtils;
|
||||||
|
import io.opentelemetry.context.Scope;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility methods for accessing the {@link Baggage} contained in the {@link io.grpc.Context}.
|
||||||
|
*
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
public final class BaggageUtils {
|
||||||
|
private static final Context.Key<Baggage> CORR_CONTEXT_KEY =
|
||||||
|
Context.key("opentelemetry-corr-context-key");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@code Context} with the given value set.
|
||||||
|
*
|
||||||
|
* @param baggage the value to be set.
|
||||||
|
* @param context the parent {@code Context}.
|
||||||
|
* @return a new context with the given value set.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
public static Context withBaggage(Baggage baggage, Context context) {
|
||||||
|
return context.withValue(CORR_CONTEXT_KEY, baggage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link Baggage} from the {@linkplain Context#current current context}, falling back
|
||||||
|
* to an empty {@link Baggage}.
|
||||||
|
*
|
||||||
|
* @return the {@link Baggage} from the {@linkplain Context#current current context}.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
public static Baggage getCurrentBaggage() {
|
||||||
|
return getBaggage(Context.current());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link Baggage} from the specified {@code Context}, falling back to an empty {@link
|
||||||
|
* Baggage}.
|
||||||
|
*
|
||||||
|
* @param context the specified {@code Context}.
|
||||||
|
* @return the {@link Baggage} from the specified {@code Context}.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
public static Baggage getBaggage(Context context) {
|
||||||
|
Baggage baggage = CORR_CONTEXT_KEY.get(context);
|
||||||
|
return baggage == null ? EmptyBaggage.getInstance() : baggage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link Baggage} from the specified {@code Context}. If none is found, this method
|
||||||
|
* returns {code null}.
|
||||||
|
*
|
||||||
|
* @param context the specified {@code Context}.
|
||||||
|
* @return the {@link Baggage} from the specified {@code Context}.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static Baggage getBaggageWithoutDefault(Context context) {
|
||||||
|
return CORR_CONTEXT_KEY.get(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link Scope} encapsulating the provided {@link Baggage} added to the current
|
||||||
|
* {@code Context}.
|
||||||
|
*
|
||||||
|
* @param baggage the {@link Baggage} to be added to the current {@code Context}.
|
||||||
|
* @return the {@link Scope} for the updated {@code Context}.
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
public static Scope currentContextWith(Baggage baggage) {
|
||||||
|
Context context = withBaggage(baggage, Context.current());
|
||||||
|
return ContextUtils.withScopedContext(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BaggageUtils() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019, OpenTelemetry Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
|
import io.grpc.Context;
|
||||||
|
import io.opentelemetry.context.Scope;
|
||||||
|
import io.opentelemetry.internal.Utils;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No-op implementations of {@link BaggageManager}.
|
||||||
|
*
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
public final class DefaultBaggageManager implements BaggageManager {
|
||||||
|
private static final DefaultBaggageManager INSTANCE = new DefaultBaggageManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@code BaggageManager} singleton that is the default implementation for {@link
|
||||||
|
* BaggageManager}.
|
||||||
|
*
|
||||||
|
* @return a {@code BaggageManager} singleton that is the default implementation for {@link
|
||||||
|
* BaggageManager}.
|
||||||
|
*/
|
||||||
|
public static BaggageManager getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage getCurrentBaggage() {
|
||||||
|
return BaggageUtils.getCurrentBaggage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage.Builder baggageBuilder() {
|
||||||
|
return new NoopBaggageBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Scope withContext(Baggage distContext) {
|
||||||
|
return BaggageUtils.currentContextWith(distContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
private static final class NoopBaggageBuilder implements Baggage.Builder {
|
||||||
|
@Override
|
||||||
|
public Baggage.Builder setParent(Baggage parent) {
|
||||||
|
Utils.checkNotNull(parent, "parent");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage.Builder setParent(Context context) {
|
||||||
|
Utils.checkNotNull(context, "context");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage.Builder setNoParent() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage.Builder put(String key, String value, EntryMetadata entryMetadata) {
|
||||||
|
Utils.checkNotNull(key, "key");
|
||||||
|
Utils.checkNotNull(value, "value");
|
||||||
|
Utils.checkNotNull(entryMetadata, "entryMetadata");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage.Builder remove(String key) {
|
||||||
|
Utils.checkNotNull(key, "key");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage build() {
|
||||||
|
return EmptyBaggage.getInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,29 +14,27 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
/**
|
/** An immutable implementation of the {@link Baggage} that does not contain any entries. */
|
||||||
* An immutable implementation of the {@link CorrelationContext} that does not contain any entries.
|
|
||||||
*/
|
|
||||||
@Immutable
|
@Immutable
|
||||||
public class EmptyCorrelationContext implements CorrelationContext {
|
public class EmptyBaggage implements Baggage {
|
||||||
/**
|
/**
|
||||||
* Returns the single instance of the {@link EmptyCorrelationContext} class.
|
* Returns the single instance of the {@link EmptyBaggage} class.
|
||||||
*
|
*
|
||||||
* @return the single instance of the {@code EmptyCorrelationContext} class.
|
* @return the single instance of the {@code EmptyBaggage} class.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public static CorrelationContext getInstance() {
|
public static Baggage getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final CorrelationContext INSTANCE = new EmptyCorrelationContext();
|
private static final Baggage INSTANCE = new EmptyBaggage();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Entry> getEntries() {
|
public Collection<Entry> getEntries() {
|
||||||
|
|
@ -49,5 +47,5 @@ public class EmptyCorrelationContext implements CorrelationContext {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmptyCorrelationContext() {}
|
private EmptyBaggage() {}
|
||||||
}
|
}
|
||||||
|
|
@ -14,10 +14,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import io.opentelemetry.correlationcontext.EntryMetadata.EntryTtl;
|
import io.opentelemetry.baggage.EntryMetadata.EntryTtl;
|
||||||
import io.opentelemetry.internal.StringUtils;
|
import io.opentelemetry.internal.StringUtils;
|
||||||
import io.opentelemetry.internal.Utils;
|
import io.opentelemetry.internal.Utils;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
@ -25,7 +25,7 @@ import javax.annotation.concurrent.Immutable;
|
||||||
/**
|
/**
|
||||||
* String-String key-value pair, along with {@link EntryMetadata}.
|
* String-String key-value pair, along with {@link EntryMetadata}.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@AutoValue
|
@AutoValue
|
||||||
|
|
@ -33,14 +33,14 @@ public abstract class Entry {
|
||||||
/**
|
/**
|
||||||
* The maximum length for an entry key name. The value is {@value #MAX_KEY_LENGTH}.
|
* The maximum length for an entry key name. The value is {@value #MAX_KEY_LENGTH}.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public static final int MAX_KEY_LENGTH = 255;
|
public static final int MAX_KEY_LENGTH = 255;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum length for a entry value. The value is {@value #MAX_VALUE_LENGTH}.
|
* The maximum length for a entry value. The value is {@value #MAX_VALUE_LENGTH}.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public static final int MAX_VALUE_LENGTH = 255;
|
public static final int MAX_VALUE_LENGTH = 255;
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ public abstract class Entry {
|
||||||
* @param value the entry value.
|
* @param value the entry value.
|
||||||
* @param entryMetadata the entry metadata.
|
* @param entryMetadata the entry metadata.
|
||||||
* @return a {@code Entry}.
|
* @return a {@code Entry}.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public static Entry create(String key, String value, EntryMetadata entryMetadata) {
|
public static Entry create(String key, String value, EntryMetadata entryMetadata) {
|
||||||
Utils.checkArgument(keyIsValid(key), "Invalid entry key name: %s", key);
|
Utils.checkArgument(keyIsValid(key), "Invalid entry key name: %s", key);
|
||||||
|
|
@ -69,7 +69,7 @@ public abstract class Entry {
|
||||||
* Returns the entry's key.
|
* Returns the entry's key.
|
||||||
*
|
*
|
||||||
* @return the entry's key.
|
* @return the entry's key.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public abstract String getKey();
|
public abstract String getKey();
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ public abstract class Entry {
|
||||||
* Returns the entry's value.
|
* Returns the entry's value.
|
||||||
*
|
*
|
||||||
* @return the entry's value.
|
* @return the entry's value.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public abstract String getValue();
|
public abstract String getValue();
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ public abstract class Entry {
|
||||||
* Returns the {@link EntryMetadata} associated with this {@link Entry}.
|
* Returns the {@link EntryMetadata} associated with this {@link Entry}.
|
||||||
*
|
*
|
||||||
* @return the {@code EntryMetadata}.
|
* @return the {@code EntryMetadata}.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public abstract EntryMetadata getEntryMetadata();
|
public abstract EntryMetadata getEntryMetadata();
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
@ -25,7 +25,7 @@ import javax.annotation.concurrent.Immutable;
|
||||||
* <p>For now only the property {@link EntryTtl} is defined. In future, additional properties may be
|
* <p>For now only the property {@link EntryTtl} is defined. In future, additional properties may be
|
||||||
* added to address specific situations.
|
* added to address specific situations.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@AutoValue
|
@AutoValue
|
||||||
|
|
@ -38,7 +38,7 @@ public abstract class EntryMetadata {
|
||||||
*
|
*
|
||||||
* @param entryTtl TTL of an {@code Entry}.
|
* @param entryTtl TTL of an {@code Entry}.
|
||||||
* @return an {@code EntryMetadata}.
|
* @return an {@code EntryMetadata}.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public static EntryMetadata create(EntryTtl entryTtl) {
|
public static EntryMetadata create(EntryTtl entryTtl) {
|
||||||
return new AutoValue_EntryMetadata(entryTtl);
|
return new AutoValue_EntryMetadata(entryTtl);
|
||||||
|
|
@ -48,7 +48,7 @@ public abstract class EntryMetadata {
|
||||||
* Returns the {@link EntryTtl} of this {@link EntryMetadata}.
|
* Returns the {@link EntryTtl} of this {@link EntryMetadata}.
|
||||||
*
|
*
|
||||||
* @return the {@code EntryTtl}.
|
* @return the {@code EntryTtl}.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public abstract EntryTtl getEntryTtl();
|
public abstract EntryTtl getEntryTtl();
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ public abstract class EntryMetadata {
|
||||||
*
|
*
|
||||||
* <p>For now, only special values of {@link EntryTtl} are supported.
|
* <p>For now, only special values of {@link EntryTtl} are supported.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
public enum EntryTtl {
|
public enum EntryTtl {
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ public abstract class EntryMetadata {
|
||||||
* An {@link Entry} with {@link EntryTtl#NO_PROPAGATION} is considered to have local scope and
|
* An {@link Entry} with {@link EntryTtl#NO_PROPAGATION} is considered to have local scope and
|
||||||
* is used within the process where it's created.
|
* is used within the process where it's created.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
NO_PROPAGATION(0),
|
NO_PROPAGATION(0),
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ public abstract class EntryMetadata {
|
||||||
* <p>{@link EntryTtl#UNLIMITED_PROPAGATION} is typical used to track a request, which may be
|
* <p>{@link EntryTtl#UNLIMITED_PROPAGATION} is typical used to track a request, which may be
|
||||||
* processed across multiple entities.
|
* processed across multiple entities.
|
||||||
*
|
*
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
UNLIMITED_PROPAGATION(-1);
|
UNLIMITED_PROPAGATION(-1);
|
||||||
|
|
||||||
|
|
@ -21,12 +21,11 @@
|
||||||
* to label anything that is associated with a specific operation. For example, the {@code
|
* to label anything that is associated with a specific operation. For example, the {@code
|
||||||
* opentelemetry.stats} package labels all stats with the current entries.
|
* opentelemetry.stats} package labels all stats with the current entries.
|
||||||
*
|
*
|
||||||
* <p>{@link io.opentelemetry.correlationcontext.Entry Entrys} are key-value pairs of {@link
|
* <p>{@link io.opentelemetry.baggage.Entry Entrys} are key-value pairs of {@link
|
||||||
* java.lang.String}s. They are stored as a map in a {@link
|
* java.lang.String}s. They are stored as a map in a {@link io.opentelemetry.baggage.Baggage}.
|
||||||
* io.opentelemetry.correlationcontext.CorrelationContext}.
|
|
||||||
*
|
*
|
||||||
* <p>Note that entries are independent of the tracing data that is propagated in the {@code
|
* <p>Note that entries are independent of the tracing data that is propagated in the {@code
|
||||||
* io.grpc.Context}, such as trace ID.
|
* io.grpc.Context}, such as trace ID.
|
||||||
*/
|
*/
|
||||||
// TODO: Add code examples.
|
// TODO: Add code examples.
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
@ -14,30 +14,29 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext.spi;
|
package io.opentelemetry.baggage.spi;
|
||||||
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CorrelationContextManagerFactory is a service provider for {@link CorrelationContextManager}.
|
* BaggageManagerFactory is a service provider for {@link BaggageManager}. Fully qualified class
|
||||||
* Fully qualified class name of the implementation should be registered in {@code
|
* name of the implementation should be registered in {@code
|
||||||
* META-INF/services/io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory}. <br>
|
* META-INF/services/io.opentelemetry.baggage.spi.BaggageManagerFactory}. <br>
|
||||||
* <br>
|
* <br>
|
||||||
* A specific implementation can be selected by a system property {@code
|
* A specific implementation can be selected by a system property {@code
|
||||||
* io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory} with value of fully
|
* io.opentelemetry.baggage.spi.BaggageManagerFactory} with value of fully qualified class name.
|
||||||
* qualified class name.
|
|
||||||
*
|
*
|
||||||
* @see io.opentelemetry.OpenTelemetry
|
* @see io.opentelemetry.OpenTelemetry
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
public interface CorrelationContextManagerFactory {
|
public interface BaggageManagerFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@code CorrelationContextManager} instance.
|
* Creates a new {@code BaggageManager} instance.
|
||||||
*
|
*
|
||||||
* @return a {@code CorrelationContextManager} instance.
|
* @return a {@code BaggageManager} instance.
|
||||||
* @since 0.1.0
|
* @since 0.9.0
|
||||||
*/
|
*/
|
||||||
CorrelationContextManager create();
|
BaggageManager create();
|
||||||
}
|
}
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Object for creating new {@link CorrelationContext}s and {@code CorrelationContext}s based on the
|
|
||||||
* current context.
|
|
||||||
*
|
|
||||||
* <p>This class returns {@link CorrelationContext.Builder builders} that can be used to create the
|
|
||||||
* implementation-dependent {@link CorrelationContext}s.
|
|
||||||
*
|
|
||||||
* <p>Implementations may have different constraints and are free to convert entry contexts to their
|
|
||||||
* own subtypes. This means callers cannot assume the {@link #getCurrentContext() current context}
|
|
||||||
* is the same instance as the one {@link #withContext(CorrelationContext) placed into scope}.
|
|
||||||
*
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
@ThreadSafe
|
|
||||||
public interface CorrelationContextManager {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current {@code CorrelationContext}.
|
|
||||||
*
|
|
||||||
* @return the current {@code CorrelationContext}.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
CorrelationContext getCurrentContext();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@code Builder}.
|
|
||||||
*
|
|
||||||
* @return a new {@code Builder}.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
CorrelationContext.Builder contextBuilder();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enters the scope of code where the given {@code CorrelationContext} is in the current context
|
|
||||||
* (replacing the previous {@code CorrelationContext}) and returns an object that represents that
|
|
||||||
* scope. The scope is exited when the returned object is closed.
|
|
||||||
*
|
|
||||||
* @param distContext the {@code CorrelationContext} to be set as the current context.
|
|
||||||
* @return an object that defines a scope where the given {@code CorrelationContext} is set as the
|
|
||||||
* current context.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
Scope withContext(CorrelationContext distContext);
|
|
||||||
}
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
|
||||||
|
|
||||||
import io.grpc.Context;
|
|
||||||
import io.opentelemetry.context.ContextUtils;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility methods for accessing the {@link CorrelationContext} contained in the {@link
|
|
||||||
* io.grpc.Context}.
|
|
||||||
*
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
@Immutable
|
|
||||||
public final class CorrelationsContextUtils {
|
|
||||||
private static final Context.Key<CorrelationContext> CORR_CONTEXT_KEY =
|
|
||||||
Context.key("opentelemetry-corr-context-key");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@code Context} with the given value set.
|
|
||||||
*
|
|
||||||
* @param corrContext the value to be set.
|
|
||||||
* @param context the parent {@code Context}.
|
|
||||||
* @return a new context with the given value set.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
public static Context withCorrelationContext(CorrelationContext corrContext, Context context) {
|
|
||||||
return context.withValue(CORR_CONTEXT_KEY, corrContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link CorrelationContext} from the current {@code Context}, falling back to an
|
|
||||||
* empty {@link CorrelationContext}.
|
|
||||||
*
|
|
||||||
* @return the {@link CorrelationContext} from the current {@code Context}.
|
|
||||||
* @since 0.3.0
|
|
||||||
*/
|
|
||||||
public static CorrelationContext getCurrentCorrelationContext() {
|
|
||||||
return getCorrelationContext(Context.current());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link CorrelationContext} from the specified {@code Context}, falling back to an
|
|
||||||
* empty {@link CorrelationContext}.
|
|
||||||
*
|
|
||||||
* @param context the specified {@code Context}.
|
|
||||||
* @return the {@link CorrelationContext} from the specified {@code Context}.
|
|
||||||
* @since 0.3.0
|
|
||||||
*/
|
|
||||||
public static CorrelationContext getCorrelationContext(Context context) {
|
|
||||||
CorrelationContext corrContext = CORR_CONTEXT_KEY.get(context);
|
|
||||||
return corrContext == null ? EmptyCorrelationContext.getInstance() : corrContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link CorrelationContext} from the specified {@code Context}. If none is found,
|
|
||||||
* this method returns {code null}.
|
|
||||||
*
|
|
||||||
* @param context the specified {@code Context}.
|
|
||||||
* @return the {@link CorrelationContext} from the specified {@code Context}.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public static CorrelationContext getCorrelationContextWithoutDefault(Context context) {
|
|
||||||
return CORR_CONTEXT_KEY.get(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@link Scope} encapsulating the provided {@link CorrelationContext} added to the
|
|
||||||
* current {@code Context}.
|
|
||||||
*
|
|
||||||
* @param corrContext the {@link CorrelationContext} to be added to the current {@code Context}.
|
|
||||||
* @return the {@link Scope} for the updated {@code Context}.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
public static Scope currentContextWith(CorrelationContext corrContext) {
|
|
||||||
Context context = withCorrelationContext(corrContext, Context.current());
|
|
||||||
return ContextUtils.withScopedContext(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CorrelationsContextUtils() {}
|
|
||||||
}
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
|
||||||
|
|
||||||
import io.grpc.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.internal.Utils;
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* No-op implementations of {@link CorrelationContextManager}.
|
|
||||||
*
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
@ThreadSafe
|
|
||||||
public final class DefaultCorrelationContextManager implements CorrelationContextManager {
|
|
||||||
private static final DefaultCorrelationContextManager INSTANCE =
|
|
||||||
new DefaultCorrelationContextManager();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a {@code CorrelationContextManager} singleton that is the default implementation for
|
|
||||||
* {@link CorrelationContextManager}.
|
|
||||||
*
|
|
||||||
* @return a {@code CorrelationContextManager} singleton that is the default implementation for
|
|
||||||
* {@link CorrelationContextManager}.
|
|
||||||
*/
|
|
||||||
public static CorrelationContextManager getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext getCurrentContext() {
|
|
||||||
return CorrelationsContextUtils.getCurrentCorrelationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext.Builder contextBuilder() {
|
|
||||||
return new NoopCorrelationContextBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Scope withContext(CorrelationContext distContext) {
|
|
||||||
return CorrelationsContextUtils.currentContextWith(distContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
private static final class NoopCorrelationContextBuilder implements CorrelationContext.Builder {
|
|
||||||
@Override
|
|
||||||
public CorrelationContext.Builder setParent(CorrelationContext parent) {
|
|
||||||
Utils.checkNotNull(parent, "parent");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext.Builder setParent(Context context) {
|
|
||||||
Utils.checkNotNull(context, "context");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext.Builder setNoParent() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext.Builder put(String key, String value, EntryMetadata entryMetadata) {
|
|
||||||
Utils.checkNotNull(key, "key");
|
|
||||||
Utils.checkNotNull(value, "value");
|
|
||||||
Utils.checkNotNull(entryMetadata, "entryMetadata");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext.Builder remove(String key) {
|
|
||||||
Utils.checkNotNull(key, "key");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext build() {
|
|
||||||
return EmptyCorrelationContext.getInstance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -20,13 +20,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import io.opentelemetry.baggage.Baggage;
|
||||||
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
|
import io.opentelemetry.baggage.DefaultBaggageManager;
|
||||||
|
import io.opentelemetry.baggage.spi.BaggageManagerFactory;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.context.propagation.DefaultContextPropagators;
|
import io.opentelemetry.context.propagation.DefaultContextPropagators;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
|
||||||
import io.opentelemetry.correlationcontext.DefaultCorrelationContextManager;
|
|
||||||
import io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory;
|
|
||||||
import io.opentelemetry.metrics.BatchRecorder;
|
import io.opentelemetry.metrics.BatchRecorder;
|
||||||
import io.opentelemetry.metrics.DefaultMeterProvider;
|
import io.opentelemetry.metrics.DefaultMeterProvider;
|
||||||
import io.opentelemetry.metrics.DoubleCounter;
|
import io.opentelemetry.metrics.DoubleCounter;
|
||||||
|
|
@ -71,7 +71,7 @@ class OpenTelemetryTest {
|
||||||
OpenTelemetry.reset();
|
OpenTelemetry.reset();
|
||||||
System.clearProperty(TracerProviderFactory.class.getName());
|
System.clearProperty(TracerProviderFactory.class.getName());
|
||||||
System.clearProperty(MeterProviderFactory.class.getName());
|
System.clearProperty(MeterProviderFactory.class.getName());
|
||||||
System.clearProperty(CorrelationContextManagerFactory.class.getName());
|
System.clearProperty(BaggageManagerFactory.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -80,10 +80,8 @@ class OpenTelemetryTest {
|
||||||
assertThat(OpenTelemetry.getTracerProvider()).isSameAs(OpenTelemetry.getTracerProvider());
|
assertThat(OpenTelemetry.getTracerProvider()).isSameAs(OpenTelemetry.getTracerProvider());
|
||||||
assertThat(OpenTelemetry.getMeterProvider()).isInstanceOf(DefaultMeterProvider.class);
|
assertThat(OpenTelemetry.getMeterProvider()).isInstanceOf(DefaultMeterProvider.class);
|
||||||
assertThat(OpenTelemetry.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider());
|
assertThat(OpenTelemetry.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider());
|
||||||
assertThat(OpenTelemetry.getCorrelationContextManager())
|
assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(DefaultBaggageManager.class);
|
||||||
.isInstanceOf(DefaultCorrelationContextManager.class);
|
assertThat(OpenTelemetry.getBaggageManager()).isSameAs(OpenTelemetry.getBaggageManager());
|
||||||
assertThat(OpenTelemetry.getCorrelationContextManager())
|
|
||||||
.isSameAs(OpenTelemetry.getCorrelationContextManager());
|
|
||||||
assertThat(OpenTelemetry.getPropagators()).isInstanceOf(DefaultContextPropagators.class);
|
assertThat(OpenTelemetry.getPropagators()).isInstanceOf(DefaultContextPropagators.class);
|
||||||
assertThat(OpenTelemetry.getPropagators()).isSameAs(OpenTelemetry.getPropagators());
|
assertThat(OpenTelemetry.getPropagators()).isSameAs(OpenTelemetry.getPropagators());
|
||||||
}
|
}
|
||||||
|
|
@ -169,48 +167,38 @@ class OpenTelemetryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCorrelationContextManagerLoadArbitrary() throws IOException {
|
void testBaggageManagerLoadArbitrary() throws IOException {
|
||||||
File serviceFile =
|
File serviceFile =
|
||||||
createService(
|
createService(
|
||||||
CorrelationContextManagerFactory.class,
|
BaggageManagerFactory.class, FirstBaggageManager.class, SecondBaggageManager.class);
|
||||||
FirstCorrelationContextManager.class,
|
|
||||||
SecondCorrelationContextManager.class);
|
|
||||||
try {
|
try {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
(OpenTelemetry.getCorrelationContextManager() instanceof FirstCorrelationContextManager)
|
(OpenTelemetry.getBaggageManager() instanceof FirstBaggageManager)
|
||||||
|| (OpenTelemetry.getCorrelationContextManager()
|
|| (OpenTelemetry.getBaggageManager() instanceof SecondBaggageManager));
|
||||||
instanceof SecondCorrelationContextManager));
|
assertThat(OpenTelemetry.getBaggageManager()).isEqualTo(OpenTelemetry.getBaggageManager());
|
||||||
assertThat(OpenTelemetry.getCorrelationContextManager())
|
|
||||||
.isEqualTo(OpenTelemetry.getCorrelationContextManager());
|
|
||||||
} finally {
|
} finally {
|
||||||
serviceFile.delete();
|
serviceFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCorrelationContextManagerSystemProperty() throws IOException {
|
void testBaggageManagerSystemProperty() throws IOException {
|
||||||
File serviceFile =
|
File serviceFile =
|
||||||
createService(
|
createService(
|
||||||
CorrelationContextManagerFactory.class,
|
BaggageManagerFactory.class, FirstBaggageManager.class, SecondBaggageManager.class);
|
||||||
FirstCorrelationContextManager.class,
|
System.setProperty(BaggageManagerFactory.class.getName(), SecondBaggageManager.class.getName());
|
||||||
SecondCorrelationContextManager.class);
|
|
||||||
System.setProperty(
|
|
||||||
CorrelationContextManagerFactory.class.getName(),
|
|
||||||
SecondCorrelationContextManager.class.getName());
|
|
||||||
try {
|
try {
|
||||||
assertThat(OpenTelemetry.getCorrelationContextManager())
|
assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(SecondBaggageManager.class);
|
||||||
.isInstanceOf(SecondCorrelationContextManager.class);
|
assertThat(OpenTelemetry.getBaggageManager()).isEqualTo(OpenTelemetry.getBaggageManager());
|
||||||
assertThat(OpenTelemetry.getCorrelationContextManager())
|
|
||||||
.isEqualTo(OpenTelemetry.getCorrelationContextManager());
|
|
||||||
} finally {
|
} finally {
|
||||||
serviceFile.delete();
|
serviceFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCorrelationContextManagerNotFound() {
|
void testBaggageManagerNotFound() {
|
||||||
System.setProperty(CorrelationContextManagerFactory.class.getName(), "io.does.not.exists");
|
System.setProperty(BaggageManagerFactory.class.getName(), "io.does.not.exists");
|
||||||
assertThrows(IllegalStateException.class, () -> OpenTelemetry.getCorrelationContextManager());
|
assertThrows(IllegalStateException.class, () -> OpenTelemetry.getBaggageManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -406,35 +394,34 @@ class OpenTelemetryTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SecondCorrelationContextManager extends FirstCorrelationContextManager {
|
public static class SecondBaggageManager extends FirstBaggageManager {
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContextManager create() {
|
public BaggageManager create() {
|
||||||
return new SecondCorrelationContextManager();
|
return new SecondBaggageManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FirstCorrelationContextManager
|
public static class FirstBaggageManager implements BaggageManager, BaggageManagerFactory {
|
||||||
implements CorrelationContextManager, CorrelationContextManagerFactory {
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContextManager create() {
|
public BaggageManager create() {
|
||||||
return new FirstCorrelationContextManager();
|
return new FirstBaggageManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContext getCurrentContext() {
|
public Baggage getCurrentBaggage() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContext.Builder contextBuilder() {
|
public Baggage.Builder baggageBuilder() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Scope withContext(CorrelationContext distContext) {
|
public Scope withContext(Baggage distContext) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019, OpenTelemetry Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import io.grpc.Context;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class BaggageUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetCurrentBaggage_Default() {
|
||||||
|
Baggage baggage = BaggageUtils.getCurrentBaggage();
|
||||||
|
assertThat(baggage).isSameAs(EmptyBaggage.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetCurrentBaggage_SetCorrContext() {
|
||||||
|
Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build();
|
||||||
|
Context orig = BaggageUtils.withBaggage(baggage, Context.current()).attach();
|
||||||
|
try {
|
||||||
|
assertThat(BaggageUtils.getCurrentBaggage()).isSameAs(baggage);
|
||||||
|
} finally {
|
||||||
|
Context.current().detach(orig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetBaggage_DefaultContext() {
|
||||||
|
Baggage baggage = BaggageUtils.getBaggage(Context.current());
|
||||||
|
assertThat(baggage).isSameAs(EmptyBaggage.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetBaggage_ExplicitContext() {
|
||||||
|
Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build();
|
||||||
|
Context context = BaggageUtils.withBaggage(baggage, Context.current());
|
||||||
|
assertThat(BaggageUtils.getBaggage(context)).isSameAs(baggage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetBaggageWithoutDefault_DefaultContext() {
|
||||||
|
Baggage baggage = BaggageUtils.getBaggageWithoutDefault(Context.current());
|
||||||
|
assertThat(baggage).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetBaggageWithoutDefault_ExplicitContext() {
|
||||||
|
Baggage baggage = DefaultBaggageManager.getInstance().baggageBuilder().build();
|
||||||
|
Context context = BaggageUtils.withBaggage(baggage, Context.current());
|
||||||
|
assertThat(BaggageUtils.getBaggage(context)).isSameAs(baggage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
@ -25,14 +25,13 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class DefaultCorrelationContextManagerTest {
|
class DefaultBaggageManagerTest {
|
||||||
private static final CorrelationContextManager defaultCorrelationContextManager =
|
private static final BaggageManager DEFAULT_BAGGAGE_MANAGER = DefaultBaggageManager.getInstance();
|
||||||
DefaultCorrelationContextManager.getInstance();
|
|
||||||
private static final String KEY = "key";
|
private static final String KEY = "key";
|
||||||
private static final String VALUE = "value";
|
private static final String VALUE = "value";
|
||||||
|
|
||||||
private static final CorrelationContext DIST_CONTEXT =
|
private static final Baggage DIST_CONTEXT =
|
||||||
new CorrelationContext() {
|
new Baggage() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Entry> getEntries() {
|
public Collection<Entry> getEntries() {
|
||||||
|
|
@ -48,21 +47,19 @@ class DefaultCorrelationContextManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void builderMethod() {
|
void builderMethod() {
|
||||||
assertThat(defaultCorrelationContextManager.contextBuilder().build().getEntries()).isEmpty();
|
assertThat(DEFAULT_BAGGAGE_MANAGER.baggageBuilder().build().getEntries()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getCurrentContext_DefaultContext() {
|
void getCurrentContext_DefaultContext() {
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
.isSameAs(EmptyCorrelationContext.getInstance());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getCurrentContext_ContextSetToNull() {
|
void getCurrentContext_ContextSetToNull() {
|
||||||
Context orig =
|
Context orig = BaggageUtils.withBaggage(null, Context.current()).attach();
|
||||||
CorrelationsContextUtils.withCorrelationContext(null, Context.current()).attach();
|
|
||||||
try {
|
try {
|
||||||
CorrelationContext distContext = defaultCorrelationContextManager.getCurrentContext();
|
Baggage distContext = DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage();
|
||||||
assertThat(distContext).isNotNull();
|
assertThat(distContext).isNotNull();
|
||||||
assertThat(distContext.getEntries()).isEmpty();
|
assertThat(distContext.getEntries()).isEmpty();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -72,69 +69,61 @@ class DefaultCorrelationContextManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withContext() {
|
void withContext() {
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
.isSameAs(EmptyCorrelationContext.getInstance());
|
try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withContext(DIST_CONTEXT)) {
|
||||||
try (Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT)) {
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT);
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext()).isSameAs(DIST_CONTEXT);
|
|
||||||
}
|
}
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
.isSameAs(EmptyCorrelationContext.getInstance());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withContext_nullContext() {
|
void withContext_nullContext() {
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
.isSameAs(EmptyCorrelationContext.getInstance());
|
try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withContext(null)) {
|
||||||
try (Scope wtm = defaultCorrelationContextManager.withContext(null)) {
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
|
||||||
.isSameAs(EmptyCorrelationContext.getInstance());
|
|
||||||
}
|
}
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
.isSameAs(EmptyCorrelationContext.getInstance());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withContextUsingWrap() {
|
void withContextUsingWrap() {
|
||||||
Runnable runnable;
|
Runnable runnable;
|
||||||
try (Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT)) {
|
try (Scope wtm = DEFAULT_BAGGAGE_MANAGER.withContext(DIST_CONTEXT)) {
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext()).isSameAs(DIST_CONTEXT);
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT);
|
||||||
runnable =
|
runnable =
|
||||||
Context.current()
|
Context.current()
|
||||||
.wrap(
|
.wrap(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(DIST_CONTEXT);
|
||||||
.isSameAs(DIST_CONTEXT);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
assertThat(DEFAULT_BAGGAGE_MANAGER.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
.isSameAs(EmptyCorrelationContext.getInstance());
|
// When we run the runnable we will have the Baggage in the current Context.
|
||||||
// When we run the runnable we will have the CorrelationContext in the current Context.
|
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noopContextBuilder_SetParent_DisallowsNullParent() {
|
void noopContextBuilder_SetParent_DisallowsNullParent() {
|
||||||
CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder();
|
Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder();
|
||||||
assertThrows(
|
assertThrows(NullPointerException.class, () -> noopBuilder.setParent((Baggage) null));
|
||||||
NullPointerException.class, () -> noopBuilder.setParent((CorrelationContext) null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noopContextBuilder_SetParent_DisallowsNullContext() {
|
void noopContextBuilder_SetParent_DisallowsNullContext() {
|
||||||
CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder();
|
Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder();
|
||||||
assertThrows(NullPointerException.class, () -> noopBuilder.setParent((Context) null));
|
assertThrows(NullPointerException.class, () -> noopBuilder.setParent((Context) null));
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noopContextBuilder_SetParent_fromContext() {
|
void noopContextBuilder_SetParent_fromContext() {
|
||||||
CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder();
|
Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder();
|
||||||
noopBuilder.setParent(Context.current()); // No error.
|
noopBuilder.setParent(Context.current()); // No error.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noopContextBuilder_Put_DisallowsNullKey() {
|
void noopContextBuilder_Put_DisallowsNullKey() {
|
||||||
CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder();
|
Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder();
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
() -> noopBuilder.put(null, VALUE, Entry.METADATA_UNLIMITED_PROPAGATION));
|
() -> noopBuilder.put(null, VALUE, Entry.METADATA_UNLIMITED_PROPAGATION));
|
||||||
|
|
@ -142,7 +131,7 @@ class DefaultCorrelationContextManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noopContextBuilder_Put_DisallowsNullValue() {
|
void noopContextBuilder_Put_DisallowsNullValue() {
|
||||||
CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder();
|
Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder();
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
() -> noopBuilder.put(KEY, null, Entry.METADATA_UNLIMITED_PROPAGATION));
|
() -> noopBuilder.put(KEY, null, Entry.METADATA_UNLIMITED_PROPAGATION));
|
||||||
|
|
@ -150,13 +139,13 @@ class DefaultCorrelationContextManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noopContextBuilder_Put_DisallowsNullEntryMetadata() {
|
void noopContextBuilder_Put_DisallowsNullEntryMetadata() {
|
||||||
CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder();
|
Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder();
|
||||||
assertThrows(NullPointerException.class, () -> noopBuilder.put(KEY, VALUE, null));
|
assertThrows(NullPointerException.class, () -> noopBuilder.put(KEY, VALUE, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noopContextBuilder_Remove_DisallowsNullKey() {
|
void noopContextBuilder_Remove_DisallowsNullKey() {
|
||||||
CorrelationContext.Builder noopBuilder = defaultCorrelationContextManager.contextBuilder();
|
Baggage.Builder noopBuilder = DEFAULT_BAGGAGE_MANAGER.baggageBuilder();
|
||||||
assertThrows(NullPointerException.class, () -> noopBuilder.remove(null));
|
assertThrows(NullPointerException.class, () -> noopBuilder.remove(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,12 +14,12 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.google.common.testing.EqualsTester;
|
import com.google.common.testing.EqualsTester;
|
||||||
import io.opentelemetry.correlationcontext.EntryMetadata.EntryTtl;
|
import io.opentelemetry.baggage.EntryMetadata.EntryTtl;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class EntryMetadataTest {
|
class EntryMetadataTest {
|
||||||
|
|
@ -14,13 +14,13 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.baggage;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import com.google.common.testing.EqualsTester;
|
import com.google.common.testing.EqualsTester;
|
||||||
import io.opentelemetry.correlationcontext.EntryMetadata.EntryTtl;
|
import io.opentelemetry.baggage.EntryMetadata.EntryTtl;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.correlationcontext;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
import io.grpc.Context;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class CorrelationsContextUtilsTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetCurrentCorrelationContext_Default() {
|
|
||||||
CorrelationContext corrContext = CorrelationsContextUtils.getCurrentCorrelationContext();
|
|
||||||
assertThat(corrContext).isSameAs(EmptyCorrelationContext.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetCurrentCorrelationContext_SetCorrContext() {
|
|
||||||
CorrelationContext corrContext =
|
|
||||||
DefaultCorrelationContextManager.getInstance().contextBuilder().build();
|
|
||||||
Context orig =
|
|
||||||
CorrelationsContextUtils.withCorrelationContext(corrContext, Context.current()).attach();
|
|
||||||
try {
|
|
||||||
assertThat(CorrelationsContextUtils.getCurrentCorrelationContext()).isSameAs(corrContext);
|
|
||||||
} finally {
|
|
||||||
Context.current().detach(orig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetCorrelationContext_DefaultContext() {
|
|
||||||
CorrelationContext corrContext =
|
|
||||||
CorrelationsContextUtils.getCorrelationContext(Context.current());
|
|
||||||
assertThat(corrContext).isSameAs(EmptyCorrelationContext.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetCorrelationContext_ExplicitContext() {
|
|
||||||
CorrelationContext corrContext =
|
|
||||||
DefaultCorrelationContextManager.getInstance().contextBuilder().build();
|
|
||||||
Context context =
|
|
||||||
CorrelationsContextUtils.withCorrelationContext(corrContext, Context.current());
|
|
||||||
assertThat(CorrelationsContextUtils.getCorrelationContext(context)).isSameAs(corrContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetCorrelationContextWithoutDefault_DefaultContext() {
|
|
||||||
CorrelationContext corrContext =
|
|
||||||
CorrelationsContextUtils.getCorrelationContextWithoutDefault(Context.current());
|
|
||||||
assertThat(corrContext).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testGetCorrelationContextWithoutDefault_ExplicitContext() {
|
|
||||||
CorrelationContext corrContext =
|
|
||||||
DefaultCorrelationContextManager.getInstance().contextBuilder().build();
|
|
||||||
Context context =
|
|
||||||
CorrelationsContextUtils.withCorrelationContext(corrContext, Context.current());
|
|
||||||
assertThat(CorrelationsContextUtils.getCorrelationContext(context)).isSameAs(corrContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -66,7 +66,7 @@ public final class DefaultContextPropagators implements ContextPropagators {
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
* ContextPropagators propagators = DefaultContextPropagators.builder()
|
* ContextPropagators propagators = DefaultContextPropagators.builder()
|
||||||
* .addTextMapPropagator(new HttpTraceContext())
|
* .addTextMapPropagator(new HttpTraceContext())
|
||||||
* .addTextMapPropagator(new HttpCorrelationContext())
|
* .addTextMapPropagator(new HttpBaggage())
|
||||||
* .addTextMapPropagator(new MyCustomContextPropagator())
|
* .addTextMapPropagator(new MyCustomContextPropagator())
|
||||||
* .build();
|
* .build();
|
||||||
* }</pre>
|
* }</pre>
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
|
||||||
import io.opentelemetry.trace.Tracer;
|
import io.opentelemetry.trace.Tracer;
|
||||||
|
|
||||||
abstract class BaseShimObject {
|
abstract class BaseShimObject {
|
||||||
|
|
@ -35,7 +35,7 @@ abstract class BaseShimObject {
|
||||||
return telemetryInfo.tracer();
|
return telemetryInfo.tracer();
|
||||||
}
|
}
|
||||||
|
|
||||||
CorrelationContextManager contextManager() {
|
BaggageManager contextManager() {
|
||||||
return telemetryInfo.contextManager();
|
return telemetryInfo.contextManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
import io.grpc.Context;
|
import io.grpc.Context;
|
||||||
|
import io.opentelemetry.baggage.BaggageUtils;
|
||||||
import io.opentelemetry.context.propagation.TextMapPropagator;
|
import io.opentelemetry.context.propagation.TextMapPropagator;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationsContextUtils;
|
|
||||||
import io.opentelemetry.trace.DefaultSpan;
|
import io.opentelemetry.trace.DefaultSpan;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
import io.opentelemetry.trace.TracingContextUtils;
|
import io.opentelemetry.trace.TracingContextUtils;
|
||||||
|
|
@ -37,9 +37,7 @@ final class Propagation extends BaseShimObject {
|
||||||
Context context =
|
Context context =
|
||||||
TracingContextUtils.withSpan(
|
TracingContextUtils.withSpan(
|
||||||
DefaultSpan.create(contextShim.getSpanContext()), Context.current());
|
DefaultSpan.create(contextShim.getSpanContext()), Context.current());
|
||||||
context =
|
context = BaggageUtils.withBaggage(contextShim.getBaggage(), context);
|
||||||
CorrelationsContextUtils.withCorrelationContext(
|
|
||||||
contextShim.getCorrelationContext(), context);
|
|
||||||
|
|
||||||
propagators().getTextMapPropagator().inject(context, carrier, TextMapSetter.INSTANCE);
|
propagators().getTextMapPropagator().inject(context, carrier, TextMapSetter.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
@ -61,8 +59,7 @@ final class Propagation extends BaseShimObject {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SpanContextShim(
|
return new SpanContextShim(telemetryInfo, span.getContext(), BaggageUtils.getBaggage(context));
|
||||||
telemetryInfo, span.getContext(), CorrelationsContextUtils.getCorrelationContext(context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class TextMapSetter implements TextMapPropagator.Setter<TextMapInject> {
|
static final class TextMapSetter implements TextMapPropagator.Setter<TextMapInject> {
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ import static io.opentelemetry.common.AttributesKeys.longKey;
|
||||||
import static io.opentelemetry.common.AttributesKeys.stringKey;
|
import static io.opentelemetry.common.AttributesKeys.stringKey;
|
||||||
|
|
||||||
import io.grpc.Context;
|
import io.grpc.Context;
|
||||||
|
import io.opentelemetry.baggage.Baggage;
|
||||||
import io.opentelemetry.common.AttributeKey;
|
import io.opentelemetry.common.AttributeKey;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
|
||||||
import io.opentelemetry.trace.DefaultSpan;
|
import io.opentelemetry.trace.DefaultSpan;
|
||||||
import io.opentelemetry.trace.Span.Kind;
|
import io.opentelemetry.trace.Span.Kind;
|
||||||
import io.opentelemetry.trace.Status;
|
import io.opentelemetry.trace.Status;
|
||||||
|
|
@ -189,7 +189,7 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder {
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
@Override
|
@Override
|
||||||
public Span start() {
|
public Span start() {
|
||||||
CorrelationContext distContext = null;
|
Baggage distContext = null;
|
||||||
io.opentelemetry.trace.Span.Builder builder = tracer().spanBuilder(spanName);
|
io.opentelemetry.trace.Span.Builder builder = tracer().spanBuilder(spanName);
|
||||||
|
|
||||||
if (ignoreActiveSpan && parentSpan == null && parentSpanContext == null) {
|
if (ignoreActiveSpan && parentSpan == null && parentSpanContext == null) {
|
||||||
|
|
@ -197,12 +197,12 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder {
|
||||||
} else if (parentSpan != null) {
|
} else if (parentSpan != null) {
|
||||||
builder.setParent(TracingContextUtils.withSpan(parentSpan.getSpan(), Context.ROOT));
|
builder.setParent(TracingContextUtils.withSpan(parentSpan.getSpan(), Context.ROOT));
|
||||||
SpanContextShim contextShim = spanContextTable().get(parentSpan);
|
SpanContextShim contextShim = spanContextTable().get(parentSpan);
|
||||||
distContext = contextShim == null ? null : contextShim.getCorrelationContext();
|
distContext = contextShim == null ? null : contextShim.getBaggage();
|
||||||
} else if (parentSpanContext != null) {
|
} else if (parentSpanContext != null) {
|
||||||
builder.setParent(
|
builder.setParent(
|
||||||
TracingContextUtils.withSpan(
|
TracingContextUtils.withSpan(
|
||||||
DefaultSpan.create(parentSpanContext.getSpanContext()), Context.ROOT));
|
DefaultSpan.create(parentSpanContext.getSpanContext()), Context.ROOT));
|
||||||
distContext = parentSpanContext.getCorrelationContext();
|
distContext = parentSpanContext.getBaggage();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (io.opentelemetry.trace.SpanContext link : parentLinks) {
|
for (io.opentelemetry.trace.SpanContext link : parentLinks) {
|
||||||
|
|
@ -226,7 +226,7 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder {
|
||||||
|
|
||||||
SpanShim spanShim = new SpanShim(telemetryInfo(), span);
|
SpanShim spanShim = new SpanShim(telemetryInfo(), span);
|
||||||
|
|
||||||
if (distContext != null && distContext != telemetryInfo().emptyCorrelationContext()) {
|
if (distContext != null && distContext != telemetryInfo().emptyBaggage()) {
|
||||||
spanContextTable().create(spanShim, distContext);
|
spanContextTable().create(spanShim, distContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
import io.opentelemetry.baggage.Baggage;
|
||||||
import io.opentelemetry.correlationcontext.Entry;
|
import io.opentelemetry.baggage.Entry;
|
||||||
import io.opentelemetry.correlationcontext.EntryMetadata;
|
import io.opentelemetry.baggage.EntryMetadata;
|
||||||
import io.opentracing.SpanContext;
|
import io.opentracing.SpanContext;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -28,30 +28,30 @@ final class SpanContextShim extends BaseShimObject implements SpanContext {
|
||||||
EntryMetadata.create(EntryMetadata.EntryTtl.UNLIMITED_PROPAGATION);
|
EntryMetadata.create(EntryMetadata.EntryTtl.UNLIMITED_PROPAGATION);
|
||||||
|
|
||||||
private final io.opentelemetry.trace.SpanContext context;
|
private final io.opentelemetry.trace.SpanContext context;
|
||||||
private final CorrelationContext distContext;
|
private final Baggage distContext;
|
||||||
|
|
||||||
public SpanContextShim(SpanShim spanShim) {
|
public SpanContextShim(SpanShim spanShim) {
|
||||||
this(
|
this(
|
||||||
spanShim.telemetryInfo(),
|
spanShim.telemetryInfo(),
|
||||||
spanShim.getSpan().getContext(),
|
spanShim.getSpan().getContext(),
|
||||||
spanShim.telemetryInfo().emptyCorrelationContext());
|
spanShim.telemetryInfo().emptyBaggage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpanContextShim(TelemetryInfo telemetryInfo, io.opentelemetry.trace.SpanContext context) {
|
public SpanContextShim(TelemetryInfo telemetryInfo, io.opentelemetry.trace.SpanContext context) {
|
||||||
this(telemetryInfo, context, telemetryInfo.emptyCorrelationContext());
|
this(telemetryInfo, context, telemetryInfo.emptyBaggage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpanContextShim(
|
public SpanContextShim(
|
||||||
TelemetryInfo telemetryInfo,
|
TelemetryInfo telemetryInfo,
|
||||||
io.opentelemetry.trace.SpanContext context,
|
io.opentelemetry.trace.SpanContext context,
|
||||||
CorrelationContext distContext) {
|
Baggage distContext) {
|
||||||
super(telemetryInfo);
|
super(telemetryInfo);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.distContext = distContext;
|
this.distContext = distContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpanContextShim newWithKeyValue(String key, String value) {
|
SpanContextShim newWithKeyValue(String key, String value) {
|
||||||
CorrelationContext.Builder builder = contextManager().contextBuilder().setParent(distContext);
|
Baggage.Builder builder = contextManager().baggageBuilder().setParent(distContext);
|
||||||
builder.put(key, value, DEFAULT_ENTRY_METADATA);
|
builder.put(key, value, DEFAULT_ENTRY_METADATA);
|
||||||
|
|
||||||
return new SpanContextShim(telemetryInfo(), context, builder.build());
|
return new SpanContextShim(telemetryInfo(), context, builder.build());
|
||||||
|
|
@ -61,7 +61,7 @@ final class SpanContextShim extends BaseShimObject implements SpanContext {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
CorrelationContext getCorrelationContext() {
|
Baggage getBaggage() {
|
||||||
return distContext;
|
return distContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
import io.opentelemetry.baggage.Baggage;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
@ -27,7 +27,7 @@ import javax.annotation.Nullable;
|
||||||
/*
|
/*
|
||||||
* SpanContextShimTable stores and manages OpenTracing SpanContext instances,
|
* SpanContextShimTable stores and manages OpenTracing SpanContext instances,
|
||||||
* which are expected to a unmodfiable union of SpanContext and Baggage
|
* which are expected to a unmodfiable union of SpanContext and Baggage
|
||||||
* (CorrelationContext/TagMap under OpenTelemetry).
|
* (Baggage/TagMap under OpenTelemetry).
|
||||||
*
|
*
|
||||||
* This requires that changes on a given Span and its (new) SpanContext
|
* This requires that changes on a given Span and its (new) SpanContext
|
||||||
* are visible in all threads at *any* moment. The current approach uses
|
* are visible in all threads at *any* moment. The current approach uses
|
||||||
|
|
@ -85,10 +85,10 @@ final class SpanContextShimTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpanContextShim create(SpanShim spanShim) {
|
public SpanContextShim create(SpanShim spanShim) {
|
||||||
return create(spanShim, spanShim.telemetryInfo().emptyCorrelationContext());
|
return create(spanShim, spanShim.telemetryInfo().emptyBaggage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpanContextShim create(SpanShim spanShim, CorrelationContext distContext) {
|
public SpanContextShim create(SpanShim spanShim, Baggage distContext) {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
SpanContextShim contextShim = shimsMap.get(spanShim.getSpan());
|
SpanContextShim contextShim = shimsMap.get(spanShim.getSpan());
|
||||||
|
|
|
||||||
|
|
@ -16,28 +16,27 @@
|
||||||
|
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
|
import io.opentelemetry.baggage.Baggage;
|
||||||
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
import io.opentelemetry.context.propagation.ContextPropagators;
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
|
||||||
import io.opentelemetry.trace.Tracer;
|
import io.opentelemetry.trace.Tracer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class that holds a Tracer, a CorrelationContextManager, and related objects that are core
|
* Utility class that holds a Tracer, a BaggageManager, and related objects that are core part of
|
||||||
* part of the OT Shim layer.
|
* the OT Shim layer.
|
||||||
*/
|
*/
|
||||||
final class TelemetryInfo {
|
final class TelemetryInfo {
|
||||||
private final Tracer tracer;
|
private final Tracer tracer;
|
||||||
private final CorrelationContextManager contextManager;
|
private final BaggageManager contextManager;
|
||||||
private final CorrelationContext emptyCorrelationContext;
|
private final Baggage emptyBaggage;
|
||||||
private final ContextPropagators propagators;
|
private final ContextPropagators propagators;
|
||||||
private final SpanContextShimTable spanContextTable;
|
private final SpanContextShimTable spanContextTable;
|
||||||
|
|
||||||
TelemetryInfo(
|
TelemetryInfo(Tracer tracer, BaggageManager contextManager, ContextPropagators propagators) {
|
||||||
Tracer tracer, CorrelationContextManager contextManager, ContextPropagators propagators) {
|
|
||||||
this.tracer = tracer;
|
this.tracer = tracer;
|
||||||
this.contextManager = contextManager;
|
this.contextManager = contextManager;
|
||||||
this.propagators = propagators;
|
this.propagators = propagators;
|
||||||
this.emptyCorrelationContext = contextManager.contextBuilder().build();
|
this.emptyBaggage = contextManager.baggageBuilder().build();
|
||||||
this.spanContextTable = new SpanContextShimTable();
|
this.spanContextTable = new SpanContextShimTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,7 +44,7 @@ final class TelemetryInfo {
|
||||||
return tracer;
|
return tracer;
|
||||||
}
|
}
|
||||||
|
|
||||||
CorrelationContextManager contextManager() {
|
BaggageManager contextManager() {
|
||||||
return contextManager;
|
return contextManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,8 +52,8 @@ final class TelemetryInfo {
|
||||||
return spanContextTable;
|
return spanContextTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
CorrelationContext emptyCorrelationContext() {
|
Baggage emptyBaggage() {
|
||||||
return emptyCorrelationContext;
|
return emptyBaggage;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextPropagators propagators() {
|
ContextPropagators propagators() {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
import io.opentelemetry.trace.Tracer;
|
import io.opentelemetry.trace.Tracer;
|
||||||
import io.opentelemetry.trace.TracerProvider;
|
import io.opentelemetry.trace.TracerProvider;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -27,7 +27,7 @@ public final class TraceShim {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code io.opentracing.Tracer} shim out of {@code OpenTelemetry.getTracer()} and
|
* Creates a {@code io.opentracing.Tracer} shim out of {@code OpenTelemetry.getTracer()} and
|
||||||
* {@code OpenTelemetry.getCorrelationContextManager()}.
|
* {@code OpenTelemetry.getBaggageManager()}.
|
||||||
*
|
*
|
||||||
* @return a {@code io.opentracing.Tracer}.
|
* @return a {@code io.opentracing.Tracer}.
|
||||||
* @since 0.1.0
|
* @since 0.1.0
|
||||||
|
|
@ -36,21 +36,21 @@ public final class TraceShim {
|
||||||
return new TracerShim(
|
return new TracerShim(
|
||||||
new TelemetryInfo(
|
new TelemetryInfo(
|
||||||
getTracer(OpenTelemetry.getTracerProvider()),
|
getTracer(OpenTelemetry.getTracerProvider()),
|
||||||
OpenTelemetry.getCorrelationContextManager(),
|
OpenTelemetry.getBaggageManager(),
|
||||||
OpenTelemetry.getPropagators()));
|
OpenTelemetry.getPropagators()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code io.opentracing.Tracer} shim out the specified {@code Tracer} and {@code
|
* Creates a {@code io.opentracing.Tracer} shim out the specified {@code Tracer} and {@code
|
||||||
* CorrelationContextManager}.
|
* BaggageManager}.
|
||||||
*
|
*
|
||||||
* @param tracerProvider the {@code TracerProvider} used by this shim.
|
* @param tracerProvider the {@code TracerProvider} used by this shim.
|
||||||
* @param contextManager the {@code CorrelationContextManager} used by this shim.
|
* @param contextManager the {@code BaggageManager} used by this shim.
|
||||||
* @return a {@code io.opentracing.Tracer}.
|
* @return a {@code io.opentracing.Tracer}.
|
||||||
* @since 0.1.0
|
* @since 0.1.0
|
||||||
*/
|
*/
|
||||||
public static io.opentracing.Tracer createTracerShim(
|
public static io.opentracing.Tracer createTracerShim(
|
||||||
TracerProvider tracerProvider, CorrelationContextManager contextManager) {
|
TracerProvider tracerProvider, BaggageManager contextManager) {
|
||||||
return new TracerShim(
|
return new TracerShim(
|
||||||
new TelemetryInfo(
|
new TelemetryInfo(
|
||||||
getTracer(Objects.requireNonNull(tracerProvider, "tracerProvider")),
|
getTracer(Objects.requireNonNull(tracerProvider, "tracerProvider")),
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.trace.Tracer;
|
import io.opentelemetry.trace.Tracer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -30,7 +30,7 @@ class SpanBuilderShimTest {
|
||||||
private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build();
|
||||||
private final Tracer tracer = tracerSdkFactory.get("SpanShimTest");
|
private final Tracer tracer = tracerSdkFactory.get("SpanShimTest");
|
||||||
private final TelemetryInfo telemetryInfo =
|
private final TelemetryInfo telemetryInfo =
|
||||||
new TelemetryInfo(tracer, new CorrelationContextManagerSdk(), OpenTelemetry.getPropagators());
|
new TelemetryInfo(tracer, new BaggageManagerSdk(), OpenTelemetry.getPropagators());
|
||||||
|
|
||||||
private static final String SPAN_NAME = "Span";
|
private static final String SPAN_NAME = "Span";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
import io.opentelemetry.trace.Tracer;
|
import io.opentelemetry.trace.Tracer;
|
||||||
|
|
@ -37,7 +37,7 @@ class SpanShimTest {
|
||||||
private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider tracerSdkFactory = TracerSdkProvider.builder().build();
|
||||||
private final Tracer tracer = tracerSdkFactory.get("SpanShimTest");
|
private final Tracer tracer = tracerSdkFactory.get("SpanShimTest");
|
||||||
private final TelemetryInfo telemetryInfo =
|
private final TelemetryInfo telemetryInfo =
|
||||||
new TelemetryInfo(tracer, new CorrelationContextManagerSdk(), OpenTelemetry.getPropagators());
|
new TelemetryInfo(tracer, new BaggageManagerSdk(), OpenTelemetry.getPropagators());
|
||||||
private Span span;
|
private Span span;
|
||||||
|
|
||||||
private static final String SPAN_NAME = "Span";
|
private static final String SPAN_NAME = "Span";
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
import static io.opentelemetry.OpenTelemetry.getCorrelationContextManager;
|
import static io.opentelemetry.OpenTelemetry.getBaggageManager;
|
||||||
import static io.opentelemetry.OpenTelemetry.getTracerProvider;
|
import static io.opentelemetry.OpenTelemetry.getTracerProvider;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -32,14 +32,14 @@ class TraceShimTest {
|
||||||
void createTracerShim_default() {
|
void createTracerShim_default() {
|
||||||
TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim();
|
TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim();
|
||||||
assertEquals(OpenTelemetry.getTracer("opentracingshim"), tracerShim.tracer());
|
assertEquals(OpenTelemetry.getTracer("opentracingshim"), tracerShim.tracer());
|
||||||
assertEquals(OpenTelemetry.getCorrelationContextManager(), tracerShim.contextManager());
|
assertEquals(OpenTelemetry.getBaggageManager(), tracerShim.contextManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createTracerShim_nullTracer() {
|
void createTracerShim_nullTracer() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
() -> TraceShim.createTracerShim(null, getCorrelationContextManager()),
|
() -> TraceShim.createTracerShim(null, getBaggageManager()),
|
||||||
"tracerProvider");
|
"tracerProvider");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ class TraceShimTest {
|
||||||
@Test
|
@Test
|
||||||
void createTracerShim() {
|
void createTracerShim() {
|
||||||
TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
CorrelationContextManagerSdk contextManager = new CorrelationContextManagerSdk();
|
BaggageManagerSdk contextManager = new BaggageManagerSdk();
|
||||||
TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim(sdk, contextManager);
|
TracerShim tracerShim = (TracerShim) TraceShim.createTracerShim(sdk, contextManager);
|
||||||
assertEquals(sdk.get("opentracingshim"), tracerShim.tracer());
|
assertEquals(sdk.get("opentracingshim"), tracerShim.tracer());
|
||||||
assertEquals(contextManager, tracerShim.contextManager());
|
assertEquals(contextManager, tracerShim.contextManager());
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class TracerShimTest {
|
||||||
new TracerShim(
|
new TracerShim(
|
||||||
new TelemetryInfo(
|
new TelemetryInfo(
|
||||||
OpenTelemetry.getTracer("opentracingshim"),
|
OpenTelemetry.getTracer("opentracingshim"),
|
||||||
OpenTelemetry.getCorrelationContextManager(),
|
OpenTelemetry.getBaggageManager(),
|
||||||
OpenTelemetry.getPropagators()));
|
OpenTelemetry.getPropagators()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ package io.opentelemetry.opentracingshim.testbed;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import io.opentelemetry.correlationcontext.DefaultCorrelationContextManager;
|
import io.opentelemetry.baggage.DefaultBaggageManager;
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
|
|
@ -38,7 +38,7 @@ class OpenTelemetryInteroperabilityTest {
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer otTracer =
|
private final Tracer otTracer =
|
||||||
TraceShim.createTracerShim(sdk, DefaultCorrelationContextManager.getInstance());
|
TraceShim.createTracerShim(sdk, DefaultBaggageManager.getInstance());
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void before() {
|
void before() {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.trace.SpanId;
|
import io.opentelemetry.trace.SpanId;
|
||||||
|
|
@ -46,7 +46,7 @@ class ActiveSpanReplacementTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.trace.Span.Kind;
|
import io.opentelemetry.trace.Span.Kind;
|
||||||
|
|
@ -51,7 +51,7 @@ class ActorPropagationTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private Phaser phaser;
|
private Phaser phaser;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
import io.opentracing.Tracer;
|
import io.opentracing.Tracer;
|
||||||
|
|
@ -34,7 +34,7 @@ public final class BaggageHandlingTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.trace.Span.Kind;
|
import io.opentelemetry.trace.Span.Kind;
|
||||||
|
|
@ -42,7 +42,7 @@ class TestClientServerTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final ArrayBlockingQueue<Message> queue = new ArrayBlockingQueue<>(10);
|
private final ArrayBlockingQueue<Message> queue = new ArrayBlockingQueue<>(10);
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.trace.Span.Kind;
|
import io.opentelemetry.trace.Span.Kind;
|
||||||
|
|
@ -50,7 +50,7 @@ class HandlerTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final Client client = new Client(new RequestHandler(tracer));
|
private final Client client = new Client(new RequestHandler(tracer));
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
||||||
|
|
@ -48,7 +48,7 @@ public final class ErrorReportingTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
/* Very simple error handling **/
|
/* Very simple error handling **/
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentracing.Scope;
|
import io.opentracing.Scope;
|
||||||
|
|
@ -41,7 +41,7 @@ public final class LateSpanFinishTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
|
|
@ -34,7 +34,7 @@ class ListenerTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentracing.Scope;
|
import io.opentracing.Scope;
|
||||||
|
|
@ -46,7 +46,7 @@ class MultipleCallbacksTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test() {
|
void test() {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import io.opentelemetry.common.ReadableAttributes;
|
import io.opentelemetry.common.ReadableAttributes;
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentracing.Scope;
|
import io.opentracing.Scope;
|
||||||
|
|
@ -44,7 +44,7 @@ public final class NestedCallbacksTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import io.opentelemetry.common.AttributeKey;
|
import io.opentelemetry.common.AttributeKey;
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.trace.SpanId;
|
import io.opentelemetry.trace.SpanId;
|
||||||
|
|
@ -50,7 +50,7 @@ class PromisePropagationTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private Phaser phaser;
|
private Phaser phaser;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentracing.Tracer;
|
import io.opentracing.Tracer;
|
||||||
|
|
@ -39,7 +39,7 @@ public final class HandlerTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
private final Client client = new Client(new RequestHandler(tracer));
|
private final Client client = new Client(new RequestHandler(tracer));
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
import io.opentelemetry.exporters.inmemory.InMemoryTracing;
|
||||||
import io.opentelemetry.opentracingshim.TraceShim;
|
import io.opentelemetry.opentracingshim.TraceShim;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.trace.SpanId;
|
import io.opentelemetry.trace.SpanId;
|
||||||
|
|
@ -39,7 +39,7 @@ class SuspendResumePropagationTest {
|
||||||
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
private final TracerSdkProvider sdk = TracerSdkProvider.builder().build();
|
||||||
private final InMemoryTracing inMemoryTracing =
|
private final InMemoryTracing inMemoryTracing =
|
||||||
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
InMemoryTracing.builder().setTracerProvider(sdk).build();
|
||||||
private final Tracer tracer = TraceShim.createTracerShim(sdk, new CorrelationContextManagerSdk());
|
private final Tracer tracer = TraceShim.createTracerShim(sdk, new BaggageManagerSdk());
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void before() {}
|
void before() {}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ ext.propertiesDir = "build/generated/properties/io/opentelemetry/sdk"
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(':opentelemetry-api'),
|
api project(':opentelemetry-api'),
|
||||||
project(':opentelemetry-sdk-common'),
|
project(':opentelemetry-sdk-common'),
|
||||||
project(':opentelemetry-sdk-correlation-context'),
|
project(':opentelemetry-sdk-baggage'),
|
||||||
project(':opentelemetry-sdk-metrics'),
|
project(':opentelemetry-sdk-metrics'),
|
||||||
project(':opentelemetry-sdk-tracing')
|
project(':opentelemetry-sdk-tracing')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,14 @@ package io.opentelemetry.sdk;
|
||||||
|
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.internal.Obfuscated;
|
import io.opentelemetry.internal.Obfuscated;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import io.opentelemetry.sdk.metrics.MeterSdkProvider;
|
import io.opentelemetry.sdk.metrics.MeterSdkProvider;
|
||||||
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a static global accessor for SDK telemetry objects {@link TracerSdkProvider},
|
* This class provides a static global accessor for SDK telemetry objects {@link TracerSdkProvider},
|
||||||
* {@link MeterSdkProvider} and {@link CorrelationContextManagerSdk}.
|
* {@link MeterSdkProvider} and {@link BaggageManagerSdk}.
|
||||||
*
|
*
|
||||||
* <p>This is a convenience class getting and casting the telemetry objects from {@link
|
* <p>This is a convenience class getting and casting the telemetry objects from {@link
|
||||||
* OpenTelemetry}.
|
* OpenTelemetry}.
|
||||||
|
|
@ -53,12 +53,12 @@ public final class OpenTelemetrySdk {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link CorrelationContextManagerSdk}.
|
* Returns a {@link BaggageManagerSdk}.
|
||||||
*
|
*
|
||||||
* @return context manager returned by {@link OpenTelemetry#getCorrelationContextManager()}.
|
* @return context manager returned by {@link OpenTelemetry#getBaggageManager()}.
|
||||||
*/
|
*/
|
||||||
public static CorrelationContextManagerSdk getCorrelationContextManager() {
|
public static BaggageManagerSdk getBaggageManager() {
|
||||||
return (CorrelationContextManagerSdk) OpenTelemetry.getCorrelationContextManager();
|
return (BaggageManagerSdk) OpenTelemetry.getBaggageManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private OpenTelemetrySdk() {}
|
private OpenTelemetrySdk() {}
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ class OpenTelemetrySdkTest {
|
||||||
void testDefault() {
|
void testDefault() {
|
||||||
assertThat(OpenTelemetrySdk.getTracerProvider().get(""))
|
assertThat(OpenTelemetrySdk.getTracerProvider().get(""))
|
||||||
.isSameAs(OpenTelemetry.getTracerProvider().get(""));
|
.isSameAs(OpenTelemetry.getTracerProvider().get(""));
|
||||||
assertThat(OpenTelemetrySdk.getCorrelationContextManager())
|
assertThat(OpenTelemetrySdk.getBaggageManager()).isSameAs(OpenTelemetry.getBaggageManager());
|
||||||
.isSameAs(OpenTelemetry.getCorrelationContextManager());
|
|
||||||
assertThat(OpenTelemetrySdk.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider());
|
assertThat(OpenTelemetrySdk.getMeterProvider()).isSameAs(OpenTelemetry.getMeterProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ plugins {
|
||||||
id "ru.vyarus.animalsniffer"
|
id "ru.vyarus.animalsniffer"
|
||||||
}
|
}
|
||||||
|
|
||||||
description = 'OpenTelemetry SDK Correlation Context'
|
description = 'OpenTelemetry SDK Baggage'
|
||||||
ext.moduleName = "io.opentelemetry.sdk.correlationcontext"
|
ext.moduleName = "io.opentelemetry.sdk.baggage"
|
||||||
ext.propertiesDir = "build/generated/properties/io/opentelemetry/sdk/correlationcontext"
|
ext.propertiesDir = "build/generated/properties/io/opentelemetry/sdk/baggage"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(':opentelemetry-api'),
|
api project(':opentelemetry-api'),
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019, OpenTelemetry Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.sdk.baggage;
|
||||||
|
|
||||||
|
import io.opentelemetry.baggage.Baggage;
|
||||||
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
|
import io.opentelemetry.baggage.BaggageUtils;
|
||||||
|
import io.opentelemetry.context.Scope;
|
||||||
|
|
||||||
|
/** {@link BaggageManagerSdk} is SDK implementation of {@link BaggageManager}. */
|
||||||
|
public class BaggageManagerSdk implements BaggageManager {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage getCurrentBaggage() {
|
||||||
|
return BaggageUtils.getCurrentBaggage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Baggage.Builder baggageBuilder() {
|
||||||
|
return new BaggageSdk.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Scope withContext(Baggage distContext) {
|
||||||
|
return BaggageUtils.currentContextWith(distContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,14 +14,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext;
|
package io.opentelemetry.sdk.baggage;
|
||||||
|
|
||||||
import io.grpc.Context;
|
import io.grpc.Context;
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
import io.opentelemetry.baggage.Baggage;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationsContextUtils;
|
import io.opentelemetry.baggage.BaggageUtils;
|
||||||
import io.opentelemetry.correlationcontext.Entry;
|
import io.opentelemetry.baggage.Entry;
|
||||||
import io.opentelemetry.correlationcontext.EntryMetadata;
|
import io.opentelemetry.baggage.EntryMetadata;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -34,19 +34,19 @@ import javax.annotation.concurrent.Immutable;
|
||||||
@Immutable
|
@Immutable
|
||||||
// TODO: Migrate to AutoValue
|
// TODO: Migrate to AutoValue
|
||||||
// @AutoValue
|
// @AutoValue
|
||||||
class CorrelationContextSdk implements CorrelationContext {
|
class BaggageSdk implements Baggage {
|
||||||
|
|
||||||
// The types of the EntryKey and Entry must match for each entry.
|
// The types of the EntryKey and Entry must match for each entry.
|
||||||
private final Map<String, Entry> entries;
|
private final Map<String, Entry> entries;
|
||||||
@Nullable private final CorrelationContext parent;
|
@Nullable private final Baggage parent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link CorrelationContextSdk} with the given entries.
|
* Creates a new {@link BaggageSdk} with the given entries.
|
||||||
*
|
*
|
||||||
* @param entries the initial entries for this {@code CorrelationContextSdk}.
|
* @param entries the initial entries for this {@code BaggageSdk}.
|
||||||
* @param parent providing a default set of entries
|
* @param parent providing a default set of entries
|
||||||
*/
|
*/
|
||||||
private CorrelationContextSdk(Map<String, ? extends Entry> entries, CorrelationContext parent) {
|
private BaggageSdk(Map<String, ? extends Entry> entries, Baggage parent) {
|
||||||
this.entries =
|
this.entries =
|
||||||
Collections.unmodifiableMap(new HashMap<>(Objects.requireNonNull(entries, "entries")));
|
Collections.unmodifiableMap(new HashMap<>(Objects.requireNonNull(entries, "entries")));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
@ -88,11 +88,11 @@ class CorrelationContextSdk implements CorrelationContext {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (o == null || !(o instanceof CorrelationContextSdk)) {
|
if (o == null || !(o instanceof BaggageSdk)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CorrelationContextSdk distContextSdk = (CorrelationContextSdk) o;
|
BaggageSdk distContextSdk = (BaggageSdk) o;
|
||||||
|
|
||||||
if (!entries.equals(distContextSdk.entries)) {
|
if (!entries.equals(distContextSdk.entries)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -109,38 +109,38 @@ class CorrelationContextSdk implements CorrelationContext {
|
||||||
|
|
||||||
// TODO: Migrate to AutoValue.Builder
|
// TODO: Migrate to AutoValue.Builder
|
||||||
// @AutoValue.Builder
|
// @AutoValue.Builder
|
||||||
static class Builder implements CorrelationContext.Builder {
|
static class Builder implements Baggage.Builder {
|
||||||
@Nullable private CorrelationContext parent;
|
@Nullable private Baggage parent;
|
||||||
private boolean noImplicitParent;
|
private boolean noImplicitParent;
|
||||||
private final Map<String, Entry> entries;
|
private final Map<String, Entry> entries;
|
||||||
|
|
||||||
/** Create a new empty CorrelationContext builder. */
|
/** Create a new empty Baggage builder. */
|
||||||
Builder() {
|
Builder() {
|
||||||
this.entries = new HashMap<>();
|
this.entries = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContext.Builder setParent(CorrelationContext parent) {
|
public Baggage.Builder setParent(Baggage parent) {
|
||||||
this.parent = Objects.requireNonNull(parent, "parent");
|
this.parent = Objects.requireNonNull(parent, "parent");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContext.Builder setParent(Context context) {
|
public Baggage.Builder setParent(Context context) {
|
||||||
Objects.requireNonNull(context, "context");
|
Objects.requireNonNull(context, "context");
|
||||||
setParent(CorrelationsContextUtils.getCorrelationContext(context));
|
setParent(BaggageUtils.getBaggage(context));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContext.Builder setNoParent() {
|
public Baggage.Builder setNoParent() {
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
noImplicitParent = true;
|
noImplicitParent = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContext.Builder put(String key, String value, EntryMetadata entryMetadata) {
|
public Baggage.Builder put(String key, String value, EntryMetadata entryMetadata) {
|
||||||
entries.put(
|
entries.put(
|
||||||
Objects.requireNonNull(key, "key"),
|
Objects.requireNonNull(key, "key"),
|
||||||
Entry.create(
|
Entry.create(
|
||||||
|
|
@ -151,7 +151,7 @@ class CorrelationContextSdk implements CorrelationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContext.Builder remove(String key) {
|
public Baggage.Builder remove(String key) {
|
||||||
entries.remove(Objects.requireNonNull(key, "key"));
|
entries.remove(Objects.requireNonNull(key, "key"));
|
||||||
if (parent != null && parent.getEntryValue(key) != null) {
|
if (parent != null && parent.getEntryValue(key) != null) {
|
||||||
entries.put(key, null);
|
entries.put(key, null);
|
||||||
|
|
@ -160,11 +160,11 @@ class CorrelationContextSdk implements CorrelationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContextSdk build() {
|
public BaggageSdk build() {
|
||||||
if (parent == null && !noImplicitParent) {
|
if (parent == null && !noImplicitParent) {
|
||||||
parent = OpenTelemetry.getCorrelationContextManager().getCurrentContext();
|
parent = OpenTelemetry.getBaggageManager().getCurrentBaggage();
|
||||||
}
|
}
|
||||||
return new CorrelationContextSdk(entries, parent);
|
return new BaggageSdk(entries, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,23 +14,22 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext.spi;
|
package io.opentelemetry.sdk.baggage.spi;
|
||||||
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
import io.opentelemetry.correlationcontext.spi.CorrelationContextManagerFactory;
|
import io.opentelemetry.baggage.spi.BaggageManagerFactory;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code CorrelationContextManager} provider implementation for {@link
|
* {@code BaggageManager} provider implementation for {@link BaggageManagerFactory}.
|
||||||
* CorrelationContextManagerFactory}.
|
|
||||||
*
|
*
|
||||||
* <p>This class is not intended to be used in application code and it is used only by {@link
|
* <p>This class is not intended to be used in application code and it is used only by {@link
|
||||||
* io.opentelemetry.OpenTelemetry}.
|
* io.opentelemetry.OpenTelemetry}.
|
||||||
*/
|
*/
|
||||||
public final class CorrelationContextManagerFactorySdk implements CorrelationContextManagerFactory {
|
public final class BaggageManagerFactorySdk implements BaggageManagerFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CorrelationContextManager create() {
|
public BaggageManager create() {
|
||||||
return new CorrelationContextManagerSdk();
|
return new BaggageManagerSdk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
io.opentelemetry.sdk.baggage.spi.BaggageManagerFactorySdk
|
||||||
|
|
@ -14,27 +14,27 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext;
|
package io.opentelemetry.sdk.baggage;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import io.grpc.Context;
|
import io.grpc.Context;
|
||||||
|
import io.opentelemetry.baggage.Baggage;
|
||||||
|
import io.opentelemetry.baggage.BaggageUtils;
|
||||||
|
import io.opentelemetry.baggage.EmptyBaggage;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationsContextUtils;
|
|
||||||
import io.opentelemetry.correlationcontext.EmptyCorrelationContext;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
/** Unit tests for {@link CorrelationContextManagerSdk}. */
|
/** Unit tests for {@link BaggageManagerSdk}. */
|
||||||
// Need to suppress warnings for MustBeClosed because Android 14 does not support
|
// Need to suppress warnings for MustBeClosed because Android 14 does not support
|
||||||
// try-with-resources.
|
// try-with-resources.
|
||||||
@SuppressWarnings("MustBeClosedChecker")
|
@SuppressWarnings("MustBeClosedChecker")
|
||||||
class CorrelationContextManagerSdkTest {
|
class BaggageManagerSdkTest {
|
||||||
@Mock private CorrelationContext distContext;
|
@Mock private Baggage distContext;
|
||||||
private final CorrelationContextManagerSdk contextManager = new CorrelationContextManagerSdk();
|
private final BaggageManagerSdk contextManager = new BaggageManagerSdk();
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
|
|
@ -43,15 +43,14 @@ class CorrelationContextManagerSdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetCurrentContext_DefaultContext() {
|
void testGetCurrentContext_DefaultContext() {
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance());
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetCurrentContext_ContextSetToNull() {
|
void testGetCurrentContext_ContextSetToNull() {
|
||||||
Context orig =
|
Context orig = BaggageUtils.withBaggage(null, Context.current()).attach();
|
||||||
CorrelationsContextUtils.withCorrelationContext(null, Context.current()).attach();
|
|
||||||
try {
|
try {
|
||||||
CorrelationContext distContext = contextManager.getCurrentContext();
|
Baggage distContext = contextManager.getCurrentBaggage();
|
||||||
assertThat(distContext).isNotNull();
|
assertThat(distContext).isNotNull();
|
||||||
assertThat(distContext.getEntries()).isEmpty();
|
assertThat(distContext.getEntries()).isEmpty();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -60,28 +59,28 @@ class CorrelationContextManagerSdkTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWithCorrelationContext() {
|
void testWithBaggage() {
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance());
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
try (Scope wtm = contextManager.withContext(distContext)) {
|
try (Scope wtm = contextManager.withContext(distContext)) {
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(distContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(distContext);
|
||||||
}
|
}
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance());
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWithCorrelationContextUsingWrap() {
|
void testWithBaggageUsingWrap() {
|
||||||
Runnable runnable;
|
Runnable runnable;
|
||||||
try (Scope wtm = contextManager.withContext(distContext)) {
|
try (Scope wtm = contextManager.withContext(distContext)) {
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(distContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(distContext);
|
||||||
runnable =
|
runnable =
|
||||||
Context.current()
|
Context.current()
|
||||||
.wrap(
|
.wrap(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(distContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(distContext);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(EmptyCorrelationContext.getInstance());
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(EmptyBaggage.getInstance());
|
||||||
// When we run the runnable we will have the CorrelationContext in the current Context.
|
// When we run the runnable we will have the Baggage in the current Context.
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,30 +14,29 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext;
|
package io.opentelemetry.sdk.baggage;
|
||||||
|
|
||||||
import static io.opentelemetry.sdk.correlationcontext.CorrelationContextTestUtil.listToCorrelationContext;
|
import static io.opentelemetry.sdk.baggage.BaggageTestUtil.listToBaggage;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import com.google.common.testing.EqualsTester;
|
import com.google.common.testing.EqualsTester;
|
||||||
import io.grpc.Context;
|
import io.grpc.Context;
|
||||||
|
import io.opentelemetry.baggage.Baggage;
|
||||||
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
|
import io.opentelemetry.baggage.BaggageUtils;
|
||||||
|
import io.opentelemetry.baggage.Entry;
|
||||||
|
import io.opentelemetry.baggage.EntryMetadata;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationsContextUtils;
|
|
||||||
import io.opentelemetry.correlationcontext.Entry;
|
|
||||||
import io.opentelemetry.correlationcontext.EntryMetadata;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link CorrelationContextSdk} and {@link CorrelationContextSdk.Builder}.
|
* Tests for {@link BaggageSdk} and {@link BaggageSdk.Builder}.
|
||||||
*
|
*
|
||||||
* <p>Tests for scope management with {@link CorrelationContextManagerSdk} are in {@link
|
* <p>Tests for scope management with {@link BaggageManagerSdk} are in {@link ScopedBaggageTest}.
|
||||||
* ScopedCorrelationContextTest}.
|
|
||||||
*/
|
*/
|
||||||
class CorrelationContextSdkTest {
|
class BaggageSdkTest {
|
||||||
private final CorrelationContextManager contextManager = new CorrelationContextManagerSdk();
|
private final BaggageManager contextManager = new BaggageManagerSdk();
|
||||||
|
|
||||||
private static final EntryMetadata TMD =
|
private static final EntryMetadata TMD =
|
||||||
EntryMetadata.create(EntryMetadata.EntryTtl.UNLIMITED_PROPAGATION);
|
EntryMetadata.create(EntryMetadata.EntryTtl.UNLIMITED_PROPAGATION);
|
||||||
|
|
@ -53,23 +52,23 @@ class CorrelationContextSdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getEntries_empty() {
|
void getEntries_empty() {
|
||||||
CorrelationContextSdk distContext = new CorrelationContextSdk.Builder().build();
|
BaggageSdk distContext = new BaggageSdk.Builder().build();
|
||||||
assertThat(distContext.getEntries()).isEmpty();
|
assertThat(distContext.getEntries()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getEntries_nonEmpty() {
|
void getEntries_nonEmpty() {
|
||||||
CorrelationContextSdk distContext = listToCorrelationContext(T1, T2);
|
BaggageSdk distContext = listToBaggage(T1, T2);
|
||||||
assertThat(distContext.getEntries()).containsExactly(T1, T2);
|
assertThat(distContext.getEntries()).containsExactly(T1, T2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getEntries_chain() {
|
void getEntries_chain() {
|
||||||
Entry t1alt = Entry.create(K1, V2, TMD);
|
Entry t1alt = Entry.create(K1, V2, TMD);
|
||||||
CorrelationContextSdk parent = listToCorrelationContext(T1, T2);
|
BaggageSdk parent = listToBaggage(T1, T2);
|
||||||
CorrelationContext distContext =
|
Baggage distContext =
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.setParent(parent)
|
.setParent(parent)
|
||||||
.put(t1alt.getKey(), t1alt.getValue(), t1alt.getEntryMetadata())
|
.put(t1alt.getKey(), t1alt.getValue(), t1alt.getEntryMetadata())
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -78,10 +77,10 @@ class CorrelationContextSdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void put_newKey() {
|
void put_newKey() {
|
||||||
CorrelationContextSdk distContext = listToCorrelationContext(T1);
|
BaggageSdk distContext = listToBaggage(T1);
|
||||||
assertThat(
|
assertThat(
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.setParent(distContext)
|
.setParent(distContext)
|
||||||
.put(K2, V2, TMD)
|
.put(K2, V2, TMD)
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -91,10 +90,10 @@ class CorrelationContextSdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void put_existingKey() {
|
void put_existingKey() {
|
||||||
CorrelationContextSdk distContext = listToCorrelationContext(T1);
|
BaggageSdk distContext = listToBaggage(T1);
|
||||||
assertThat(
|
assertThat(
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.setParent(distContext)
|
.setParent(distContext)
|
||||||
.put(K1, V2, TMD)
|
.put(K1, V2, TMD)
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -104,71 +103,61 @@ class CorrelationContextSdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void put_nullKey() {
|
void put_nullKey() {
|
||||||
CorrelationContextSdk distContext = listToCorrelationContext(T1);
|
BaggageSdk distContext = listToBaggage(T1);
|
||||||
CorrelationContext.Builder builder = contextManager.contextBuilder().setParent(distContext);
|
Baggage.Builder builder = contextManager.baggageBuilder().setParent(distContext);
|
||||||
assertThrows(NullPointerException.class, () -> builder.put(null, V2, TMD), "key");
|
assertThrows(NullPointerException.class, () -> builder.put(null, V2, TMD), "key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void put_nullValue() {
|
void put_nullValue() {
|
||||||
CorrelationContextSdk distContext = listToCorrelationContext(T1);
|
BaggageSdk distContext = listToBaggage(T1);
|
||||||
CorrelationContext.Builder builder = contextManager.contextBuilder().setParent(distContext);
|
Baggage.Builder builder = contextManager.baggageBuilder().setParent(distContext);
|
||||||
assertThrows(NullPointerException.class, () -> builder.put(K2, null, TMD), "value");
|
assertThrows(NullPointerException.class, () -> builder.put(K2, null, TMD), "value");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setParent_nullValue() {
|
void setParent_nullValue() {
|
||||||
CorrelationContextSdk parent = listToCorrelationContext(T1);
|
BaggageSdk parent = listToBaggage(T1);
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
() ->
|
() -> contextManager.baggageBuilder().setParent(parent).setParent((Baggage) null).build());
|
||||||
contextManager
|
|
||||||
.contextBuilder()
|
|
||||||
.setParent(parent)
|
|
||||||
.setParent((CorrelationContext) null)
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setParent_nullContext() {
|
void setParent_nullContext() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
() -> contextManager.contextBuilder().setParent((Context) null));
|
() -> contextManager.baggageBuilder().setParent((Context) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setParent_fromContext() {
|
void setParent_fromContext() {
|
||||||
CorrelationContextSdk parent = listToCorrelationContext(T1);
|
BaggageSdk parent = listToBaggage(T1);
|
||||||
Context context =
|
Context context = BaggageUtils.withBaggage(listToBaggage(T2), Context.current());
|
||||||
CorrelationsContextUtils.withCorrelationContext(
|
Baggage baggage = contextManager.baggageBuilder().setParent(parent).setParent(context).build();
|
||||||
listToCorrelationContext(T2), Context.current());
|
assertThat(baggage.getEntries()).containsExactly(T2);
|
||||||
CorrelationContext corrContext =
|
|
||||||
contextManager.contextBuilder().setParent(parent).setParent(context).build();
|
|
||||||
assertThat(corrContext.getEntries()).containsExactly(T2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setParent_fromEmptyContext() {
|
void setParent_fromEmptyContext() {
|
||||||
Context emptyContext = Context.current();
|
Context emptyContext = Context.current();
|
||||||
CorrelationContextSdk parent = listToCorrelationContext(T1);
|
BaggageSdk parent = listToBaggage(T1);
|
||||||
try (Scope scope = CorrelationsContextUtils.currentContextWith(parent)) {
|
try (Scope scope = BaggageUtils.currentContextWith(parent)) {
|
||||||
CorrelationContext corrContext =
|
Baggage baggage = contextManager.baggageBuilder().setParent(emptyContext).build();
|
||||||
contextManager.contextBuilder().setParent(emptyContext).build();
|
assertThat(baggage.getEntries()).isEmpty();
|
||||||
assertThat(corrContext.getEntries()).isEmpty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setParent_setNoParent() {
|
void setParent_setNoParent() {
|
||||||
CorrelationContextSdk parent = listToCorrelationContext(T1);
|
BaggageSdk parent = listToBaggage(T1);
|
||||||
CorrelationContext distContext =
|
Baggage distContext = contextManager.baggageBuilder().setParent(parent).setNoParent().build();
|
||||||
contextManager.contextBuilder().setParent(parent).setNoParent().build();
|
|
||||||
assertThat(distContext.getEntries()).isEmpty();
|
assertThat(distContext.getEntries()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void remove_existingKey() {
|
void remove_existingKey() {
|
||||||
CorrelationContextSdk.Builder builder = new CorrelationContextSdk.Builder();
|
BaggageSdk.Builder builder = new BaggageSdk.Builder();
|
||||||
builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata());
|
builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata());
|
||||||
builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata());
|
builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata());
|
||||||
|
|
||||||
|
|
@ -177,7 +166,7 @@ class CorrelationContextSdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void remove_differentKey() {
|
void remove_differentKey() {
|
||||||
CorrelationContextSdk.Builder builder = new CorrelationContextSdk.Builder();
|
BaggageSdk.Builder builder = new BaggageSdk.Builder();
|
||||||
builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata());
|
builder.put(T1.getKey(), T1.getValue(), T1.getEntryMetadata());
|
||||||
builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata());
|
builder.put(T2.getKey(), T2.getValue(), T2.getEntryMetadata());
|
||||||
|
|
||||||
|
|
@ -186,15 +175,15 @@ class CorrelationContextSdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void remove_keyFromParent() {
|
void remove_keyFromParent() {
|
||||||
CorrelationContextSdk distContext = listToCorrelationContext(T1, T2);
|
BaggageSdk distContext = listToBaggage(T1, T2);
|
||||||
assertThat(
|
assertThat(
|
||||||
contextManager.contextBuilder().setParent(distContext).remove(K1).build().getEntries())
|
contextManager.baggageBuilder().setParent(distContext).remove(K1).build().getEntries())
|
||||||
.containsExactly(T2);
|
.containsExactly(T2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void remove_nullKey() {
|
void remove_nullKey() {
|
||||||
CorrelationContext.Builder builder = contextManager.contextBuilder();
|
Baggage.Builder builder = contextManager.baggageBuilder();
|
||||||
assertThrows(NullPointerException.class, () -> builder.remove(null), "key");
|
assertThrows(NullPointerException.class, () -> builder.remove(null), "key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,11 +191,11 @@ class CorrelationContextSdkTest {
|
||||||
void testEquals() {
|
void testEquals() {
|
||||||
new EqualsTester()
|
new EqualsTester()
|
||||||
.addEqualityGroup(
|
.addEqualityGroup(
|
||||||
contextManager.contextBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(),
|
contextManager.baggageBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(),
|
||||||
contextManager.contextBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(),
|
contextManager.baggageBuilder().put(K1, V1, TMD).put(K2, V2, TMD).build(),
|
||||||
contextManager.contextBuilder().put(K2, V2, TMD).put(K1, V1, TMD).build())
|
contextManager.baggageBuilder().put(K2, V2, TMD).put(K1, V1, TMD).build())
|
||||||
.addEqualityGroup(contextManager.contextBuilder().put(K1, V1, TMD).put(K2, V1, TMD).build())
|
.addEqualityGroup(contextManager.baggageBuilder().put(K1, V1, TMD).put(K2, V1, TMD).build())
|
||||||
.addEqualityGroup(contextManager.contextBuilder().put(K1, V2, TMD).put(K2, V1, TMD).build())
|
.addEqualityGroup(contextManager.baggageBuilder().put(K1, V2, TMD).put(K2, V1, TMD).build())
|
||||||
.testEquals();
|
.testEquals();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,25 +14,25 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext;
|
package io.opentelemetry.sdk.baggage;
|
||||||
|
|
||||||
import io.opentelemetry.correlationcontext.Entry;
|
import io.opentelemetry.baggage.Entry;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class CorrelationContextTestUtil {
|
class BaggageTestUtil {
|
||||||
|
|
||||||
static CorrelationContextSdk listToCorrelationContext(Entry... entries) {
|
static BaggageSdk listToBaggage(Entry... entries) {
|
||||||
return listToCorrelationContext(Arrays.asList(entries));
|
return listToBaggage(Arrays.asList(entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
static CorrelationContextSdk listToCorrelationContext(List<Entry> entries) {
|
static BaggageSdk listToBaggage(List<Entry> entries) {
|
||||||
CorrelationContextSdk.Builder builder = new CorrelationContextSdk.Builder();
|
BaggageSdk.Builder builder = new BaggageSdk.Builder();
|
||||||
for (Entry entry : entries) {
|
for (Entry entry : entries) {
|
||||||
builder.put(entry.getKey(), entry.getValue(), entry.getEntryMetadata());
|
builder.put(entry.getKey(), entry.getValue(), entry.getEntryMetadata());
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CorrelationContextTestUtil() {}
|
private BaggageTestUtil() {}
|
||||||
}
|
}
|
||||||
|
|
@ -14,23 +14,23 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext;
|
package io.opentelemetry.sdk.baggage;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import io.opentelemetry.baggage.Baggage;
|
||||||
|
import io.opentelemetry.baggage.BaggageManager;
|
||||||
|
import io.opentelemetry.baggage.EmptyBaggage;
|
||||||
|
import io.opentelemetry.baggage.Entry;
|
||||||
|
import io.opentelemetry.baggage.EntryMetadata;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
|
||||||
import io.opentelemetry.correlationcontext.EmptyCorrelationContext;
|
|
||||||
import io.opentelemetry.correlationcontext.Entry;
|
|
||||||
import io.opentelemetry.correlationcontext.EntryMetadata;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the methods in {@link CorrelationContextManagerSdk} and {@link
|
* Unit tests for the methods in {@link BaggageManagerSdk} and {@link BaggageSdk.Builder} that
|
||||||
* CorrelationContextSdk.Builder} that interact with the current {@link CorrelationContextSdk}.
|
* interact with the current {@link BaggageSdk}.
|
||||||
*/
|
*/
|
||||||
class ScopedCorrelationContextTest {
|
class ScopedBaggageTest {
|
||||||
private static final String KEY_1 = "key 1";
|
private static final String KEY_1 = "key 1";
|
||||||
private static final String KEY_2 = "key 2";
|
private static final String KEY_2 = "key 2";
|
||||||
private static final String KEY_3 = "key 3";
|
private static final String KEY_3 = "key 3";
|
||||||
|
|
@ -45,120 +45,120 @@ class ScopedCorrelationContextTest {
|
||||||
private static final EntryMetadata METADATA_NO_PROPAGATION =
|
private static final EntryMetadata METADATA_NO_PROPAGATION =
|
||||||
EntryMetadata.create(EntryMetadata.EntryTtl.NO_PROPAGATION);
|
EntryMetadata.create(EntryMetadata.EntryTtl.NO_PROPAGATION);
|
||||||
|
|
||||||
private final CorrelationContextManager contextManager = new CorrelationContextManagerSdk();
|
private final BaggageManager contextManager = new BaggageManagerSdk();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void emptyCorrelationContext() {
|
void emptyBaggage() {
|
||||||
CorrelationContext defaultCorrelationContext = contextManager.getCurrentContext();
|
Baggage defaultBaggage = contextManager.getCurrentBaggage();
|
||||||
assertThat(defaultCorrelationContext.getEntries()).isEmpty();
|
assertThat(defaultBaggage.getEntries()).isEmpty();
|
||||||
assertThat(defaultCorrelationContext).isInstanceOf(EmptyCorrelationContext.class);
|
assertThat(defaultBaggage).isInstanceOf(EmptyBaggage.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withContext() {
|
void withContext() {
|
||||||
assertThat(contextManager.getCurrentContext().getEntries()).isEmpty();
|
assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty();
|
||||||
CorrelationContext scopedEntries =
|
Baggage scopedEntries =
|
||||||
contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
||||||
try (Scope scope = contextManager.withContext(scopedEntries)) {
|
try (Scope scope = contextManager.withContext(scopedEntries)) {
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(scopedEntries);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedEntries);
|
||||||
}
|
}
|
||||||
assertThat(contextManager.getCurrentContext().getEntries()).isEmpty();
|
assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createBuilderFromCurrentEntries() {
|
void createBuilderFromCurrentEntries() {
|
||||||
CorrelationContext scopedDistContext =
|
Baggage scopedDistContext =
|
||||||
contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
||||||
try (Scope scope = contextManager.withContext(scopedDistContext)) {
|
try (Scope scope = contextManager.withContext(scopedDistContext)) {
|
||||||
CorrelationContext newEntries =
|
Baggage newEntries =
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
||||||
.build();
|
.build();
|
||||||
assertThat(newEntries.getEntries())
|
assertThat(newEntries.getEntries())
|
||||||
.containsExactlyInAnyOrder(
|
.containsExactlyInAnyOrder(
|
||||||
Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION),
|
Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION),
|
||||||
Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION));
|
Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION));
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCurrentEntriesWithBuilder() {
|
void setCurrentEntriesWithBuilder() {
|
||||||
assertThat(contextManager.getCurrentContext().getEntries()).isEmpty();
|
assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty();
|
||||||
CorrelationContext scopedDistContext =
|
Baggage scopedDistContext =
|
||||||
contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
||||||
try (Scope scope = contextManager.withContext(scopedDistContext)) {
|
try (Scope scope = contextManager.withContext(scopedDistContext)) {
|
||||||
assertThat(contextManager.getCurrentContext().getEntries())
|
assertThat(contextManager.getCurrentBaggage().getEntries())
|
||||||
.containsExactly(Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION));
|
.containsExactly(Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION));
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext);
|
||||||
}
|
}
|
||||||
assertThat(contextManager.getCurrentContext().getEntries()).isEmpty();
|
assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addToCurrentEntriesWithBuilder() {
|
void addToCurrentEntriesWithBuilder() {
|
||||||
CorrelationContext scopedDistContext =
|
Baggage scopedDistContext =
|
||||||
contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
||||||
try (Scope scope1 = contextManager.withContext(scopedDistContext)) {
|
try (Scope scope1 = contextManager.withContext(scopedDistContext)) {
|
||||||
CorrelationContext innerDistContext =
|
Baggage innerDistContext =
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
||||||
.build();
|
.build();
|
||||||
try (Scope scope2 = contextManager.withContext(innerDistContext)) {
|
try (Scope scope2 = contextManager.withContext(innerDistContext)) {
|
||||||
assertThat(contextManager.getCurrentContext().getEntries())
|
assertThat(contextManager.getCurrentBaggage().getEntries())
|
||||||
.containsExactlyInAnyOrder(
|
.containsExactlyInAnyOrder(
|
||||||
Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION),
|
Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION),
|
||||||
Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION));
|
Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION));
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(innerDistContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(innerDistContext);
|
||||||
}
|
}
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multiScopeCorrelationContextWithMetadata() {
|
void multiScopeBaggageWithMetadata() {
|
||||||
CorrelationContext scopedDistContext =
|
Baggage scopedDistContext =
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION)
|
.put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION)
|
||||||
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
||||||
.build();
|
.build();
|
||||||
try (Scope scope1 = contextManager.withContext(scopedDistContext)) {
|
try (Scope scope1 = contextManager.withContext(scopedDistContext)) {
|
||||||
CorrelationContext innerDistContext =
|
Baggage innerDistContext =
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.put(KEY_3, VALUE_3, METADATA_NO_PROPAGATION)
|
.put(KEY_3, VALUE_3, METADATA_NO_PROPAGATION)
|
||||||
.put(KEY_2, VALUE_4, METADATA_NO_PROPAGATION)
|
.put(KEY_2, VALUE_4, METADATA_NO_PROPAGATION)
|
||||||
.build();
|
.build();
|
||||||
try (Scope scope2 = contextManager.withContext(innerDistContext)) {
|
try (Scope scope2 = contextManager.withContext(innerDistContext)) {
|
||||||
assertThat(contextManager.getCurrentContext().getEntries())
|
assertThat(contextManager.getCurrentBaggage().getEntries())
|
||||||
.containsExactlyInAnyOrder(
|
.containsExactlyInAnyOrder(
|
||||||
Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION),
|
Entry.create(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION),
|
||||||
Entry.create(KEY_2, VALUE_4, METADATA_NO_PROPAGATION),
|
Entry.create(KEY_2, VALUE_4, METADATA_NO_PROPAGATION),
|
||||||
Entry.create(KEY_3, VALUE_3, METADATA_NO_PROPAGATION));
|
Entry.create(KEY_3, VALUE_3, METADATA_NO_PROPAGATION));
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(innerDistContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(innerDistContext);
|
||||||
}
|
}
|
||||||
assertThat(contextManager.getCurrentContext()).isSameAs(scopedDistContext);
|
assertThat(contextManager.getCurrentBaggage()).isSameAs(scopedDistContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setNoParent_doesNotInheritContext() {
|
void setNoParent_doesNotInheritContext() {
|
||||||
assertThat(contextManager.getCurrentContext().getEntries()).isEmpty();
|
assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty();
|
||||||
CorrelationContext scopedDistContext =
|
Baggage scopedDistContext =
|
||||||
contextManager.contextBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
contextManager.baggageBuilder().put(KEY_1, VALUE_1, METADATA_UNLIMITED_PROPAGATION).build();
|
||||||
try (Scope scope = contextManager.withContext(scopedDistContext)) {
|
try (Scope scope = contextManager.withContext(scopedDistContext)) {
|
||||||
CorrelationContext innerDistContext =
|
Baggage innerDistContext =
|
||||||
contextManager
|
contextManager
|
||||||
.contextBuilder()
|
.baggageBuilder()
|
||||||
.setNoParent()
|
.setNoParent()
|
||||||
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
.put(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION)
|
||||||
.build();
|
.build();
|
||||||
assertThat(innerDistContext.getEntries())
|
assertThat(innerDistContext.getEntries())
|
||||||
.containsExactly(Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION));
|
.containsExactly(Entry.create(KEY_2, VALUE_2, METADATA_UNLIMITED_PROPAGATION));
|
||||||
}
|
}
|
||||||
assertThat(contextManager.getCurrentContext().getEntries()).isEmpty();
|
assertThat(contextManager.getCurrentBaggage().getEntries()).isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,19 +14,18 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext.spi;
|
package io.opentelemetry.sdk.baggage.spi;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
|
import io.opentelemetry.sdk.baggage.BaggageManagerSdk;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class CorrelationContextManagerFactorySdkTest {
|
class BaggageManagerFactorySdkTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDefault() {
|
void testDefault() {
|
||||||
assertThat(OpenTelemetry.getCorrelationContextManager())
|
assertThat(OpenTelemetry.getBaggageManager()).isInstanceOf(BaggageManagerSdk.class);
|
||||||
.isInstanceOf(CorrelationContextManagerSdk.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.sdk.correlationcontext;
|
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
|
||||||
import io.opentelemetry.correlationcontext.CorrelationsContextUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link CorrelationContextManagerSdk} is SDK implementation of {@link CorrelationContextManager}.
|
|
||||||
*/
|
|
||||||
public class CorrelationContextManagerSdk implements CorrelationContextManager {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext getCurrentContext() {
|
|
||||||
return CorrelationsContextUtils.getCurrentCorrelationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext.Builder contextBuilder() {
|
|
||||||
return new CorrelationContextSdk.Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Scope withContext(CorrelationContext distContext) {
|
|
||||||
return CorrelationsContextUtils.currentContextWith(distContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
io.opentelemetry.sdk.correlationcontext.spi.CorrelationContextManagerFactorySdk
|
|
||||||
|
|
@ -35,8 +35,8 @@ include ":opentelemetry-all",
|
||||||
":opentelemetry-integration-tests-tracecontext",
|
":opentelemetry-integration-tests-tracecontext",
|
||||||
":opentelemetry-opentracing-shim",
|
":opentelemetry-opentracing-shim",
|
||||||
":opentelemetry-proto",
|
":opentelemetry-proto",
|
||||||
|
":opentelemetry-sdk-baggage",
|
||||||
":opentelemetry-sdk-common",
|
":opentelemetry-sdk-common",
|
||||||
":opentelemetry-sdk-correlation-context",
|
|
||||||
":opentelemetry-sdk-metrics",
|
":opentelemetry-sdk-metrics",
|
||||||
":opentelemetry-sdk-tracing",
|
":opentelemetry-sdk-tracing",
|
||||||
":opentelemetry-sdk",
|
":opentelemetry-sdk",
|
||||||
|
|
@ -53,14 +53,14 @@ include ":opentelemetry-all",
|
||||||
|
|
||||||
rootProject.children.each {
|
rootProject.children.each {
|
||||||
it.projectDir = "$rootDir/" + it.name
|
it.projectDir = "$rootDir/" + it.name
|
||||||
.replace("opentelemetry-integration-tests-", "integration_tests/")
|
.replace("opentelemetry-integration-tests-", "integration_tests/")
|
||||||
.replace("opentelemetry-exporters-", "exporters/")
|
.replace("opentelemetry-exporters-", "exporters/")
|
||||||
.replace("opentelemetry-extension-", "extensions/")
|
.replace("opentelemetry-extension-", "extensions/")
|
||||||
.replace("opentelemetry-sdk-extension-", "sdk_extensions/")
|
.replace("opentelemetry-sdk-extension-", "sdk_extensions/")
|
||||||
.replace("opentelemetry-sdk-", "sdk/")
|
.replace("opentelemetry-sdk-", "sdk/")
|
||||||
.replace("logging-", "logging/")
|
.replace("logging-", "logging/")
|
||||||
.replace("opentelemetry-", "")
|
.replace("opentelemetry-", "")
|
||||||
.replace("-", "_") as File
|
.replace("-", "_") as File
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":opentelemetry-sdk").projectDir = "$rootDir/sdk/all" as File
|
project(":opentelemetry-sdk").projectDir = "$rootDir/sdk/all" as File
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue