I have a NiFi flow that includes various custom processors to collect data from Kafka, perform calculations, and store results in a database. I want to add OpenTelemetry tracing to gain better insights into what happens internally throughout the flow by adding spans.
I went through OpenTelemetry concepts and examples and then attempted to add spans inside my NiFi custom processors.
Here’s what I did: Added OpenTelemetry dependencies in pom.xml:
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>1.30.0</version>
</dependency>
Initialized OpenTelemetry in my custom processor:
@OnScheduled
public void onScheduled(final ProcessContext context) {
AttributeKey<String> strKey = AttributeKey.stringKey("NiFi-CustomProcessor");
Attributes attr = Attributes.builder()
.put(strKey, "String")
.build();
Resource resource = Resource.create(attr);
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder().build()).build())
.setResource(resource)
.build();
openTelemetry = OpenTelemetrySdk.builder().setTracerProvider(sdkTracerProvider).build();
tracer = openTelemetry.getTracer("MyCustomProcessorTracer");
}
Added spans inside onTrigger:
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
Span span = tracer.spanBuilder("processFlowFile").startSpan();
// ........
span.addEvent("Processor Started");
//business logic
span.addEvent("Processor Finished");
span.end();
}
Configured the OpenTelemetry Java Agent in nifi-bootstrap.conf:
java.arg.extra=javaagent:/path/to/opentelemetry-javaagent.jar
Trying to set up an OpenTelemetry Collector but not finding a proper .exe file to run it on Windows.
Need help on the following:
- Am I on the right track for adding OpenTelemetry tracing to NiFi custom processors?
- Do I need to manually initialize OpenTelemetry inside each processor, or is there a better way?
- How do I correctly set up the OpenTelemetry Collector on Windows?
- Is adding the Java agent in nifi-bootstrap.conf sufficient for tracing, or do I need additional configurations?
- Any guidance or improvements on my approach would be greatly appreciated!