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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations