最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

open telemetry - How to Add OpenTelemetry Tracing to NiFi Custom Processors? - Stack Overflow

programmeradmin2浏览0评论

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:

  1. Am I on the right track for adding OpenTelemetry tracing to NiFi custom processors?
  2. Do I need to manually initialize OpenTelemetry inside each processor, or is there a better way?
  3. How do I correctly set up the OpenTelemetry Collector on Windows?
  4. Is adding the Java agent in nifi-bootstrap.conf sufficient for tracing, or do I need additional configurations?
  5. Any guidance or improvements on my approach would be greatly appreciated!
发布评论

评论列表(0)

  1. 暂无评论