feat: support OTLP tracing protocol selection#1050
Conversation
efd69e0 to
1392242
Compare
|
Update: the first integration CI run failed before executing integration tests because Additional local validation for that fix:
|
1392242 to
a7485e4
Compare
|
Small follow-up after a final sweep: since this PR adds OTLP/gRPC support, I also exposed Jaeger's Additional local validation:
|
a7485e4 to
5ccb749
Compare
|
Small final coverage follow-up: I added a config validation test proving an invalid tracing Additional local validation after the amend:
|
jranson
left a comment
There was a problem hiding this comment.
looks generally good, just a few minor nits around use of string literals versus consts, and some error cleanup.
| return nil, err | ||
| } | ||
|
|
||
| tracerOpts := make([]sdktrace.TracerProviderOption, 0, 3) |
There was a problem hiding this comment.
You should be able bootstrap tp in a single line without creating/appending tracerOpts, like:
tp = sdktrace.NewTracerProvider(
sdktrace.WithSampler(tracing.Sampler(o)),
sdktrace.WithResource(resource.NewWithAttributes("", tags...)),
sdktrace.WithBatcher(exporter),
)
| switch { | ||
| case o.Endpoint == "": | ||
| case strings.HasPrefix(o.Endpoint, "/"): | ||
| return nil, fmt.Errorf("%w: path-only endpoints require OTLP/HTTP protocol", |
There was a problem hiding this comment.
prefer a static package-level error here. a dynamically-created error is not necessary (the error message will always be the same) and unit tests can then use a simple pointer equality test on the error var for verification instead of errors.Is().
| if v.Provider == "" { | ||
| v.Provider = DefaultTracerProvider | ||
| } | ||
| if v.Provider == "otlp" && v.Protocol == "" { |
There was a problem hiding this comment.
should create and use an OTLP constant here instead of the "otlp" string literal.
| } | ||
|
|
||
| otlp := &Options{Provider: "otlp"} | ||
| ProcessTracingOptions(Lookup{"otlp": otlp}) |
There was a problem hiding this comment.
should use an OTLP constant here instead of the "otlp" string literal.
| opt.Protocol = options.OTLPProtocolGRPC | ||
| opt.Endpoint = "/v1/traces" | ||
| _, err = New(opt) | ||
| if !errors.Is(err, errs.ErrInvalidEndpointURL) { |
There was a problem hiding this comment.
here is where you can check for the requested package-level var instead of using errors.Is()
| opt.Protocol = options.OTLPProtocolGRPC | ||
| opt.Endpoint = "http://" + lis.Addr().String() | ||
| opt.ServiceName = "trickster-grpc-test" | ||
| opt.Headers = map[string]string{"x-trickster-test": "grpc"} |
There was a problem hiding this comment.
use options.OTLPProtocolGRPC here instead of the string literal
| select { | ||
| case md := <-metadataCh: | ||
| if got := md.Get("x-trickster-test"); len(got) != 1 || got[0] != "grpc" { | ||
| t.Errorf("expected gRPC metadata header %q, got %v", "grpc", got) |
There was a problem hiding this comment.
use options.OTLPProtocolGRPC in the conditional check and the test error
5ccb749 to
410b054
Compare
|
Thanks, fixed the requested nits:
Validated with:
|
Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
410b054 to
93e452d
Compare
Description
Fixes #381.
This adds explicit OTLP transport selection for tracing configs with
protocol: http|grpc:protocoltohttpprotocol: httpexplicitlyI think this completes the remaining OTLP transport/config gap after the earlier #381 tracing slices landed.
Validation:
go test ./pkg/observability/tracing/options -count=1go test ./pkg/observability/tracing/exporters/otlp -count=1go test ./pkg/observability/tracing/... -count=1go test ./pkg/observability/... -count=1go test -race ./pkg/observability/tracing/exporters/otlp -run TestNewAppliesGRPCProtocol -count=1go tool golangci-lint run --timeout 5m ./pkg/observability/tracing/...go test -run '^$' ./...go test ./pkg/config/validate -count=1go run ./cmd/trickster -validate-config -config examples\docker-compose\docker-compose-data\trickster-config\trickster.yamlgo run ./cmd/trickster -validate-config -config docs\developer\environment\trickster-config\trickster.yamlgit diff --checkNote: I also tried
go test ./pkg/config/...locally on Windows; it hits the existingTestConfig_defaultinggolden/path separator difference (/tmp/trickstervs.\cache), so I did not list it as passing validation above.Type of Change
AI Disclosure