Wednesday, September 28, 2022
HomeJavaFinish-to-end tracing with OpenTelemetry

Finish-to-end tracing with OpenTelemetry


The catalog service is a Reactive Spring Boot utility developed in Kotlin. It gives two endpoints:

  • One to fetch a single product
  • The opposite to fetch all merchandise

Each first look within the product database, then question the above pricing service for the value.

As for Python, we are able to leverage automated and handbook instrumentation. Let’s begin with the low-hanging fruit, automated instrumentation. On the JVM, we obtain it via an agent:

java -javaagent:opentelemetry-javaagent.jar -jar catalog.jar

As in Python, it creates spans for each methodology name and HTTP entry level. It additionally devices JDBC calls, however we now have a Reactive stack and thus use R2DBC. For the file, a GitHub concern is open for including help.

We have to configure the default habits:

  catalog:
    construct: ./catalog
    atmosphere:
      APP_PRICING_ENDPOINT: http://pricing:5000/value
      OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4317     (1)
      OTEL_RESOURCE_ATTRIBUTES: service.title=orders       (2)
      OTEL_METRICS_EXPORTER: none                         (3)
      OTEL_LOGS_EXPORTER: none                            (3)

1 Ship the traces to Jaeger
2 Set the title of the service. It’s the title that may seem within the hint show part
3 We have an interest neither in logs nor in metrics

As for Python, we are able to up the sport by including handbook instrumentation. Two choices can be found, programmatic and annotation-based. The previous is a bit concerned until we introduce Spring Cloud Sleuth. Let’s add annotations.

We’d like a further dependency:

pom.xml

<dependency>
	<groupId>io.opentelemetry.instrumentation</groupId>
	<artifactId>opentelemetry-instrumentation-annotations</artifactId>
	<model>1.17.0-alpha</model>
</dependency>

Watch out, the artifact was very lately relocated from io.opentelemetry:opentelemetry-extension-annotations.

We are able to now annotate our code:

@WithSpan("ProductHandler.fetch")                                               (1)
droop enjoyable fetch(@SpanAttribute("id") id: Lengthy): Outcome<Product> {             (2)
    val product = repository.findById(id)
    return if (product == null) Outcome.failure(IllegalArgumentException("Product $id not discovered"))
    else Outcome.success(product)
}

1 Add a further span with the configured label
2 Use the parameter as an attribute, with the important thing set to id and the worth the parameter’s runtime worth
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments