Skip to content

Commit

Permalink
fix: tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Sep 16, 2024
1 parent f08232f commit 693c34a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ mock-attestation-docker:
sample-cognito-auth:
@echo "Building sample cognito auth server"
@mkdir -p ./build/bin
@GOPROXY=$(GOPROXY) go build -modfile test/bdd/go.mod -o ./build/bin/cognito-auth-server test/bdd/cognito-auth/main.go
@GOPROXY=$(GOPROXY) go build -C test/bdd/cognito-auth -modfile ../../../test/bdd/go.mod -o ./build/bin/cognito-auth-server

.PHONY: sample-cognito-auth-docker
sample-cognito-auth-docker:
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.27.33
github.com/aws/aws-sdk-go-v2/service/kms v1.35.7
github.com/aws/aws-sdk-go-v2/service/s3 v1.61.2
github.com/aws/smithy-go v1.20.4
github.com/btcsuite/btcd v0.20.1-beta
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cenkalti/backoff/v4 v4.3.0
Expand Down Expand Up @@ -51,7 +52,7 @@ require (
go.mongodb.org/mongo-driver v1.16.1
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.54.0
go.opentelemetry.io/otel v1.29.0
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.29.0
go.opentelemetry.io/otel/sdk v1.29.0
go.opentelemetry.io/otel/trace v1.29.0
Expand Down Expand Up @@ -90,7 +91,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.22.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.7 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.7 // indirect
github.com/aws/smithy-go v1.20.4 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.14.3 // indirect
Expand Down Expand Up @@ -233,8 +233,8 @@ require (
go.opentelemetry.io/contrib/propagators/b3 v1.29.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.29.0 // indirect
go.opentelemetry.io/contrib/samplers/jaegerremote v0.23.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
Expand Down
21 changes: 4 additions & 17 deletions pkg/observability/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/trustbloc/logutil-go/pkg/log"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
Expand All @@ -35,9 +35,7 @@ const (
)

const (
JaegerAgentEndpointEnvKey = "OTEL_EXPORTER_JAEGER_AGENT_HOST"
JaegerCollectorEndpointEnvKey = "OTEL_EXPORTER_JAEGER_ENDPOINT"
tracerName = "https://github.com/trustbloc/vcs"
tracerName = "https://github.com/trustbloc/vcs"
)

// Initialize creates and registers globally a new tracer provider with specified span exporter.
Expand All @@ -59,20 +57,9 @@ func Initialize(exporter SpanExporterType, serviceName string) (func(), trace.Tr

switch exporter {
case Jaeger:
var endpoint jaeger.EndpointOption

switch {
case os.Getenv(JaegerAgentEndpointEnvKey) != "":
endpoint = jaeger.WithAgentEndpoint()
case os.Getenv(JaegerCollectorEndpointEnvKey) != "":
endpoint = jaeger.WithCollectorEndpoint()
default:
return nil, nil, fmt.Errorf("neither agent nor collector endpoint is provided")
}

spanExporter, err = jaeger.New(endpoint)
spanExporter, err = otlptracehttp.New(context.Background())
if err != nil {
return nil, nil, fmt.Errorf("create jaeger exporter: %w", err)
return nil, nil, fmt.Errorf("create OTLP HTTP exporter: %w", err)

Check warning on line 62 in pkg/observability/tracing/tracing.go

View check run for this annotation

Codecov / codecov/patch

pkg/observability/tracing/tracing.go#L62

Added line #L62 was not covered by tests
}
case Stdout:
spanExporter, err = stdouttrace.New()
Expand Down
2 changes: 1 addition & 1 deletion pkg/observability/tracing/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestInitialize(t *testing.T) {
})

t.Run("Provider JAEGER", func(t *testing.T) {
t.Setenv("OTEL_EXPORTER_JAEGER_ENDPOINT", "localhost")
t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost")

shutdown, tracer, err := Initialize("JAEGER", "service1")
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion test/bdd/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ services:
- VC_PROM_HTTP_URL=vc-rest-echo.trustbloc.local:48127
- VC_OAUTH_CLIENTS_FILE_PATH=/oauth-clients/clients.json
- OTEL_EXPORTER_TYPE=JAEGER
- OTEL_EXPORTER_JAEGER_ENDPOINT=http://jaeger.example.com:14268/api/traces
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger.example.com:14268
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://jaeger.example.com:14268
- VC_OIDC4VP_RECEIVED_CLAIMS_DATA_TTL=10s
- VC_SYSTEM_VERSION=v1.0.0
- VC_REST_DATA_ENCRYPTION_KEY_ID=bc436485-5092-42b8-92a3-0aa8b93536dc
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.30.5
github.com/aws/aws-sdk-go-v2/config v1.27.33
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.43.4
github.com/aws/smithy-go v1.20.4
github.com/cucumber/godog v0.12.5
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
Expand Down Expand Up @@ -60,7 +61,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.22.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.7 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.7 // indirect
github.com/aws/smithy-go v1.20.4 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bits-and-blooms/bitset v1.14.3 // indirect
github.com/bluele/gcache v0.0.2 // indirect
Expand Down

0 comments on commit 693c34a

Please sign in to comment.