Skip to content

Enhance Traces with pod information #4898

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

Merged
merged 5 commits into from
Oct 6, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* [ENHANCEMENT] Ingester: Prevent ingesters to become unhealthy during wall replay. #4847
* [ENHANCEMENT] Compactor: Introduced visit marker file for blocks so blocks are under compaction will not be picked up by another compactor. #4805
* [ENHANCEMENT] Distributor: Add label name to labelValueTooLongError. #4855
* [ENHANCEMENT] Enhance traces with hostname information. #4898
* [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784
* [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787
* [FEATURE] Compactor: Added configurations for Azure MSI in blocks-storage, ruler-storage and alertmanager-storage. #4818
Expand Down
37 changes: 25 additions & 12 deletions pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"

"github.com/cortexproject/cortex/pkg/tracing/migration"
"github.com/cortexproject/cortex/pkg/tracing/sampler"
Expand All @@ -40,11 +40,12 @@ type Config struct {
}

type Otel struct {
OltpEndpoint string `yaml:"oltp_endpoint" json:"oltp_endpoint"`
ExporterType string `yaml:"exporter_type" json:"exporter_type"`
SampleRatio float64 `yaml:"sample_ratio" json:"sample_ratio"`
TLSEnabled bool `yaml:"tls_enabled"`
TLS tls.ClientConfig `yaml:"tls"`
OltpEndpoint string `yaml:"oltp_endpoint" json:"oltp_endpoint"`
ExporterType string `yaml:"exporter_type" json:"exporter_type"`
SampleRatio float64 `yaml:"sample_ratio" json:"sample_ratio"`
TLSEnabled bool `yaml:"tls_enabled"`
TLS tls.ClientConfig `yaml:"tls"`
ExtraDetectors []resource.Detector `yaml:"-"`
}

// RegisterFlags registers flag.
Expand Down Expand Up @@ -103,7 +104,13 @@ func SetupTracing(ctx context.Context, name string, c Config) (func(context.Cont
return nil, fmt.Errorf("creating OTLP trace exporter: %w", err)
}

tracerProvider := newTraceProvider(name, c, exporter)
r, err := newResource(ctx, name, c.Otel.ExtraDetectors)

if err != nil {
return nil, fmt.Errorf("creating tracing resource: %w", err)
}

tracerProvider := newTraceProvider(r, c, exporter)

bridge, wrappedProvider := migration.NewCortexBridgeTracerWrapper(tracerProvider.Tracer("github.com/cortexproject/cortex/cmd/cortex"))
bridge.SetTextMapPropagator(propagation.TraceContext{})
Expand All @@ -118,10 +125,10 @@ func SetupTracing(ctx context.Context, name string, c Config) (func(context.Cont
}, nil
}

func newTraceProvider(name string, c Config, exporter *otlptrace.Exporter) *sdktrace.TracerProvider {
func newTraceProvider(r *resource.Resource, c Config, exporter *otlptrace.Exporter) *sdktrace.TracerProvider {
options := []sdktrace.TracerProviderOption{
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(newResource(name)),
sdktrace.WithResource(r),
}

switch strings.ToLower(c.Otel.ExporterType) {
Expand All @@ -135,9 +142,15 @@ func newTraceProvider(name string, c Config, exporter *otlptrace.Exporter) *sdkt
return sdktrace.NewTracerProvider(options...)
}

func newResource(target string) *resource.Resource {
return resource.NewWithAttributes(
func newResource(ctx context.Context, target string, detectors []resource.Detector) (*resource.Resource, error) {
r, err := resource.New(ctx, resource.WithHost(), resource.WithDetectors(detectors...))

if err != nil {
return nil, err
}

return resource.Merge(r, resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String(target),
)
))
}
20 changes: 0 additions & 20 deletions vendor/go.opentelemetry.io/otel/semconv/v1.10.0/doc.go

This file was deleted.

20 changes: 0 additions & 20 deletions vendor/go.opentelemetry.io/otel/semconv/v1.10.0/exception.go

This file was deleted.

114 changes: 0 additions & 114 deletions vendor/go.opentelemetry.io/otel/semconv/v1.10.0/http.go

This file was deleted.

Loading