Skip to content

Commit

Permalink
PIP-2428: Improve logging on OTel initialization. (#171)
Browse files Browse the repository at this point in the history
* PIP-2428: Improve logging on OTel initialization.

* PIP-2428: Fix test.

---------

Co-authored-by: Shawn Poulson <[email protected]>
  • Loading branch information
Baliedge and Baliedge authored Jun 1, 2023
1 parent 6210080 commit 0a7769c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions mxresolv/mxresolv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func TestLookupError(t *testing.T) {
outError string
}{
{
inDomainName: "test-broken.definbox.com",
outError: "lookup test-broken.definbox.com.*: no such host",
inDomainName: "test-bogus.definbox.com",
outError: "lookup test-bogus.definbox.com.*: no such host",
},
{
inDomainName: "",
Expand Down
47 changes: 31 additions & 16 deletions tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"runtime/debug"
"strconv"
"strings"

"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -199,10 +200,19 @@ func makeOtlpExporter(ctx context.Context) (*otlptrace.Exporter, error) {
client = otlptracegrpc.NewClient()
}

log.WithFields(logrus.Fields{
logFields := logrus.Fields{
"exporter": "otlp",
"protocol": protocol,
"endpoint": getenvOrDefault("", "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"),
}).Info("Initializing OTLP exporter")
}

sampler := getenvOrDefault("", "OTEL_TRACES_SAMPLER")
logFields["sampler"] = sampler
if strings.HasSuffix(sampler, "traceidratio") {
logFields["sampler.ratio"], _ = strconv.ParseFloat(getenvOrDefault("", "OTEL_TRACES_SAMPLER_ARG"), 64)
}

log.WithFields(logFields).Info("Initializing OpenTelemetry")

return otlptrace.New(ctx, client)
}
Expand All @@ -211,32 +221,37 @@ func makeJaegerExporter() (*jaeger.Exporter, error) {
var endpointOption jaeger.EndpointOption
protocol := getenvOrDefault("udp/thrift.compact", "OTEL_EXPORTER_JAEGER_PROTOCOL")

logFields := logrus.Fields{
"exporter": "jaeger",
"protocol": protocol,
}

sampler := getenvOrDefault("", "OTEL_TRACES_SAMPLER")
logFields["sampler"] = sampler
if strings.HasSuffix(sampler, "traceidratio") {
logFields["sampler.ratio"], _ = strconv.ParseFloat(getenvOrDefault("", "OTEL_TRACES_SAMPLER_ARG"), 64)
}

// OTel Jaeger client doesn't seem to implement the spec for
// OTEL_EXPORTER_JAEGER_PROTOCOL selection. So we must.
// Jaeger endpoint option will parse supported env var configuration.
switch protocol {
// TODO: Support for "grpc" protocol. https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#jaeger-exporter
case "http/thrift.binary":
log.WithFields(logrus.Fields{
"endpoint": os.Getenv("OTEL_EXPORTER_JAEGER_ENDPOINT"),
"protocol": protocol,
}).Info("Initializing Jaeger exporter")
logFields["endpoint"] = os.Getenv("OTEL_EXPORTER_JAEGER_ENDPOINT")
log.WithFields(logFields).Info("Initializing OpenTelemetry")
endpointOption = jaeger.WithCollectorEndpoint()

case "udp/thrift.binary":
log.WithFields(logrus.Fields{
"agentHost": os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_HOST"),
"agentPort": os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_PORT"),
"protocol": protocol,
}).Info("Initializing Jaeger exporter")
logFields["agentHost"] = os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_HOST")
logFields["agentPort"] = os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_PORT")
log.WithFields(logFields).Info("Initializing OpenTelemetry")
endpointOption = jaeger.WithAgentEndpoint()

case "udp/thrift.compact":
log.WithFields(logrus.Fields{
"agentHost": os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_HOST"),
"agentPort": os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_PORT"),
"protocol": protocol,
}).Info("Initializing Jaeger exporter")
logFields["agentHost"] = os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_HOST")
logFields["agentPort"] = os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_PORT")
log.WithFields(logFields).Info("Initializing OpenTelemetry")
endpointOption = jaeger.WithAgentEndpoint()

default:
Expand Down

0 comments on commit 0a7769c

Please sign in to comment.