Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support OTEL_EXPERIMENTAL_EXPORTER_OTLP_RETRY_ENABLED env var #1159

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ kamon.otel {
attributes = ""
attributes = ${?OTEL_RESOURCE_ATTRIBUTES}

retryEnabled = false
retryEnabled = ${?OTEL_EXPERIMENTAL_EXPORTER_OTLP_RETRY_ENABLED}

trace {
endpoint = ${kamon.otel.endpoint}
full-endpoint = ${?OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}
Expand All @@ -43,6 +46,7 @@ kamon.otel {
protocol = ${kamon.otel.protocol}
protocol = ${?OTEL_EXPORTER_OTLP_TRACES_PROTOCOL}

retryEnabled = ${kamon.otel.retryEnabled}
# If set to true, any error (message and stacktrace) on a span will be included as an event on the span with
# standard attribute names; enable for 'more full' compliance with otel standard
include-error-event = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.util.{Collection => JCollection}
import scala.concurrent.{Future, Promise}

import com.typesafe.config.Config
import io.opentelemetry.exporter.internal.retry.{RetryPolicy, RetryUtil}
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter
import io.opentelemetry.sdk.trace.`export`.SpanExporter
Expand Down Expand Up @@ -71,6 +72,7 @@ private[otel] object OtlpTraceService {
case Array(k, v) => k -> v
}.toSeq
val timeout = otelExporterConfig.getDuration("timeout")
val retryEnabled = otelExporterConfig.getBoolean("retryEnabled")
// See https://opentelemetry.io/docs/reference/specification/protocol/exporter/#endpoint-urls-for-otlphttp
val url = (protocol, fullEndpoint) match {
case ("http/protobuf", Some(full)) =>
Expand All @@ -85,20 +87,22 @@ private[otel] object OtlpTraceService {

logger.info(s"Configured endpoint for OpenTelemetry trace reporting [$url] using $protocol protocol")

new OtlpTraceService(protocol, url, compression, headers, timeout)
new OtlpTraceService(protocol, url, compression, headers, timeout, retryEnabled)
}
}

private[otel] class OtlpTraceService(protocol: String, endpoint: String, compressionEnabled: Boolean, headers: Seq[(String, String)], timeout: Duration) extends TraceService {
private[otel] class OtlpTraceService(protocol: String, endpoint: String, compressionEnabled: Boolean, headers: Seq[(String, String)], timeout: Duration, retryEnabled: Boolean) extends TraceService {
private val compressionMethod = if (compressionEnabled) "gzip" else "none"
private val delegate: SpanExporter = protocol match {
case "grpc" =>
val builder = OtlpGrpcSpanExporter.builder().setEndpoint(endpoint).setCompression(compressionMethod).setTimeout(timeout)
headers.foreach { case (k, v) => builder.addHeader(k, v) }
if (retryEnabled) RetryUtil.setRetryPolicyOnDelegate(builder, RetryPolicy.getDefault)
builder.build()
case "http/protobuf" =>
val builder = OtlpHttpSpanExporter.builder().setEndpoint(endpoint).setCompression(compressionMethod).setTimeout(timeout)
headers.foreach { case (k, v) => builder.addHeader(k, v) }
if (retryEnabled) RetryUtil.setRetryPolicyOnDelegate(builder, RetryPolicy.getDefault)
builder.build()
}

Expand Down