Search in sources :

Example 1 with InstrumentationScopeInfo

use of io.opentelemetry.sdk.common.InstrumentationScopeInfo in project opentelemetry-java by open-telemetry.

the class SdkTracerProviderTest method propagatesInstrumentationScopeInfoToTracer.

@Test
void propagatesInstrumentationScopeInfoToTracer() {
    InstrumentationScopeInfo expected = InstrumentationScopeInfo.create("theName", "theVersion", "http://url");
    Tracer tracer = tracerFactory.tracerBuilder(expected.getName()).setInstrumentationVersion(expected.getVersion()).setSchemaUrl(expected.getSchemaUrl()).build();
    assertThat(((SdkTracer) tracer).getInstrumentationScopeInfo()).isEqualTo(expected);
}
Also used : InstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo) Tracer(io.opentelemetry.api.trace.Tracer) Test(org.junit.jupiter.api.Test)

Example 2 with InstrumentationScopeInfo

use of io.opentelemetry.sdk.common.InstrumentationScopeInfo in project opentelemetry-java by open-telemetry.

the class ComponentRegistry method get.

/**
 * 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.
 *
 * @param instrumentationScopeName the name of the instrumentation scope.
 * @param instrumentationScopeVersion the version of the instrumentation scope.
 * @param schemaUrl the URL of the OpenTelemetry schema used by the instrumentation scope.
 * @return the registered value associated with this name and version.
 * @since 1.4.0
 */
public V get(String instrumentationScopeName, @Nullable String instrumentationScopeVersion, @Nullable String schemaUrl) {
    InstrumentationScopeInfo instrumentationScopeInfo = InstrumentationScopeInfo.create(instrumentationScopeName, instrumentationScopeVersion, schemaUrl);
    // Optimistic lookup, before creating the new component.
    V component = registry.get(instrumentationScopeInfo);
    if (component != null) {
        return component;
    }
    V newComponent = factory.apply(instrumentationScopeInfo);
    V oldComponent = registry.putIfAbsent(instrumentationScopeInfo, newComponent);
    return oldComponent != null ? oldComponent : newComponent;
}
Also used : InstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo)

Example 3 with InstrumentationScopeInfo

use of io.opentelemetry.sdk.common.InstrumentationScopeInfo in project opentelemetry-java by open-telemetry.

the class SdkMeterRegistryTest method propagatesInstrumentationScopeInfoToMeter.

@Test
void propagatesInstrumentationScopeInfoToMeter() {
    InstrumentationScopeInfo expected = InstrumentationScopeInfo.create("theName", "theVersion", "http://theschema");
    SdkMeter meter = (SdkMeter) meterProvider.meterBuilder(expected.getName()).setInstrumentationVersion(expected.getVersion()).setSchemaUrl(expected.getSchemaUrl()).build();
    assertThat(meter.getInstrumentationScopeInfo()).isEqualTo(expected);
}
Also used : InstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo) Test(org.junit.jupiter.api.Test)

Example 4 with InstrumentationScopeInfo

use of io.opentelemetry.sdk.common.InstrumentationScopeInfo in project opentelemetry-java by open-telemetry.

the class SdkLogEmitterProviderTest method logEmitterBuilder_PropagatesToEmitter.

@Test
void logEmitterBuilder_PropagatesToEmitter() {
    InstrumentationScopeInfo expected = InstrumentationScopeInfo.create("test", "version", "http://url");
    assertThat(((SdkLogEmitter) sdkLogEmitterProvider.logEmitterBuilder("test").setInstrumentationVersion("version").setSchemaUrl("http://url").build()).getInstrumentationScopeInfo()).isEqualTo(expected);
}
Also used : InstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo) Test(org.junit.jupiter.api.Test)

Example 5 with InstrumentationScopeInfo

use of io.opentelemetry.sdk.common.InstrumentationScopeInfo in project opentelemetry-java by open-telemetry.

the class SdkLogEmitterTest method logBuilder.

@Test
void logBuilder() {
    LogEmitterSharedState state = mock(LogEmitterSharedState.class);
    InstrumentationScopeInfo info = InstrumentationScopeInfo.create("foo");
    AtomicReference<LogData> seenLog = new AtomicReference<>();
    LogProcessor logProcessor = seenLog::set;
    Clock clock = mock(Clock.class);
    when(clock.now()).thenReturn(5L);
    when(state.getResource()).thenReturn(Resource.getDefault());
    when(state.getLogProcessor()).thenReturn(logProcessor);
    when(state.getClock()).thenReturn(clock);
    SdkLogEmitter emitter = new SdkLogEmitter(state, info);
    LogBuilder logBuilder = emitter.logBuilder();
    logBuilder.setBody("foo");
    // Have to test through the builder
    logBuilder.emit();
    assertThat(seenLog.get()).hasBody("foo").hasEpochNanos(5);
}
Also used : InstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo) LogData(io.opentelemetry.sdk.logs.data.LogData) AtomicReference(java.util.concurrent.atomic.AtomicReference) Clock(io.opentelemetry.sdk.common.Clock) Test(org.junit.jupiter.api.Test)

Aggregations

InstrumentationScopeInfo (io.opentelemetry.sdk.common.InstrumentationScopeInfo)5 Test (org.junit.jupiter.api.Test)4 Tracer (io.opentelemetry.api.trace.Tracer)1 Clock (io.opentelemetry.sdk.common.Clock)1 LogData (io.opentelemetry.sdk.logs.data.LogData)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1