Instrumentation scope (#4215)
* Add InstrumentationScopeInfo class * Rewrite tracer provider documentation * Refactor ComponentRegistry to use InstrumentationScopeInfo * Finish updating documentation to reference scope instead of library * PR feedback
This commit is contained in:
parent
9f10e0048e
commit
963bc384c8
|
@ -106,44 +106,45 @@ public final class GlobalOpenTelemetry {
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named tracer instance from the globally registered {@link TracerProvider}.
|
* Gets or creates a named tracer instance from the globally registered {@link TracerProvider}.
|
||||||
*
|
*
|
||||||
* <p>This is a shortcut method for {@code getTracerProvider().get(instrumentationName)}
|
* <p>This is a shortcut method for {@code getTracerProvider().get(instrumentationScopeName)}
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a tracer instance.
|
* @return a tracer instance.
|
||||||
*/
|
*/
|
||||||
public static Tracer getTracer(String instrumentationName) {
|
public static Tracer getTracer(String instrumentationScopeName) {
|
||||||
return get().getTracer(instrumentationName);
|
return get().getTracer(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named and versioned tracer instance from the globally registered {@link
|
* Gets or creates a named and versioned tracer instance from the globally registered {@link
|
||||||
* TracerProvider}.
|
* TracerProvider}.
|
||||||
*
|
*
|
||||||
* <p>This is a shortcut method for {@code getTracerProvider().get(instrumentationName,
|
* <p>This is a shortcut method for {@code getTracerProvider().get(instrumentationScopeName,
|
||||||
* instrumentationVersion)}
|
* instrumentationScopeVersion)}
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @param instrumentationVersion The version of the instrumentation library (e.g., "1.0.0").
|
* @param instrumentationScopeVersion The version of the instrumentation scope (e.g., "1.0.0").
|
||||||
* @return a tracer instance.
|
* @return a tracer instance.
|
||||||
*/
|
*/
|
||||||
public static Tracer getTracer(String instrumentationName, String instrumentationVersion) {
|
public static Tracer getTracer(
|
||||||
return get().getTracer(instrumentationName, instrumentationVersion);
|
String instrumentationScopeName, String instrumentationScopeVersion) {
|
||||||
|
return get().getTracer(instrumentationScopeName, instrumentationScopeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a TracerBuilder for a named {@link Tracer} instance.
|
* Creates a TracerBuilder for a named {@link Tracer} instance.
|
||||||
*
|
*
|
||||||
* <p>This is a shortcut method for {@code get().tracerBuilder(instrumentationName)}
|
* <p>This is a shortcut method for {@code get().tracerBuilder(instrumentationScopeName)}
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a TracerBuilder instance.
|
* @return a TracerBuilder instance.
|
||||||
* @since 1.4.0
|
* @since 1.4.0
|
||||||
*/
|
*/
|
||||||
public static TracerBuilder tracerBuilder(String instrumentationName) {
|
public static TracerBuilder tracerBuilder(String instrumentationScopeName) {
|
||||||
return get().tracerBuilder(instrumentationName);
|
return get().tracerBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,29 +159,29 @@ public final class GlobalOpenTelemetry {
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named meter instance from the globally registered {@link MeterProvider}.
|
* Gets or creates a named meter instance from the globally registered {@link MeterProvider}.
|
||||||
*
|
*
|
||||||
* <p>This is a shortcut method for {@code getMeterProvider().get(instrumentationName)}
|
* <p>This is a shortcut method for {@code getMeterProvider().get(instrumentationScopeName)}
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a Meter instance.
|
* @return a Meter instance.
|
||||||
* @since 1.10.0
|
* @since 1.10.0
|
||||||
*/
|
*/
|
||||||
public static Meter getMeter(String instrumentationName) {
|
public static Meter getMeter(String instrumentationScopeName) {
|
||||||
return get().getMeter(instrumentationName);
|
return get().getMeter(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a MeterBuilder for a named {@link Meter} instance.
|
* Creates a MeterBuilder for a named {@link Meter} instance.
|
||||||
*
|
*
|
||||||
* <p>This is a shortcut method for {@code get().meterBuilder(instrumentationName)}
|
* <p>This is a shortcut method for {@code get().meterBuilder(instrumentationScopeName)}
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a MeterBuilder instance.
|
* @return a MeterBuilder instance.
|
||||||
* @since 1.10.0
|
* @since 1.10.0
|
||||||
*/
|
*/
|
||||||
public static MeterBuilder meterBuilder(String instrumentationName) {
|
public static MeterBuilder meterBuilder(String instrumentationScopeName) {
|
||||||
return get().meterBuilder(instrumentationName);
|
return get().meterBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,8 +259,8 @@ public final class GlobalOpenTelemetry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TracerBuilder tracerBuilder(String instrumentationName) {
|
public TracerBuilder tracerBuilder(String instrumentationScopeName) {
|
||||||
return delegate.tracerBuilder(instrumentationName);
|
return delegate.tracerBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,37 +46,37 @@ public interface OpenTelemetry {
|
||||||
* Gets or creates a named tracer instance from the {@link TracerProvider} for this {@link
|
* Gets or creates a named tracer instance from the {@link TracerProvider} for this {@link
|
||||||
* OpenTelemetry}.
|
* OpenTelemetry}.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a tracer instance.
|
* @return a tracer instance.
|
||||||
*/
|
*/
|
||||||
default Tracer getTracer(String instrumentationName) {
|
default Tracer getTracer(String instrumentationScopeName) {
|
||||||
return getTracerProvider().get(instrumentationName);
|
return getTracerProvider().get(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named and versioned tracer instance from the {@link TracerProvider} in this
|
* Gets or creates a named and versioned tracer instance from the {@link TracerProvider} in this
|
||||||
* {@link OpenTelemetry}.
|
* {@link OpenTelemetry}.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @param instrumentationVersion The version of the instrumentation library (e.g., "1.0.0").
|
* @param instrumentationScopeVersion The version of the instrumentation scope (e.g., "1.0.0").
|
||||||
* @return a tracer instance.
|
* @return a tracer instance.
|
||||||
*/
|
*/
|
||||||
default Tracer getTracer(String instrumentationName, String instrumentationVersion) {
|
default Tracer getTracer(String instrumentationScopeName, String instrumentationScopeVersion) {
|
||||||
return getTracerProvider().get(instrumentationName, instrumentationVersion);
|
return getTracerProvider().get(instrumentationScopeName, instrumentationScopeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link TracerBuilder} for a named {@link Tracer} instance.
|
* Creates a {@link TracerBuilder} for a named {@link Tracer} instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a TracerBuilder instance.
|
* @return a TracerBuilder instance.
|
||||||
* @since 1.4.0
|
* @since 1.4.0
|
||||||
*/
|
*/
|
||||||
default TracerBuilder tracerBuilder(String instrumentationName) {
|
default TracerBuilder tracerBuilder(String instrumentationScopeName) {
|
||||||
return getTracerProvider().tracerBuilder(instrumentationName);
|
return getTracerProvider().tracerBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,25 +92,25 @@ public interface OpenTelemetry {
|
||||||
* Gets or creates a named meter instance from the {@link MeterProvider} for this {@link
|
* Gets or creates a named meter instance from the {@link MeterProvider} for this {@link
|
||||||
* OpenTelemetry}.
|
* OpenTelemetry}.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a Meter instance.
|
* @return a Meter instance.
|
||||||
* @since 1.10.0
|
* @since 1.10.0
|
||||||
*/
|
*/
|
||||||
default Meter getMeter(String instrumentationName) {
|
default Meter getMeter(String instrumentationScopeName) {
|
||||||
return getMeterProvider().get(instrumentationName);
|
return getMeterProvider().get(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link MeterBuilder} for a named {@link Tracer} instance.
|
* Creates a {@link MeterBuilder} for a named {@link Tracer} instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a MeterBuilder instance.
|
* @return a MeterBuilder instance.
|
||||||
* @since 1.10.0
|
* @since 1.10.0
|
||||||
*/
|
*/
|
||||||
default MeterBuilder meterBuilder(String instrumentationName) {
|
default MeterBuilder meterBuilder(String instrumentationScopeName) {
|
||||||
return getMeterProvider().meterBuilder(instrumentationName);
|
return getMeterProvider().meterBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link ContextPropagators} for this {@link OpenTelemetry}. */
|
/** Returns the {@link ContextPropagators} for this {@link OpenTelemetry}. */
|
||||||
|
|
|
@ -8,7 +8,7 @@ package io.opentelemetry.api.metrics;
|
||||||
/** A {@link MeterProvider} that does nothing. */
|
/** A {@link MeterProvider} that does nothing. */
|
||||||
class DefaultMeterProvider implements MeterProvider {
|
class DefaultMeterProvider implements MeterProvider {
|
||||||
@Override
|
@Override
|
||||||
public MeterBuilder meterBuilder(String instrumentationName) {
|
public MeterBuilder meterBuilder(String instrumentationScopeName) {
|
||||||
return BUILDER_INSTANCE;
|
return BUILDER_INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class DefaultMeterProvider implements MeterProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MeterBuilder setInstrumentationVersion(String instrumentationVersion) {
|
public MeterBuilder setInstrumentationVersion(String instrumentationScopeVersion) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||||
* <p>Instruments are obtained through builders provided by this interface. Each builder has a
|
* <p>Instruments are obtained through builders provided by this interface. Each builder has a
|
||||||
* default "type" associated with recordings that may be changed.
|
* default "type" associated with recordings that may be changed.
|
||||||
*
|
*
|
||||||
* <p>A Meter is generally associated with an instrumentation library, e.g. "I monitor apache
|
* <p>A Meter is generally associated with an instrumentation scope, e.g. "I monitor apache
|
||||||
* httpclient".
|
* httpclient".
|
||||||
*
|
*
|
||||||
* <p>Choosing an instrument can be hard, but here's a rule of thumb for selecting the right
|
* <p>Choosing an instrument can be hard, but here's a rule of thumb for selecting the right
|
||||||
|
|
|
@ -18,19 +18,18 @@ public interface MeterBuilder {
|
||||||
* <p>Schemas are used to identify expected metrics (semantic conventions) and allow backends to
|
* <p>Schemas are used to identify expected metrics (semantic conventions) and allow backends to
|
||||||
* "automatically migrate" to supported versions.
|
* "automatically migrate" to supported versions.
|
||||||
*
|
*
|
||||||
* @param schemaUrl The URL of the OpenTelemetry schema being used by this instrumentation
|
* @param schemaUrl The URL of the OpenTelemetry schema being used by this instrumentation scope.
|
||||||
* library.
|
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
MeterBuilder setSchemaUrl(String schemaUrl);
|
MeterBuilder setSchemaUrl(String schemaUrl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns a version to the instrumentation library that is using the resulting Meter.
|
* Assigns a version to the instrumentation scope that is using the resulting Meter.
|
||||||
*
|
*
|
||||||
* @param instrumentationVersion The version of the instrumentation library.
|
* @param instrumentationScopeVersion The version of the instrumentation scope.
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
MeterBuilder setInstrumentationVersion(String instrumentationVersion);
|
MeterBuilder setInstrumentationVersion(String instrumentationScopeVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a {@link Meter} instance.
|
* Gets or creates a {@link Meter} instance.
|
||||||
|
|
|
@ -23,23 +23,23 @@ public interface MeterProvider {
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named and versioned meter instance.
|
* Gets or creates a named and versioned meter instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a meter instance.
|
* @return a meter instance.
|
||||||
*/
|
*/
|
||||||
default Meter get(String instrumentationName) {
|
default Meter get(String instrumentationScopeName) {
|
||||||
return meterBuilder(instrumentationName).build();
|
return meterBuilder(instrumentationScopeName).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a MeterBuilder for a named meter instance.
|
* Creates a MeterBuilder for a named meter instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a MeterBuilder instance.
|
* @return a MeterBuilder instance.
|
||||||
* @since 1.4.0
|
* @since 1.4.0
|
||||||
*/
|
*/
|
||||||
MeterBuilder meterBuilder(String instrumentationName);
|
MeterBuilder meterBuilder(String instrumentationScopeName);
|
||||||
|
|
||||||
/** Returns a no-op {@link MeterProvider} which provides meters which do not record or emit. */
|
/** Returns a no-op {@link MeterProvider} which provides meters which do not record or emit. */
|
||||||
static MeterProvider noop() {
|
static MeterProvider noop() {
|
||||||
|
|
|
@ -18,7 +18,7 @@ class DefaultTracerBuilder implements TracerBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TracerBuilder setInstrumentationVersion(String instrumentationVersion) {
|
public TracerBuilder setInstrumentationVersion(String instrumentationScopeVersion) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@ class DefaultTracerProvider implements TracerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName) {
|
public Tracer get(String instrumentationScopeName) {
|
||||||
return DefaultTracer.getInstance();
|
return DefaultTracer.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName, String instrumentationVersion) {
|
public Tracer get(String instrumentationScopeName, String instrumentationScopeVersion) {
|
||||||
return DefaultTracer.getInstance();
|
return DefaultTracer.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,19 +15,18 @@ public interface TracerBuilder {
|
||||||
/**
|
/**
|
||||||
* Assign an OpenTelemetry schema URL to the resulting Tracer.
|
* Assign an OpenTelemetry schema URL to the resulting Tracer.
|
||||||
*
|
*
|
||||||
* @param schemaUrl The URL of the OpenTelemetry schema being used by this instrumentation
|
* @param schemaUrl The URL of the OpenTelemetry schema being used by this instrumentation scope.
|
||||||
* library.
|
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
TracerBuilder setSchemaUrl(String schemaUrl);
|
TracerBuilder setSchemaUrl(String schemaUrl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign a version to the instrumentation library that is using the resulting Tracer.
|
* Assign a version to the instrumentation scope that is using the resulting Tracer.
|
||||||
*
|
*
|
||||||
* @param instrumentationVersion The version of the instrumentation library.
|
* @param instrumentationScopeVersion The version of the instrumentation scope.
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
TracerBuilder setInstrumentationVersion(String instrumentationVersion);
|
TracerBuilder setInstrumentationVersion(String instrumentationScopeVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a {@link Tracer} instance.
|
* Gets or creates a {@link Tracer} instance.
|
||||||
|
|
|
@ -27,35 +27,31 @@ public interface TracerProvider {
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named tracer instance.
|
* Gets or creates a named tracer instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null. If the
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* instrumented library is providing its own instrumentation, this should match the library
|
|
||||||
* name.
|
|
||||||
* @return a tracer instance.
|
* @return a tracer instance.
|
||||||
*/
|
*/
|
||||||
Tracer get(String instrumentationName);
|
Tracer get(String instrumentationScopeName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named and versioned tracer instance.
|
* Gets or creates a named and versioned tracer instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null. If the
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* instrumented library is providing its own instrumentation, this should match the library
|
* @param instrumentationScopeVersion The version of the instrumentation scope (e.g., "1.0.0").
|
||||||
* name.
|
|
||||||
* @param instrumentationVersion The version of the instrumentation library (e.g., "1.0.0").
|
|
||||||
* @return a tracer instance.
|
* @return a tracer instance.
|
||||||
*/
|
*/
|
||||||
Tracer get(String instrumentationName, String instrumentationVersion);
|
Tracer get(String instrumentationScopeName, String instrumentationScopeVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a TracerBuilder for a named {@link Tracer} instance.
|
* Creates a TracerBuilder for a named {@link Tracer} instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName The name of the instrumentation library, not the name of the
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
* instrument*ed* library.
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a TracerBuilder instance.
|
* @return a TracerBuilder instance.
|
||||||
* @since 1.4.0
|
* @since 1.4.0
|
||||||
*/
|
*/
|
||||||
default TracerBuilder tracerBuilder(String instrumentationName) {
|
default TracerBuilder tracerBuilder(String instrumentationScopeName) {
|
||||||
return DefaultTracerBuilder.getInstance();
|
return DefaultTracerBuilder.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,12 @@
|
||||||
Comparing source compatibility of against
|
Comparing source compatibility of against
|
||||||
No changes.
|
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.common.InstrumentationScopeInfo (not serializable)
|
||||||
|
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
|
||||||
|
+++ NEW SUPERCLASS: java.lang.Object
|
||||||
|
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.InstrumentationScopeInfo create(java.lang.String)
|
||||||
|
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.InstrumentationScopeInfo create(java.lang.String, java.lang.String, java.lang.String)
|
||||||
|
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.InstrumentationScopeInfo empty()
|
||||||
|
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getName()
|
||||||
|
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getSchemaUrl()
|
||||||
|
+++ NEW ANNOTATION: javax.annotation.Nullable
|
||||||
|
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getVersion()
|
||||||
|
+++ NEW ANNOTATION: javax.annotation.Nullable
|
||||||
|
|
|
@ -20,12 +20,12 @@ enum NoopTracerProvider implements TracerProvider {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName) {
|
public Tracer get(String instrumentationScopeName) {
|
||||||
return NoopTracer.INSTANCE;
|
return NoopTracer.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName, String instrumentationVersion) {
|
public Tracer get(String instrumentationScopeName, String instrumentationScopeVersion) {
|
||||||
return NoopTracer.INSTANCE;
|
return NoopTracer.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,18 +98,18 @@ public final class OpenTelemetrySdk implements OpenTelemetry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName) {
|
public Tracer get(String instrumentationScopeName) {
|
||||||
return delegate.get(instrumentationName);
|
return delegate.get(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName, String instrumentationVersion) {
|
public Tracer get(String instrumentationScopeName, String instrumentationScopeVersion) {
|
||||||
return delegate.get(instrumentationName, instrumentationVersion);
|
return delegate.get(instrumentationScopeName, instrumentationScopeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TracerBuilder tracerBuilder(String instrumentationName) {
|
public TracerBuilder tracerBuilder(String instrumentationScopeName) {
|
||||||
return delegate.tracerBuilder(instrumentationName);
|
return delegate.tracerBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SdkTracerProvider unobfuscate() {
|
public SdkTracerProvider unobfuscate() {
|
||||||
|
@ -135,8 +135,8 @@ public final class OpenTelemetrySdk implements OpenTelemetry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MeterBuilder meterBuilder(String instrumentationName) {
|
public MeterBuilder meterBuilder(String instrumentationScopeName) {
|
||||||
return delegate.meterBuilder(instrumentationName);
|
return delegate.meterBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SdkMeterProvider unobfuscate() {
|
public SdkMeterProvider unobfuscate() {
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.sdk.common;
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds information about instrumentation scope.
|
||||||
|
*
|
||||||
|
* <p>Instrumentation scope is a logical unit of the application code with which emitted telemetry
|
||||||
|
* is associated. The most common approach is to use the instrumentation library as the scope,
|
||||||
|
* however other scopes are also common, e.g. a module, a package, or a class may be chosen as the
|
||||||
|
* instrumentation scope.
|
||||||
|
*/
|
||||||
|
@AutoValue
|
||||||
|
@Immutable
|
||||||
|
public abstract class InstrumentationScopeInfo {
|
||||||
|
private static final InstrumentationScopeInfo EMPTY = create("");
|
||||||
|
|
||||||
|
/** Creates a new instance of {@link InstrumentationScopeInfo}. */
|
||||||
|
public static InstrumentationScopeInfo create(String name) {
|
||||||
|
requireNonNull(name, "name");
|
||||||
|
return new AutoValue_InstrumentationScopeInfo(name, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a new instance of {@link InstrumentationScopeInfo}. */
|
||||||
|
public static InstrumentationScopeInfo create(
|
||||||
|
String name, @Nullable String version, @Nullable String schemaUrl) {
|
||||||
|
requireNonNull(name, "name");
|
||||||
|
return new AutoValue_InstrumentationScopeInfo(name, version, schemaUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns an "empty" {@link InstrumentationScopeInfo}. */
|
||||||
|
public static InstrumentationScopeInfo empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the name of the instrumentation scope. */
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
/** Returns the version of the instrumentation scope, or {@code null} if not available. */
|
||||||
|
@Nullable
|
||||||
|
public abstract String getVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the URL of the schema used by this instrumentation scope, or {@code null} if not
|
||||||
|
* available.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public abstract String getSchemaUrl();
|
||||||
|
|
||||||
|
InstrumentationScopeInfo() {}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.internal;
|
package io.opentelemetry.sdk.internal;
|
||||||
|
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -17,17 +17,17 @@ import javax.annotation.Nullable;
|
||||||
/**
|
/**
|
||||||
* Base class for all the provider classes (TracerProvider, MeterProvider, etc.).
|
* Base class for all the provider classes (TracerProvider, MeterProvider, etc.).
|
||||||
*
|
*
|
||||||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can hange at
|
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
|
||||||
* any time.
|
* at any time.
|
||||||
*
|
*
|
||||||
* @param <V> the type of the registered value.
|
* @param <V> the type of the registered value.
|
||||||
*/
|
*/
|
||||||
public final class ComponentRegistry<V> {
|
public final class ComponentRegistry<V> {
|
||||||
|
|
||||||
private final ConcurrentMap<InstrumentationLibraryInfo, V> registry = new ConcurrentHashMap<>();
|
private final ConcurrentMap<InstrumentationScopeInfo, V> registry = new ConcurrentHashMap<>();
|
||||||
private final Function<InstrumentationLibraryInfo, V> factory;
|
private final Function<InstrumentationScopeInfo, V> factory;
|
||||||
|
|
||||||
public ComponentRegistry(Function<InstrumentationLibraryInfo, V> factory) {
|
public ComponentRegistry(Function<InstrumentationScopeInfo, V> factory) {
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,11 +36,11 @@ public final class ComponentRegistry<V> {
|
||||||
* otherwise creates a new instance and associates it with the given name and {@code null} version
|
* otherwise creates a new instance and associates it with the given name and {@code null} version
|
||||||
* and schemaUrl.
|
* and schemaUrl.
|
||||||
*
|
*
|
||||||
* @param instrumentationName the name of the instrumentation library.
|
* @param instrumentationScopeName the name of the instrumentation scope.
|
||||||
* @return the registered value associated with this name and {@code null} version.
|
* @return the registered value associated with this name and {@code null} version.
|
||||||
*/
|
*/
|
||||||
public V get(String instrumentationName) {
|
public V get(String instrumentationScopeName) {
|
||||||
return get(instrumentationName, null);
|
return get(instrumentationScopeName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,39 +48,40 @@ public final class ComponentRegistry<V> {
|
||||||
* new instance and associates it with the given name and version. The schemaUrl will be set to
|
* new instance and associates it with the given name and version. The schemaUrl will be set to
|
||||||
* null.
|
* null.
|
||||||
*
|
*
|
||||||
* @param instrumentationName the name of the instrumentation library.
|
* @param instrumentationScopeName the name of the instrumentation scope.
|
||||||
* @param instrumentationVersion the version of the instrumentation library.
|
* @param instrumentationScopeVersion the version of the instrumentation scope.
|
||||||
* @return the registered value associated with this name and version.
|
* @return the registered value associated with this name and version.
|
||||||
*/
|
*/
|
||||||
public V get(String instrumentationName, @Nullable String instrumentationVersion) {
|
public V get(String instrumentationScopeName, @Nullable String instrumentationScopeVersion) {
|
||||||
return get(instrumentationName, instrumentationVersion, null);
|
return get(instrumentationScopeName, instrumentationScopeVersion, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the registered value associated with this name and version if any, otherwise creates a
|
* Returns the registered value associated with this name and version if any, otherwise creates a
|
||||||
* new instance and associates it with the given name and version.
|
* new instance and associates it with the given name and version.
|
||||||
*
|
*
|
||||||
* @param instrumentationName the name of the instrumentation library.
|
* @param instrumentationScopeName the name of the instrumentation scope.
|
||||||
* @param instrumentationVersion the version of the instrumentation library.
|
* @param instrumentationScopeVersion the version of the instrumentation scope.
|
||||||
* @param schemaUrl the URL of the OpenTelemetry schema used by the instrumentation library.
|
* @param schemaUrl the URL of the OpenTelemetry schema used by the instrumentation scope.
|
||||||
* @return the registered value associated with this name and version.
|
* @return the registered value associated with this name and version.
|
||||||
* @since 1.4.0
|
* @since 1.4.0
|
||||||
*/
|
*/
|
||||||
public V get(
|
public V get(
|
||||||
String instrumentationName,
|
String instrumentationScopeName,
|
||||||
@Nullable String instrumentationVersion,
|
@Nullable String instrumentationScopeVersion,
|
||||||
@Nullable String schemaUrl) {
|
@Nullable String schemaUrl) {
|
||||||
InstrumentationLibraryInfo instrumentationLibraryInfo =
|
InstrumentationScopeInfo instrumentationScopeInfo =
|
||||||
InstrumentationLibraryInfo.create(instrumentationName, instrumentationVersion, schemaUrl);
|
InstrumentationScopeInfo.create(
|
||||||
|
instrumentationScopeName, instrumentationScopeVersion, schemaUrl);
|
||||||
|
|
||||||
// Optimistic lookup, before creating the new component.
|
// Optimistic lookup, before creating the new component.
|
||||||
V component = registry.get(instrumentationLibraryInfo);
|
V component = registry.get(instrumentationScopeInfo);
|
||||||
if (component != null) {
|
if (component != null) {
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
V newComponent = factory.apply(instrumentationLibraryInfo);
|
V newComponent = factory.apply(instrumentationScopeInfo);
|
||||||
V oldComponent = registry.putIfAbsent(instrumentationLibraryInfo, newComponent);
|
V oldComponent = registry.putIfAbsent(instrumentationScopeInfo, newComponent);
|
||||||
return oldComponent != null ? oldComponent : newComponent;
|
return oldComponent != null ? oldComponent : newComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.sdk.internal;
|
||||||
|
|
||||||
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
|
* any time.
|
||||||
|
*/
|
||||||
|
public final class InstrumentationScopeUtil {
|
||||||
|
|
||||||
|
/** Convert to {@link InstrumentationLibraryInfo}. */
|
||||||
|
public static InstrumentationLibraryInfo toInstrumentationLibraryInfo(
|
||||||
|
InstrumentationScopeInfo instrumentationScopeInfo) {
|
||||||
|
return InstrumentationLibraryInfo.create(
|
||||||
|
instrumentationScopeInfo.getName(),
|
||||||
|
instrumentationScopeInfo.getVersion(),
|
||||||
|
instrumentationScopeInfo.getSchemaUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
private InstrumentationScopeUtil() {}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.sdk.common;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class InstrumentationScopeInfoTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void emptyScopeInfo() {
|
||||||
|
assertThat(InstrumentationScopeInfo.empty().getName()).isEmpty();
|
||||||
|
assertThat(InstrumentationScopeInfo.empty().getVersion()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void nullName() {
|
||||||
|
assertThatThrownBy(() -> InstrumentationScopeInfo.create(null))
|
||||||
|
.isInstanceOf(NullPointerException.class)
|
||||||
|
.hasMessage("name");
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,10 +8,9 @@ package io.opentelemetry.sdk.internal;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Tests for {@link InstrumentationLibraryInfo}. */
|
|
||||||
class ComponentRegistryTest {
|
class ComponentRegistryTest {
|
||||||
|
|
||||||
private static final String INSTRUMENTATION_NAME = "test_name";
|
private static final String INSTRUMENTATION_NAME = "test_name";
|
||||||
|
@ -20,18 +19,18 @@ class ComponentRegistryTest {
|
||||||
new ComponentRegistry<>(TestComponent::new);
|
new ComponentRegistry<>(TestComponent::new);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void libraryName_MustNotBeNull() {
|
void scopeName_MustNotBeNull() {
|
||||||
assertThatThrownBy(() -> registry.get(null, "version"))
|
assertThatThrownBy(() -> registry.get(null, "version"))
|
||||||
.isInstanceOf(NullPointerException.class)
|
.isInstanceOf(NullPointerException.class)
|
||||||
.hasMessage("name");
|
.hasMessage("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void libraryVersion_AllowsNull() {
|
void scopeVersion_AllowsNull() {
|
||||||
TestComponent testComponent = registry.get(INSTRUMENTATION_NAME, null);
|
TestComponent testComponent = registry.get(INSTRUMENTATION_NAME, null);
|
||||||
assertThat(testComponent).isNotNull();
|
assertThat(testComponent).isNotNull();
|
||||||
assertThat(testComponent.instrumentationLibraryInfo.getName()).isEqualTo(INSTRUMENTATION_NAME);
|
assertThat(testComponent.instrumentationScopeInfo.getName()).isEqualTo(INSTRUMENTATION_NAME);
|
||||||
assertThat(testComponent.instrumentationLibraryInfo.getVersion()).isNull();
|
assertThat(testComponent.instrumentationScopeInfo.getVersion()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -60,10 +59,10 @@ class ComponentRegistryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestComponent {
|
private static final class TestComponent {
|
||||||
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
private final InstrumentationScopeInfo instrumentationScopeInfo;
|
||||||
|
|
||||||
private TestComponent(InstrumentationLibraryInfo instrumentationLibraryInfo) {
|
private TestComponent(InstrumentationScopeInfo instrumentationScopeInfo) {
|
||||||
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
|
this.instrumentationScopeInfo = instrumentationScopeInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,18 @@ public interface LogEmitterBuilder {
|
||||||
/**
|
/**
|
||||||
* Assign an OpenTelemetry schema URL to the resulting {@link LogEmitter}.
|
* Assign an OpenTelemetry schema URL to the resulting {@link LogEmitter}.
|
||||||
*
|
*
|
||||||
* @param schemaUrl the URL of the OpenTelemetry schema being used by this instrumentation library
|
* @param schemaUrl the URL of the OpenTelemetry schema being used by this instrumentation scope
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
LogEmitterBuilder setSchemaUrl(String schemaUrl);
|
LogEmitterBuilder setSchemaUrl(String schemaUrl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign a version to the instrumentation library that is using the resulting {@link LogEmitter}.
|
* Assign a version to the instrumentation scope that is using the resulting {@link LogEmitter}.
|
||||||
*
|
*
|
||||||
* @param instrumentationVersion the version of the instrumentation library
|
* @param instrumentationScopeVersion the version of the instrumentation scope
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
LogEmitterBuilder setInstrumentationVersion(String instrumentationVersion);
|
LogEmitterBuilder setInstrumentationVersion(String instrumentationScopeVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a {@link LogEmitter} instance.
|
* Gets or creates a {@link LogEmitter} instance.
|
||||||
|
|
|
@ -6,19 +6,24 @@
|
||||||
package io.opentelemetry.sdk.logs;
|
package io.opentelemetry.sdk.logs;
|
||||||
|
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
|
import io.opentelemetry.sdk.internal.InstrumentationScopeUtil;
|
||||||
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
|
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
|
||||||
|
|
||||||
/** SDK implementation of {@link LogEmitter}. */
|
/** SDK implementation of {@link LogEmitter}. */
|
||||||
final class SdkLogEmitter implements LogEmitter {
|
final class SdkLogEmitter implements LogEmitter {
|
||||||
|
|
||||||
private final LogEmitterSharedState logEmitterSharedState;
|
private final LogEmitterSharedState logEmitterSharedState;
|
||||||
|
private final InstrumentationScopeInfo instrumentationScopeInfo;
|
||||||
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
||||||
|
|
||||||
SdkLogEmitter(
|
SdkLogEmitter(
|
||||||
LogEmitterSharedState logEmitterSharedState,
|
LogEmitterSharedState logEmitterSharedState,
|
||||||
InstrumentationLibraryInfo instrumentationLibraryInfo) {
|
InstrumentationScopeInfo instrumentationScopeInfo) {
|
||||||
this.logEmitterSharedState = logEmitterSharedState;
|
this.logEmitterSharedState = logEmitterSharedState;
|
||||||
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
|
this.instrumentationScopeInfo = instrumentationScopeInfo;
|
||||||
|
this.instrumentationLibraryInfo =
|
||||||
|
InstrumentationScopeUtil.toInstrumentationLibraryInfo(instrumentationScopeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,7 +37,7 @@ final class SdkLogEmitter implements LogEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisibleForTesting
|
// VisibleForTesting
|
||||||
InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
|
InstrumentationScopeInfo getInstrumentationScopeInfo() {
|
||||||
return instrumentationLibraryInfo;
|
return instrumentationScopeInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,13 @@ import javax.annotation.Nullable;
|
||||||
final class SdkLogEmitterBuilder implements LogEmitterBuilder {
|
final class SdkLogEmitterBuilder implements LogEmitterBuilder {
|
||||||
|
|
||||||
private final ComponentRegistry<SdkLogEmitter> registry;
|
private final ComponentRegistry<SdkLogEmitter> registry;
|
||||||
private final String instrumentationName;
|
private final String instrumentationScopeName;
|
||||||
@Nullable private String getInstrumentationVersion;
|
@Nullable private String instrumentationScopeVersion;
|
||||||
@Nullable private String schemaUrl;
|
@Nullable private String schemaUrl;
|
||||||
|
|
||||||
SdkLogEmitterBuilder(ComponentRegistry<SdkLogEmitter> registry, String instrumentationName) {
|
SdkLogEmitterBuilder(ComponentRegistry<SdkLogEmitter> registry, String instrumentationScopeName) {
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
this.instrumentationName = instrumentationName;
|
this.instrumentationScopeName = instrumentationScopeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,13 +27,13 @@ final class SdkLogEmitterBuilder implements LogEmitterBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SdkLogEmitterBuilder setInstrumentationVersion(String instrumentationVersion) {
|
public SdkLogEmitterBuilder setInstrumentationVersion(String instrumentationScopeVersion) {
|
||||||
this.getInstrumentationVersion = instrumentationVersion;
|
this.instrumentationScopeVersion = instrumentationScopeVersion;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SdkLogEmitter build() {
|
public SdkLogEmitter build() {
|
||||||
return registry.get(instrumentationName, getInstrumentationVersion, schemaUrl);
|
return registry.get(instrumentationScopeName, instrumentationScopeVersion, schemaUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,32 +42,32 @@ public final class SdkLogEmitterProvider implements Closeable {
|
||||||
this.sharedState = new LogEmitterSharedState(resource, logLimitsSupplier, processors, clock);
|
this.sharedState = new LogEmitterSharedState(resource, logLimitsSupplier, processors, clock);
|
||||||
this.logEmitterComponentRegistry =
|
this.logEmitterComponentRegistry =
|
||||||
new ComponentRegistry<>(
|
new ComponentRegistry<>(
|
||||||
instrumentationLibraryInfo ->
|
instrumentationScopeInfo -> new SdkLogEmitter(sharedState, instrumentationScopeInfo));
|
||||||
new SdkLogEmitter(sharedState, instrumentationLibraryInfo));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a named log emitter instance.
|
* Gets or creates a named log emitter instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName the name of the instrumentation library
|
* @param instrumentationScopeName A name uniquely identifying the instrumentation scope, such as
|
||||||
|
* the instrumentation library, package, or fully qualified class name. Must not be null.
|
||||||
* @return a log emitter instance
|
* @return a log emitter instance
|
||||||
*/
|
*/
|
||||||
public LogEmitter get(String instrumentationName) {
|
public LogEmitter get(String instrumentationScopeName) {
|
||||||
return logEmitterBuilder(instrumentationName).build();
|
return logEmitterBuilder(instrumentationScopeName).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link LogEmitterBuilder} instance.
|
* Creates a {@link LogEmitterBuilder} instance.
|
||||||
*
|
*
|
||||||
* @param instrumentationName the name of the instrumentation library
|
* @param instrumentationScopeName the name of the instrumentation scope
|
||||||
* @return a log emitter builder instance
|
* @return a log emitter builder instance
|
||||||
*/
|
*/
|
||||||
public LogEmitterBuilder logEmitterBuilder(String instrumentationName) {
|
public LogEmitterBuilder logEmitterBuilder(String instrumentationScopeName) {
|
||||||
if (instrumentationName == null || instrumentationName.isEmpty()) {
|
if (instrumentationScopeName == null || instrumentationScopeName.isEmpty()) {
|
||||||
LOGGER.fine("LogEmitter requested without instrumentation name.");
|
LOGGER.fine("LogEmitter requested without instrumentation scope name.");
|
||||||
instrumentationName = DEFAULT_EMITTER_NAME;
|
instrumentationScopeName = DEFAULT_EMITTER_NAME;
|
||||||
}
|
}
|
||||||
return new SdkLogEmitterBuilder(logEmitterComponentRegistry, instrumentationName);
|
return new SdkLogEmitterBuilder(logEmitterComponentRegistry, instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,7 +15,7 @@ import static org.mockito.Mockito.when;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.sdk.common.Clock;
|
import io.opentelemetry.sdk.common.Clock;
|
||||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
import io.opentelemetry.sdk.logs.data.LogData;
|
import io.opentelemetry.sdk.logs.data.LogData;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -175,8 +175,8 @@ class SdkLogEmitterProviderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void logEmitterBuilder_PropagatesToEmitter() {
|
void logEmitterBuilder_PropagatesToEmitter() {
|
||||||
InstrumentationLibraryInfo expected =
|
InstrumentationScopeInfo expected =
|
||||||
InstrumentationLibraryInfo.create("test", "version", "http://url");
|
InstrumentationScopeInfo.create("test", "version", "http://url");
|
||||||
assertThat(
|
assertThat(
|
||||||
((SdkLogEmitter)
|
((SdkLogEmitter)
|
||||||
sdkLogEmitterProvider
|
sdkLogEmitterProvider
|
||||||
|
@ -184,7 +184,7 @@ class SdkLogEmitterProviderTest {
|
||||||
.setInstrumentationVersion("version")
|
.setInstrumentationVersion("version")
|
||||||
.setSchemaUrl("http://url")
|
.setSchemaUrl("http://url")
|
||||||
.build())
|
.build())
|
||||||
.getInstrumentationLibraryInfo())
|
.getInstrumentationScopeInfo())
|
||||||
.isEqualTo(expected);
|
.isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,13 +192,13 @@ class SdkLogEmitterProviderTest {
|
||||||
void logEmitterBuilder_DefaultEmitterName() {
|
void logEmitterBuilder_DefaultEmitterName() {
|
||||||
assertThat(
|
assertThat(
|
||||||
((SdkLogEmitter) sdkLogEmitterProvider.logEmitterBuilder(null).build())
|
((SdkLogEmitter) sdkLogEmitterProvider.logEmitterBuilder(null).build())
|
||||||
.getInstrumentationLibraryInfo()
|
.getInstrumentationScopeInfo()
|
||||||
.getName())
|
.getName())
|
||||||
.isEqualTo(SdkLogEmitterProvider.DEFAULT_EMITTER_NAME);
|
.isEqualTo(SdkLogEmitterProvider.DEFAULT_EMITTER_NAME);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
((SdkLogEmitter) sdkLogEmitterProvider.logEmitterBuilder("").build())
|
((SdkLogEmitter) sdkLogEmitterProvider.logEmitterBuilder("").build())
|
||||||
.getInstrumentationLibraryInfo()
|
.getInstrumentationScopeInfo()
|
||||||
.getName())
|
.getName())
|
||||||
.isEqualTo(SdkLogEmitterProvider.DEFAULT_EMITTER_NAME);
|
.isEqualTo(SdkLogEmitterProvider.DEFAULT_EMITTER_NAME);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.api.internal.StringUtils;
|
import io.opentelemetry.api.internal.StringUtils;
|
||||||
import io.opentelemetry.sdk.common.Clock;
|
import io.opentelemetry.sdk.common.Clock;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
import io.opentelemetry.sdk.logs.data.LogData;
|
import io.opentelemetry.sdk.logs.data.LogData;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -30,7 +30,7 @@ class SdkLogEmitterTest {
|
||||||
@Test
|
@Test
|
||||||
void logBuilder() {
|
void logBuilder() {
|
||||||
LogEmitterSharedState state = mock(LogEmitterSharedState.class);
|
LogEmitterSharedState state = mock(LogEmitterSharedState.class);
|
||||||
InstrumentationLibraryInfo info = InstrumentationLibraryInfo.create("foo", "bar");
|
InstrumentationScopeInfo info = InstrumentationScopeInfo.create("foo");
|
||||||
AtomicReference<LogData> seenLog = new AtomicReference<>();
|
AtomicReference<LogData> seenLog = new AtomicReference<>();
|
||||||
LogProcessor logProcessor = seenLog::set;
|
LogProcessor logProcessor = seenLog::set;
|
||||||
Clock clock = mock(Clock.class);
|
Clock clock = mock(Clock.class);
|
||||||
|
|
|
@ -10,7 +10,8 @@ import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
|
||||||
import io.opentelemetry.api.metrics.LongCounterBuilder;
|
import io.opentelemetry.api.metrics.LongCounterBuilder;
|
||||||
import io.opentelemetry.api.metrics.LongUpDownCounterBuilder;
|
import io.opentelemetry.api.metrics.LongUpDownCounterBuilder;
|
||||||
import io.opentelemetry.api.metrics.Meter;
|
import io.opentelemetry.api.metrics.Meter;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
|
import io.opentelemetry.sdk.internal.InstrumentationScopeUtil;
|
||||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||||
import io.opentelemetry.sdk.metrics.internal.export.CollectionInfo;
|
import io.opentelemetry.sdk.metrics.internal.export.CollectionInfo;
|
||||||
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
|
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
|
||||||
|
@ -19,19 +20,23 @@ import java.util.Collection;
|
||||||
|
|
||||||
/** {@link SdkMeter} is SDK implementation of {@link Meter}. */
|
/** {@link SdkMeter} is SDK implementation of {@link Meter}. */
|
||||||
final class SdkMeter implements Meter {
|
final class SdkMeter implements Meter {
|
||||||
|
private final InstrumentationScopeInfo instrumentationScopeInfo;
|
||||||
private final MeterProviderSharedState meterProviderSharedState;
|
private final MeterProviderSharedState meterProviderSharedState;
|
||||||
private final MeterSharedState meterSharedState;
|
private final MeterSharedState meterSharedState;
|
||||||
|
|
||||||
SdkMeter(
|
SdkMeter(
|
||||||
MeterProviderSharedState meterProviderSharedState,
|
MeterProviderSharedState meterProviderSharedState,
|
||||||
InstrumentationLibraryInfo instrumentationLibraryInfo) {
|
InstrumentationScopeInfo instrumentationScopeInfo) {
|
||||||
|
this.instrumentationScopeInfo = instrumentationScopeInfo;
|
||||||
this.meterProviderSharedState = meterProviderSharedState;
|
this.meterProviderSharedState = meterProviderSharedState;
|
||||||
this.meterSharedState = MeterSharedState.create(instrumentationLibraryInfo);
|
this.meterSharedState =
|
||||||
|
MeterSharedState.create(
|
||||||
|
InstrumentationScopeUtil.toInstrumentationLibraryInfo(instrumentationScopeInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only used in testing....
|
// Visible for testing
|
||||||
InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
|
InstrumentationScopeInfo getInstrumentationScopeInfo() {
|
||||||
return meterSharedState.getInstrumentationLibraryInfo();
|
return instrumentationScopeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Collects all the metric recordings that changed since the previous call. */
|
/** Collects all the metric recordings that changed since the previous call. */
|
||||||
|
|
|
@ -13,13 +13,13 @@ import javax.annotation.Nullable;
|
||||||
class SdkMeterBuilder implements MeterBuilder {
|
class SdkMeterBuilder implements MeterBuilder {
|
||||||
|
|
||||||
private final ComponentRegistry<SdkMeter> registry;
|
private final ComponentRegistry<SdkMeter> registry;
|
||||||
private final String instrumentationName;
|
private final String instrumentationScopeName;
|
||||||
@Nullable private String instrumentationVersion;
|
@Nullable private String instrumentationScopeVersion;
|
||||||
@Nullable private String schemaUrl;
|
@Nullable private String schemaUrl;
|
||||||
|
|
||||||
SdkMeterBuilder(ComponentRegistry<SdkMeter> registry, String instrumentationName) {
|
SdkMeterBuilder(ComponentRegistry<SdkMeter> registry, String instrumentationScopeName) {
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
this.instrumentationName = instrumentationName;
|
this.instrumentationScopeName = instrumentationScopeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,13 +29,13 @@ class SdkMeterBuilder implements MeterBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MeterBuilder setInstrumentationVersion(String instrumentationVersion) {
|
public MeterBuilder setInstrumentationVersion(String instrumentationScopeVersion) {
|
||||||
this.instrumentationVersion = instrumentationVersion;
|
this.instrumentationScopeVersion = instrumentationScopeVersion;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Meter build() {
|
public Meter build() {
|
||||||
return registry.get(instrumentationName, instrumentationVersion, schemaUrl);
|
return registry.get(instrumentationScopeName, instrumentationScopeVersion, schemaUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,15 +88,15 @@ public final class SdkMeterProvider implements MeterProvider, Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MeterBuilder meterBuilder(String instrumentationName) {
|
public MeterBuilder meterBuilder(String instrumentationScopeName) {
|
||||||
if (collectionInfoMap.isEmpty()) {
|
if (collectionInfoMap.isEmpty()) {
|
||||||
return MeterProvider.noop().meterBuilder(instrumentationName);
|
return MeterProvider.noop().meterBuilder(instrumentationScopeName);
|
||||||
}
|
}
|
||||||
if (instrumentationName == null || instrumentationName.isEmpty()) {
|
if (instrumentationScopeName == null || instrumentationScopeName.isEmpty()) {
|
||||||
LOGGER.fine("Meter requested without instrumentation name.");
|
LOGGER.fine("Meter requested without instrumentation scope name.");
|
||||||
instrumentationName = DEFAULT_METER_NAME;
|
instrumentationScopeName = DEFAULT_METER_NAME;
|
||||||
}
|
}
|
||||||
return new SdkMeterBuilder(registry, instrumentationName);
|
return new SdkMeterBuilder(registry, instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.metrics;
|
package io.opentelemetry.sdk.metrics;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.internal.InstrumentationScopeUtil.toInstrumentationLibraryInfo;
|
||||||
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
|
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.metrics.LongCounter;
|
import io.opentelemetry.api.metrics.LongCounter;
|
||||||
import io.opentelemetry.api.metrics.Meter;
|
import io.opentelemetry.api.metrics.Meter;
|
||||||
import io.opentelemetry.sdk.common.Clock;
|
import io.opentelemetry.sdk.common.Clock;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
|
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||||
import io.opentelemetry.sdk.testing.time.TestClock;
|
import io.opentelemetry.sdk.testing.time.TestClock;
|
||||||
|
@ -89,9 +90,9 @@ class SdkMeterRegistryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void propagatesInstrumentationLibraryInfoToMeter() {
|
void propagatesInstrumentationScopeInfoToMeter() {
|
||||||
InstrumentationLibraryInfo expected =
|
InstrumentationScopeInfo expected =
|
||||||
InstrumentationLibraryInfo.create("theName", "theVersion", "http://theschema");
|
InstrumentationScopeInfo.create("theName", "theVersion", "http://theschema");
|
||||||
SdkMeter meter =
|
SdkMeter meter =
|
||||||
(SdkMeter)
|
(SdkMeter)
|
||||||
meterProvider
|
meterProvider
|
||||||
|
@ -99,11 +100,10 @@ class SdkMeterRegistryTest {
|
||||||
.setInstrumentationVersion(expected.getVersion())
|
.setInstrumentationVersion(expected.getVersion())
|
||||||
.setSchemaUrl(expected.getSchemaUrl())
|
.setSchemaUrl(expected.getSchemaUrl())
|
||||||
.build();
|
.build();
|
||||||
assertThat(meter.getInstrumentationLibraryInfo()).isEqualTo(expected);
|
assertThat(meter.getInstrumentationScopeInfo()).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
void metricProducer_GetAllMetrics() {
|
void metricProducer_GetAllMetrics() {
|
||||||
Meter sdkMeter1 = meterProvider.get("io.opentelemetry.sdk.metrics.MeterSdkRegistryTest_1");
|
Meter sdkMeter1 = meterProvider.get("io.opentelemetry.sdk.metrics.MeterSdkRegistryTest_1");
|
||||||
LongCounter longCounter1 = sdkMeter1.counterBuilder("testLongCounter").build();
|
LongCounter longCounter1 = sdkMeter1.counterBuilder("testLongCounter").build();
|
||||||
|
@ -127,31 +127,31 @@ class SdkMeterRegistryTest {
|
||||||
.hasValue(10)
|
.hasValue(10)
|
||||||
.hasStartEpochNanos(testClock.now())
|
.hasStartEpochNanos(testClock.now())
|
||||||
.hasEpochNanos(testClock.now())))
|
.hasEpochNanos(testClock.now())))
|
||||||
.extracting(metric -> metric.getInstrumentationLibraryInfo())
|
.extracting(MetricData::getInstrumentationLibraryInfo)
|
||||||
.containsExactlyInAnyOrder(
|
.containsExactlyInAnyOrder(
|
||||||
((SdkMeter) sdkMeter1).getInstrumentationLibraryInfo(),
|
toInstrumentationLibraryInfo(((SdkMeter) sdkMeter1).getInstrumentationScopeInfo()),
|
||||||
((SdkMeter) sdkMeter2).getInstrumentationLibraryInfo());
|
toInstrumentationLibraryInfo(((SdkMeter) sdkMeter2).getInstrumentationScopeInfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void suppliesDefaultMeterForNullName() {
|
void suppliesDefaultMeterForNullName() {
|
||||||
SdkMeter meter = (SdkMeter) meterProvider.get(null);
|
SdkMeter meter = (SdkMeter) meterProvider.get(null);
|
||||||
assertThat(meter.getInstrumentationLibraryInfo().getName())
|
assertThat(meter.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
||||||
|
|
||||||
meter = (SdkMeter) meterProvider.meterBuilder(null).build();
|
meter = (SdkMeter) meterProvider.meterBuilder(null).build();
|
||||||
assertThat(meter.getInstrumentationLibraryInfo().getName())
|
assertThat(meter.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void suppliesDefaultMeterForEmptyName() {
|
void suppliesDefaultMeterForEmptyName() {
|
||||||
SdkMeter meter = (SdkMeter) meterProvider.get("");
|
SdkMeter meter = (SdkMeter) meterProvider.get("");
|
||||||
assertThat(meter.getInstrumentationLibraryInfo().getName())
|
assertThat(meter.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
||||||
|
|
||||||
meter = (SdkMeter) meterProvider.meterBuilder("").build();
|
meter = (SdkMeter) meterProvider.meterBuilder("").build();
|
||||||
assertThat(meter.getInstrumentationLibraryInfo().getName())
|
assertThat(meter.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
.isEqualTo(SdkMeterProvider.DEFAULT_METER_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,17 +9,22 @@ import io.opentelemetry.api.trace.SpanBuilder;
|
||||||
import io.opentelemetry.api.trace.Tracer;
|
import io.opentelemetry.api.trace.Tracer;
|
||||||
import io.opentelemetry.api.trace.TracerProvider;
|
import io.opentelemetry.api.trace.TracerProvider;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
|
import io.opentelemetry.sdk.internal.InstrumentationScopeUtil;
|
||||||
|
|
||||||
/** {@link SdkTracer} is SDK implementation of {@link Tracer}. */
|
/** {@link SdkTracer} is SDK implementation of {@link Tracer}. */
|
||||||
final class SdkTracer implements Tracer {
|
final class SdkTracer implements Tracer {
|
||||||
static final String FALLBACK_SPAN_NAME = "<unspecified span name>";
|
static final String FALLBACK_SPAN_NAME = "<unspecified span name>";
|
||||||
|
|
||||||
private final TracerSharedState sharedState;
|
private final TracerSharedState sharedState;
|
||||||
|
private final InstrumentationScopeInfo instrumentationScopeInfo;
|
||||||
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
||||||
|
|
||||||
SdkTracer(TracerSharedState sharedState, InstrumentationLibraryInfo instrumentationLibraryInfo) {
|
SdkTracer(TracerSharedState sharedState, InstrumentationScopeInfo instrumentationScopeInfo) {
|
||||||
this.sharedState = sharedState;
|
this.sharedState = sharedState;
|
||||||
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
|
this.instrumentationScopeInfo = instrumentationScopeInfo;
|
||||||
|
this.instrumentationLibraryInfo =
|
||||||
|
InstrumentationScopeUtil.toInstrumentationLibraryInfo(instrumentationScopeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,19 +33,15 @@ final class SdkTracer implements Tracer {
|
||||||
spanName = FALLBACK_SPAN_NAME;
|
spanName = FALLBACK_SPAN_NAME;
|
||||||
}
|
}
|
||||||
if (sharedState.hasBeenShutdown()) {
|
if (sharedState.hasBeenShutdown()) {
|
||||||
Tracer tracer = TracerProvider.noop().get(instrumentationLibraryInfo.getName());
|
Tracer tracer = TracerProvider.noop().get(instrumentationScopeInfo.getName());
|
||||||
return tracer.spanBuilder(spanName);
|
return tracer.spanBuilder(spanName);
|
||||||
}
|
}
|
||||||
return new SdkSpanBuilder(
|
return new SdkSpanBuilder(
|
||||||
spanName, instrumentationLibraryInfo, sharedState, sharedState.getSpanLimits());
|
spanName, instrumentationLibraryInfo, sharedState, sharedState.getSpanLimits());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Visible for testing
|
||||||
* Returns the instrumentation library specified when creating the tracer.
|
InstrumentationScopeInfo getInstrumentationScopeInfo() {
|
||||||
*
|
return instrumentationScopeInfo;
|
||||||
* @return an instance of {@link InstrumentationLibraryInfo}
|
|
||||||
*/
|
|
||||||
InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
|
|
||||||
return instrumentationLibraryInfo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,13 @@ import javax.annotation.Nullable;
|
||||||
class SdkTracerBuilder implements TracerBuilder {
|
class SdkTracerBuilder implements TracerBuilder {
|
||||||
|
|
||||||
private final ComponentRegistry<SdkTracer> registry;
|
private final ComponentRegistry<SdkTracer> registry;
|
||||||
private final String instrumentationName;
|
private final String instrumentationScopeName;
|
||||||
@Nullable private String instrumentationVersion;
|
@Nullable private String instrumentationScopeVersion;
|
||||||
@Nullable private String schemaUrl;
|
@Nullable private String schemaUrl;
|
||||||
|
|
||||||
SdkTracerBuilder(ComponentRegistry<SdkTracer> registry, String instrumentationName) {
|
SdkTracerBuilder(ComponentRegistry<SdkTracer> registry, String instrumentationScopeName) {
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
this.instrumentationName = instrumentationName;
|
this.instrumentationScopeName = instrumentationScopeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,13 +29,13 @@ class SdkTracerBuilder implements TracerBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TracerBuilder setInstrumentationVersion(String instrumentationVersion) {
|
public TracerBuilder setInstrumentationVersion(String instrumentationScopeVersion) {
|
||||||
this.instrumentationVersion = instrumentationVersion;
|
this.instrumentationScopeVersion = instrumentationScopeVersion;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer build() {
|
public Tracer build() {
|
||||||
return registry.get(instrumentationName, instrumentationVersion, schemaUrl);
|
return registry.get(instrumentationScopeName, instrumentationScopeVersion, schemaUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,29 +49,29 @@ public final class SdkTracerProvider implements TracerProvider, Closeable {
|
||||||
clock, idsGenerator, resource, spanLimitsSupplier, sampler, spanProcessors);
|
clock, idsGenerator, resource, spanLimitsSupplier, sampler, spanProcessors);
|
||||||
this.tracerSdkComponentRegistry =
|
this.tracerSdkComponentRegistry =
|
||||||
new ComponentRegistry<>(
|
new ComponentRegistry<>(
|
||||||
instrumentationLibraryInfo -> new SdkTracer(sharedState, instrumentationLibraryInfo));
|
instrumentationScopeInfo -> new SdkTracer(sharedState, instrumentationScopeInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName) {
|
public Tracer get(String instrumentationScopeName) {
|
||||||
return tracerBuilder(instrumentationName).build();
|
return tracerBuilder(instrumentationScopeName).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tracer get(String instrumentationName, String instrumentationVersion) {
|
public Tracer get(String instrumentationScopeName, String instrumentationScopeVersion) {
|
||||||
return tracerBuilder(instrumentationName)
|
return tracerBuilder(instrumentationScopeName)
|
||||||
.setInstrumentationVersion(instrumentationVersion)
|
.setInstrumentationVersion(instrumentationScopeVersion)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TracerBuilder tracerBuilder(@Nullable String instrumentationName) {
|
public TracerBuilder tracerBuilder(@Nullable String instrumentationScopeName) {
|
||||||
// Per the spec, both null and empty are "invalid" and a default value should be used.
|
// Per the spec, both null and empty are "invalid" and a default value should be used.
|
||||||
if (instrumentationName == null || instrumentationName.isEmpty()) {
|
if (instrumentationScopeName == null || instrumentationScopeName.isEmpty()) {
|
||||||
logger.fine("Tracer requested without instrumentation name.");
|
logger.fine("Tracer requested without instrumentation scope name.");
|
||||||
instrumentationName = DEFAULT_TRACER_NAME;
|
instrumentationScopeName = DEFAULT_TRACER_NAME;
|
||||||
}
|
}
|
||||||
return new SdkTracerBuilder(tracerSdkComponentRegistry, instrumentationName);
|
return new SdkTracerBuilder(tracerSdkComponentRegistry, instrumentationScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link SpanLimits} that are currently applied to created spans. */
|
/** Returns the {@link SpanLimits} that are currently applied to created spans. */
|
||||||
|
|
|
@ -16,7 +16,7 @@ import io.opentelemetry.api.trace.Tracer;
|
||||||
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
|
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
|
||||||
import io.opentelemetry.sdk.common.Clock;
|
import io.opentelemetry.sdk.common.Clock;
|
||||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
||||||
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
|
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
|
||||||
|
@ -169,16 +169,16 @@ class SdkTracerProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void propagatesInstrumentationLibraryInfoToTracer() {
|
void propagatesInstrumentationScopeInfoToTracer() {
|
||||||
InstrumentationLibraryInfo expected =
|
InstrumentationScopeInfo expected =
|
||||||
InstrumentationLibraryInfo.create("theName", "theVersion", "http://url");
|
InstrumentationScopeInfo.create("theName", "theVersion", "http://url");
|
||||||
Tracer tracer =
|
Tracer tracer =
|
||||||
tracerFactory
|
tracerFactory
|
||||||
.tracerBuilder(expected.getName())
|
.tracerBuilder(expected.getName())
|
||||||
.setInstrumentationVersion(expected.getVersion())
|
.setInstrumentationVersion(expected.getVersion())
|
||||||
.setSchemaUrl(expected.getSchemaUrl())
|
.setSchemaUrl(expected.getSchemaUrl())
|
||||||
.build();
|
.build();
|
||||||
assertThat(((SdkTracer) tracer).getInstrumentationLibraryInfo()).isEqualTo(expected);
|
assertThat(((SdkTracer) tracer).getInstrumentationScopeInfo()).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -228,22 +228,22 @@ class SdkTracerProviderTest {
|
||||||
@Test
|
@Test
|
||||||
void suppliesDefaultTracerForNullName() {
|
void suppliesDefaultTracerForNullName() {
|
||||||
SdkTracer tracer = (SdkTracer) tracerFactory.get(null);
|
SdkTracer tracer = (SdkTracer) tracerFactory.get(null);
|
||||||
assertThat(tracer.getInstrumentationLibraryInfo().getName())
|
assertThat(tracer.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
||||||
|
|
||||||
tracer = (SdkTracer) tracerFactory.get(null, null);
|
tracer = (SdkTracer) tracerFactory.get(null, null);
|
||||||
assertThat(tracer.getInstrumentationLibraryInfo().getName())
|
assertThat(tracer.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void suppliesDefaultTracerForEmptyName() {
|
void suppliesDefaultTracerForEmptyName() {
|
||||||
SdkTracer tracer = (SdkTracer) tracerFactory.get("");
|
SdkTracer tracer = (SdkTracer) tracerFactory.get("");
|
||||||
assertThat(tracer.getInstrumentationLibraryInfo().getName())
|
assertThat(tracer.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
||||||
|
|
||||||
tracer = (SdkTracer) tracerFactory.get("", "");
|
tracer = (SdkTracer) tracerFactory.get("", "");
|
||||||
assertThat(tracer.getInstrumentationLibraryInfo().getName())
|
assertThat(tracer.getInstrumentationScopeInfo().getName())
|
||||||
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
.isEqualTo(SdkTracerProvider.DEFAULT_TRACER_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
|
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||||
import io.opentelemetry.sdk.trace.StressTestRunner.OperationUpdater;
|
import io.opentelemetry.sdk.trace.StressTestRunner.OperationUpdater;
|
||||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||||
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
|
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
|
||||||
|
@ -23,18 +24,18 @@ import org.junit.jupiter.api.Test;
|
||||||
class SdkTracerTest {
|
class SdkTracerTest {
|
||||||
|
|
||||||
private static final String SPAN_NAME = "span_name";
|
private static final String SPAN_NAME = "span_name";
|
||||||
private static final String INSTRUMENTATION_LIBRARY_NAME =
|
private static final String INSTRUMENTATION_SCOPE_NAME =
|
||||||
"io.opentelemetry.sdk.trace.TracerSdkTest";
|
"io.opentelemetry.sdk.trace.TracerSdkTest";
|
||||||
private static final String INSTRUMENTATION_LIBRARY_VERSION = "0.2.0";
|
private static final String INSTRUMENTATION_SCOPE_VERSION = "0.2.0";
|
||||||
private static final InstrumentationLibraryInfo instrumentationLibraryInfo =
|
private static final InstrumentationScopeInfo instrumentationScopeInfo =
|
||||||
InstrumentationLibraryInfo.create(
|
InstrumentationScopeInfo.create(
|
||||||
INSTRUMENTATION_LIBRARY_NAME, INSTRUMENTATION_LIBRARY_VERSION, "http://schemaurl");
|
INSTRUMENTATION_SCOPE_NAME, INSTRUMENTATION_SCOPE_VERSION, "http://schemaurl");
|
||||||
private final SdkTracer tracer =
|
private final SdkTracer tracer =
|
||||||
(SdkTracer)
|
(SdkTracer)
|
||||||
SdkTracerProvider.builder()
|
SdkTracerProvider.builder()
|
||||||
.build()
|
.build()
|
||||||
.tracerBuilder(INSTRUMENTATION_LIBRARY_NAME)
|
.tracerBuilder(INSTRUMENTATION_SCOPE_NAME)
|
||||||
.setInstrumentationVersion(INSTRUMENTATION_LIBRARY_VERSION)
|
.setInstrumentationVersion(INSTRUMENTATION_SCOPE_VERSION)
|
||||||
.setSchemaUrl("http://schemaurl")
|
.setSchemaUrl("http://schemaurl")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -44,14 +45,19 @@ class SdkTracerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getInstrumentationLibraryInfo() {
|
void getInstrumentationScopeInfo() {
|
||||||
assertThat(tracer.getInstrumentationLibraryInfo()).isEqualTo(instrumentationLibraryInfo);
|
assertThat(tracer.getInstrumentationScopeInfo()).isEqualTo(instrumentationScopeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void propagatesInstrumentationLibraryInfoToSpan() {
|
void propagatesInstrumentationScopeInfoToSpan() {
|
||||||
ReadableSpan readableSpan = (ReadableSpan) tracer.spanBuilder("spanName").startSpan();
|
ReadableSpan readableSpan = (ReadableSpan) tracer.spanBuilder("spanName").startSpan();
|
||||||
assertThat(readableSpan.getInstrumentationLibraryInfo()).isEqualTo(instrumentationLibraryInfo);
|
assertThat(readableSpan.getInstrumentationLibraryInfo())
|
||||||
|
.isEqualTo(
|
||||||
|
InstrumentationLibraryInfo.create(
|
||||||
|
instrumentationScopeInfo.getName(),
|
||||||
|
instrumentationScopeInfo.getVersion(),
|
||||||
|
instrumentationScopeInfo.getSchemaUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -70,7 +76,7 @@ class SdkTracerTest {
|
||||||
SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build();
|
SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build();
|
||||||
SdkTracer tracer =
|
SdkTracer tracer =
|
||||||
(SdkTracer)
|
(SdkTracer)
|
||||||
sdkTracerProvider.get(INSTRUMENTATION_LIBRARY_NAME, INSTRUMENTATION_LIBRARY_VERSION);
|
sdkTracerProvider.get(INSTRUMENTATION_SCOPE_NAME, INSTRUMENTATION_SCOPE_VERSION);
|
||||||
|
|
||||||
StressTestRunner.Builder stressTestBuilder =
|
StressTestRunner.Builder stressTestBuilder =
|
||||||
StressTestRunner.builder().setTracer(tracer).setSpanProcessor(spanProcessor);
|
StressTestRunner.builder().setTracer(tracer).setSpanProcessor(spanProcessor);
|
||||||
|
@ -93,7 +99,7 @@ class SdkTracerTest {
|
||||||
SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build();
|
SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build();
|
||||||
SdkTracer tracer =
|
SdkTracer tracer =
|
||||||
(SdkTracer)
|
(SdkTracer)
|
||||||
sdkTracerProvider.get(INSTRUMENTATION_LIBRARY_NAME, INSTRUMENTATION_LIBRARY_VERSION);
|
sdkTracerProvider.get(INSTRUMENTATION_SCOPE_NAME, INSTRUMENTATION_SCOPE_VERSION);
|
||||||
|
|
||||||
StressTestRunner.Builder stressTestBuilder =
|
StressTestRunner.Builder stressTestBuilder =
|
||||||
StressTestRunner.builder().setTracer(tracer).setSpanProcessor(spanProcessor);
|
StressTestRunner.builder().setTracer(tracer).setSpanProcessor(spanProcessor);
|
||||||
|
|
Loading…
Reference in New Issue