use of io.opentelemetry.sdk.trace.SpanProcessor in project opentelemetry-java by open-telemetry.
the class SimpleSpanProcessorTest method onEndSync_OnlySampled_SampledSpan.
@Test
void onEndSync_OnlySampled_SampledSpan() {
when(readableSpan.getSpanContext()).thenReturn(SAMPLED_SPAN_CONTEXT);
when(readableSpan.toSpanData()).thenReturn(TestUtils.makeBasicSpan()).thenThrow(new RuntimeException());
SpanProcessor simpleSpanProcessor = SimpleSpanProcessor.create(spanExporter);
simpleSpanProcessor.onEnd(readableSpan);
verify(spanExporter).export(Collections.singletonList(TestUtils.makeBasicSpan()));
}
use of io.opentelemetry.sdk.trace.SpanProcessor in project opentelemetry-java by open-telemetry.
the class TracerProviderConfiguration method configureSpanProcessors.
static List<SpanProcessor> configureSpanProcessors(ConfigProperties config, Map<String, SpanExporter> exportersByName, MeterProvider meterProvider) {
Map<String, SpanExporter> exportersByNameCopy = new HashMap<>(exportersByName);
List<SpanProcessor> spanProcessors = new ArrayList<>();
SpanExporter exporter = exportersByNameCopy.remove("logging");
if (exporter != null) {
spanProcessors.add(SimpleSpanProcessor.create(exporter));
}
if (!exportersByNameCopy.isEmpty()) {
SpanExporter compositeSpanExporter = SpanExporter.composite(exportersByNameCopy.values());
spanProcessors.add(configureBatchSpanProcessor(config, compositeSpanExporter, meterProvider));
}
return spanProcessors;
}
use of io.opentelemetry.sdk.trace.SpanProcessor in project opentelemetry-java by open-telemetry.
the class SimpleSpanProcessorTest method onEndSync_OnlySampled_NotSampledSpan.
@Test
void onEndSync_OnlySampled_NotSampledSpan() {
when(readableSpan.getSpanContext()).thenReturn(NOT_SAMPLED_SPAN_CONTEXT);
when(readableSpan.toSpanData()).thenReturn(TestUtils.makeBasicSpan()).thenThrow(new RuntimeException());
SpanProcessor simpleSpanProcessor = SimpleSpanProcessor.create(spanExporter);
simpleSpanProcessor.onEnd(readableSpan);
verifyNoInteractions(spanExporter);
}
use of io.opentelemetry.sdk.trace.SpanProcessor in project honeycomb-opentelemetry-java by honeycombio.
the class OpenTelemetryConfigurationTest method testConfiguration_tracerSettings.
@Test
@SuppressWarnings("unchecked")
public void testConfiguration_tracerSettings() {
Sampler sampler = new DeterministicTraceSampler(5);
OpenTelemetry openTelemetry = OpenTelemetryConfiguration.builder().setSampler(sampler).setApiKey("foobar").setDataset("dataset").addResourceAttribute("str", "str").addResourceAttribute("bool", true).addResourceAttribute("int", 123).addResourceAttribute("str-array", "str1", "str2", "str3").build();
TracerProvider provider = openTelemetry.getTracerProvider();
try {
Method m = provider.getClass().getDeclaredMethod("unobfuscate");
m.setAccessible(true);
SdkTracerProvider sdkProvider = (SdkTracerProvider) m.invoke(provider, (Object[]) null);
// verify sampler
Sampler s = sdkProvider.getSampler();
Assertions.assertEquals(sampler, s);
Field providerField = pluckField(sdkProvider.getClass(), "sharedState");
Object sharedState = providerField.get(sdkProvider);
Field resourceField = pluckField(sharedState.getClass(), "resource");
Resource r = (Resource) resourceField.get(sharedState);
Attributes attrs = r.getAttributes();
// verify resource attributes
Assertions.assertEquals(DistroMetadata.VERSION_VALUE, attrs.get(AttributeKey.stringKey(DistroMetadata.VERSION_FIELD)));
Assertions.assertEquals(DistroMetadata.RUNTIME_VERSION_VALUE, attrs.get(AttributeKey.stringKey(DistroMetadata.RUNTIME_VERSION_FIELD)));
Assertions.assertEquals("str", attrs.get(AttributeKey.stringKey("str")));
Assertions.assertEquals(true, attrs.get(AttributeKey.booleanKey("bool")));
Assertions.assertEquals(123, attrs.get(AttributeKey.longKey("int")));
Assertions.assertEquals(Arrays.asList("str1", "str2", "str3"), attrs.get(AttributeKey.stringArrayKey("str-array")));
Field procesorField = pluckField(sharedState.getClass(), "activeSpanProcessor");
Object sp = procesorField.get(sharedState);
Field allSpanProcessors = pluckField(sp.getClass(), "spanProcessorsAll");
List<SpanProcessor> processors = (List<SpanProcessor>) allSpanProcessors.get(sp);
// verify configured span processors
Assertions.assertInstanceOf(BaggageSpanProcessor.class, processors.get(0));
Assertions.assertInstanceOf(BatchSpanProcessor.class, processors.get(1));
} catch (Exception e) {
Assertions.fail(e);
}
}
use of io.opentelemetry.sdk.trace.SpanProcessor in project incubator-eventmesh by apache.
the class ZipkinTraceService method init.
@Override
public void init() {
// zipkin's config
eventMeshZipkinIP = ZipkinConfiguration.getEventMeshZipkinIP();
eventMeshZipkinPort = ZipkinConfiguration.getEventMeshZipkinPort();
// exporter's config
eventMeshTraceExportInterval = ExporterConfiguration.getEventMeshTraceExportInterval();
eventMeshTraceExportTimeout = ExporterConfiguration.getEventMeshTraceExportTimeout();
eventMeshTraceMaxExportSize = ExporterConfiguration.getEventMeshTraceMaxExportSize();
eventMeshTraceMaxQueueSize = ExporterConfiguration.getEventMeshTraceMaxQueueSize();
String httpUrl = String.format("http://%s:%s", eventMeshZipkinIP, eventMeshZipkinPort);
ZipkinSpanExporter zipkinExporter = ZipkinSpanExporter.builder().setEndpoint(httpUrl + ENDPOINT_V2_SPANS).build();
SpanProcessor spanProcessor = BatchSpanProcessor.builder(zipkinExporter).setScheduleDelay(eventMeshTraceExportInterval, TimeUnit.SECONDS).setExporterTimeout(eventMeshTraceExportTimeout, TimeUnit.SECONDS).setMaxExportBatchSize(eventMeshTraceMaxExportSize).setMaxQueueSize(eventMeshTraceMaxQueueSize).build();
// set the trace service's name
Resource serviceNameResource = Resource.create(Attributes.of(stringKey("service.name"), serviceName));
sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(spanProcessor).setResource(Resource.getDefault().merge(serviceNameResource)).build();
openTelemetry = OpenTelemetrySdk.builder().setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())).setTracerProvider(sdkTracerProvider).build();
Runtime.getRuntime().addShutdownHook(new Thread(sdkTracerProvider::close));
}
Aggregations