Search in sources :

Example 1 with BatchingLogsProcessor

use of com.splunk.opentelemetry.logs.BatchingLogsProcessor in project splunk-otel-java by signalfx.

the class JfrActivator method activateJfrAndRunForever.

private void activateJfrAndRunForever(Config config, Resource resource) {
    // can't be null, default value is set in Configuration.getProperties
    Duration recordingDuration = config.getDuration(CONFIG_KEY_RECORDING_DURATION, null);
    Path outputDir = Paths.get(config.getString(CONFIG_KEY_PROFILER_DIRECTORY));
    RecordingFileNamingConvention namingConvention = new RecordingFileNamingConvention(outputDir);
    RecordingEscapeHatch recordingEscapeHatch = RecordingEscapeHatch.builder().namingConvention(namingConvention).configKeepsFilesOnDisk(keepFiles(config)).recordingDuration(recordingDuration).build();
    Map<String, String> jfrSettings = buildJfrSettings(config);
    RecordedEventStream.Factory recordedEventStreamFactory = () -> new BasicJfrRecordingFile(JFR.instance);
    SpanContextualizer spanContextualizer = new SpanContextualizer();
    EventPeriods periods = new EventPeriods(jfrSettings::get);
    LogDataCommonAttributes commonAttributes = new LogDataCommonAttributes(periods);
    LogExporter logsExporter = LogExporterBuilder.fromConfig(config);
    ScheduledExecutorService exportExecutorService = HelpfulExecutors.newSingleThreadedScheduledExecutor("Batched Logs Exporter");
    BatchingLogsProcessor batchingLogsProcessor = BatchingLogsProcessor.builder().maxTimeBetweenBatches(MAX_TIME_BETWEEN_BATCHES).maxBatchSize(MAX_BATCH_SIZE).batchAction(logsExporter).executorService(exportExecutorService).build();
    batchingLogsProcessor.start();
    LogDataCreator logDataCreator = new LogDataCreator(commonAttributes, resource);
    StackToSpanLinkageProcessor processor = new StackToSpanLinkageProcessor(logDataCreator, batchingLogsProcessor);
    ThreadDumpProcessor threadDumpProcessor = buildThreadDumpProcessor(spanContextualizer, processor, buildStackTraceFilter(config), config);
    TLABProcessor tlabProcessor = TLABProcessor.builder(config).logProcessor(batchingLogsProcessor).commonAttributes(commonAttributes).resource(resource).spanContextualizer(spanContextualizer).build();
    EventProcessingChain eventProcessingChain = new EventProcessingChain(spanContextualizer, threadDumpProcessor, tlabProcessor);
    Consumer<Path> deleter = buildFileDeleter(config);
    JfrDirCleanup dirCleanup = new JfrDirCleanup(deleter);
    Consumer<Path> onFileFinished = buildOnFileFinished(deleter, dirCleanup);
    JfrPathHandler jfrPathHandler = JfrPathHandler.builder().recordedEventStreamFactory(recordedEventStreamFactory).eventProcessingChain(eventProcessingChain).onFileFinished(onFileFinished).build();
    Consumer<Path> onNewRecording = buildOnNewRecording(jfrPathHandler, dirCleanup);
    JfrRecorder recorder = JfrRecorder.builder().settings(jfrSettings).maxAgeDuration(recordingDuration.multipliedBy(10)).jfr(JFR.instance).namingConvention(namingConvention).onNewRecordingFile(onNewRecording).build();
    RecordingSequencer sequencer = RecordingSequencer.builder().recordingDuration(recordingDuration).recordingEscapeHatch(recordingEscapeHatch).recorder(recorder).build();
    sequencer.start();
    dirCleanup.registerShutdownHook();
}
Also used : EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Path(java.nio.file.Path) BatchingLogsProcessor(com.splunk.opentelemetry.logs.BatchingLogsProcessor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Duration(java.time.Duration) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter)

Example 2 with BatchingLogsProcessor

use of com.splunk.opentelemetry.logs.BatchingLogsProcessor in project splunk-otel-java by signalfx.

the class StackToSpanLinkageProcessorTest method testProcessor.

@Test
void testProcessor() {
    Instant time = Instant.now();
    StackToSpanLinkage linkedSpan = new StackToSpanLinkage(time, "some stack", "event name", SpanLinkage.NONE);
    LogDataCreator logCreator = mock(LogDataCreator.class);
    BatchingLogsProcessor exportProcessor = mock(BatchingLogsProcessor.class);
    LogDataBuilder builder = LogDataBuilder.create(Resource.getDefault(), InstrumentationLibraryInfo.create("test", "1.2.3"));
    LogData log = builder.setBody("the.body").build();
    when(logCreator.apply(linkedSpan)).thenReturn(log);
    StackToSpanLinkageProcessor processor = new StackToSpanLinkageProcessor(logCreator, exportProcessor);
    processor.accept(linkedSpan);
    verify(exportProcessor).emit(log);
}
Also used : StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) BatchingLogsProcessor(com.splunk.opentelemetry.logs.BatchingLogsProcessor) LogData(io.opentelemetry.sdk.logs.data.LogData) Instant(java.time.Instant) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

BatchingLogsProcessor (com.splunk.opentelemetry.logs.BatchingLogsProcessor)2 SpanContextualizer (com.splunk.opentelemetry.profiler.context.SpanContextualizer)1 StackToSpanLinkage (com.splunk.opentelemetry.profiler.context.StackToSpanLinkage)1 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)1 LogData (io.opentelemetry.sdk.logs.data.LogData)1 LogDataBuilder (io.opentelemetry.sdk.logs.data.LogDataBuilder)1 LogExporter (io.opentelemetry.sdk.logs.export.LogExporter)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Test (org.junit.jupiter.api.Test)1