Am using opentelemetry java agent on my springboot app as well the opentelemetry sdk to manually instrument some business logic that is executed by kafka streams in my app.
The dependencies in my build.gradle.kts
file look like this;
implementation("io.opentelemetry:opentelemetry-api")
implementation("io.opentelemetry:opentelemetry-sdk")
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
Here is an example of the manually instrumented business logic
override fun assignDemographic(transaction: Transaction): Either<DemographicAssignmentError, RawCustomerDemographic> {
val span = tracer.spanBuilder("assignDemographic")
.setSpanKind(SpanKind.CONSUMER)
.startSpan()
span.makeCurrent()
val spanAttributes = Attributes.of(
stringKey("transaction"), transaction.transaction,
stringKey("customerId"), transaction.customerId)
span.addEvent("Assigning Demographics", spanAttributes)
val result = transactionValidatorService.checkIsValidTransaction(transaction)
val validationSpanAttributes = Attributes.of(booleanKey("validationResult"), result)
span.addEvent("Checked to see if transaction is valid/supported", validationSpanAttributes)
return when (result) {
true -> {
val assignedDemographic = demographicAssignerService.assignDemographic(transaction).right()
assignedDemographic.map {
val resultAttributes = Attributes.of(stringArrayKey("result"), it.demographics)
span.setStatus(StatusCode.OK)
span.addEvent("Successfully assigned demograhics to customer", resultAttributes)
}
assignedDemographic
}
else -> {
val error = DemographicAssignmentError().left()
error.mapLeft {
span.setStatus(StatusCode.ERROR)
span.addEvent("Could not successfully assign demographics to the customer")
}
error
}
}
}
Here is the config for running my app
export JAVA_TOOL_OPTIONS="-javaagent:./opentelemetry-javaagent.jar"
export OTEL_SERVICE_NAME="app-name"
export OTEL_JAVAAGENT_LOGGING=application
export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT="https://backend-endpoint"
java \
-jar \
-Dotel.instrumentation.kafka.experimental-span-attributes=true \
./build/libs/$APP_NAME.jar
The problem am facing is that the span created in this logic never gets picked by the exporter.
What could be problem?
Thank you
The cause of problem here was that i did not call span.end()
anywhere in my code