Skip to content

Commit

Permalink
chore: Remove unused OTEL flags
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Sep 18, 2024
1 parent b05d24b commit 099fc0f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
46 changes: 1 addition & 45 deletions serve/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"reflect"
"strings"
"time"

"github.com/cloudquery/plugin-sdk/v4/plugin"
Expand Down Expand Up @@ -41,23 +40,9 @@ func newResource(p *plugin.Plugin) *resource.Resource {
return r
}

func parseOtelHeaders(headers []string) map[string]string {
headerMap := make(map[string]string, len(headers))
for _, h := range headers {
parts := strings.SplitN(h, ":", 2)
if len(parts) != 2 {
continue
}
headerMap[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
}
return headerMap
}

type otelConfig struct {
endpoint string
insecure bool
headers []string
urlPath string
}

func getTraceExporter(ctx context.Context, opts otelConfig) (*otlptrace.Exporter, error) {
Expand All @@ -73,15 +58,6 @@ func getTraceExporter(ctx context.Context, opts otelConfig) (*otlptrace.Exporter
traceOptions = append(traceOptions, otlptracehttp.WithInsecure())
}

if len(opts.headers) > 0 {
headers := parseOtelHeaders(opts.headers)
traceOptions = append(traceOptions, otlptracehttp.WithHeaders(headers))
}

if opts.urlPath != "" {
traceOptions = append(traceOptions, otlptracehttp.WithURLPath(opts.urlPath))
}

traceClient := otlptracehttp.NewClient(traceOptions...)
traceExporter, err := otlptrace.New(ctx, traceClient)
if err != nil {
Expand All @@ -104,15 +80,6 @@ func getMetricReader(ctx context.Context, opts otelConfig) (*metric.PeriodicRead
metricOptions = append(metricOptions, otlpmetrichttp.WithInsecure())
}

if len(opts.headers) > 0 {
headers := parseOtelHeaders(opts.headers)
metricOptions = append(metricOptions, otlpmetrichttp.WithHeaders(headers))
}

if opts.urlPath != "" {
metricOptions = append(metricOptions, otlpmetrichttp.WithURLPath(opts.urlPath))
}

metricExporter, err := otlpmetrichttp.New(ctx, metricOptions...)
if err != nil {
return nil, fmt.Errorf("creating OTLP metric exporter: %w", err)
Expand All @@ -136,15 +103,6 @@ func getLogsProcessor(ctx context.Context, opts otelConfig) (*log.BatchProcessor
logOptions = append(logOptions, otlploghttp.WithInsecure())
}

if len(opts.headers) > 0 {
headers := parseOtelHeaders(opts.headers)
logOptions = append(logOptions, otlploghttp.WithHeaders(headers))
}

if opts.urlPath != "" {
logOptions = append(logOptions, otlploghttp.WithURLPath(opts.urlPath))
}

exporter, err := otlploghttp.New(ctx, logOptions...)
if err != nil {
return nil, fmt.Errorf("creating OTLP log exporter: %w", err)
Expand All @@ -154,15 +112,13 @@ func getLogsProcessor(ctx context.Context, opts otelConfig) (*log.BatchProcessor
return processor, nil
}

func setupOtel(ctx context.Context, logger zerolog.Logger, p *plugin.Plugin, otelEndpoint string, otelEndpointInsecure bool, otelEndpointHeaders []string, otelEndpointURLPath string) (shutdown func(), err error) {
func setupOtel(ctx context.Context, logger zerolog.Logger, p *plugin.Plugin, otelEndpoint string, otelEndpointInsecure bool) (shutdown func(), err error) {
if otelEndpoint == "" {
return nil, nil
}
opts := otelConfig{
endpoint: otelEndpoint,
insecure: otelEndpointInsecure,
headers: otelEndpointHeaders,
urlPath: otelEndpointURLPath,
}
traceExporter, err := getTraceExporter(ctx, opts)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions serve/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
var network string
var noSentry bool
var otelEndpoint string
var otelEndpointHeaders []string
var otelEndpointInsecure bool
var otelEndpointURLPath string
var licenseFile string
logLevel := newEnum([]string{"trace", "debug", "info", "warn", "error"}, "info")
logFormat := newEnum([]string{"text", "json"}, "text")
Expand Down Expand Up @@ -136,7 +134,7 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout}).Level(zerologLevel)
}

shutdown, err := setupOtel(cmd.Context(), logger, s.plugin, otelEndpoint, otelEndpointInsecure, otelEndpointHeaders, otelEndpointURLPath)
shutdown, err := setupOtel(cmd.Context(), logger, s.plugin, otelEndpoint, otelEndpointInsecure)
if err != nil {
return fmt.Errorf("failed to setup OpenTelemetry: %w", err)
}
Expand Down Expand Up @@ -234,8 +232,6 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
cmd.Flags().Var(logLevel, "log-level", fmt.Sprintf("log level. one of: %s", strings.Join(logLevel.Allowed, ",")))
cmd.Flags().Var(logFormat, "log-format", fmt.Sprintf("log format. one of: %s", strings.Join(logFormat.Allowed, ",")))
cmd.Flags().StringVar(&otelEndpoint, "otel-endpoint", "", "Open Telemetry HTTP collector endpoint")
cmd.Flags().StringVar(&otelEndpointURLPath, "otel-endpoint-urlpath", "", "Open Telemetry HTTP collector endpoint URL path")
cmd.Flags().StringArrayVar(&otelEndpointHeaders, "otel-endpoint-headers", []string{}, "Open Telemetry HTTP collector endpoint headers")
cmd.Flags().BoolVar(&otelEndpointInsecure, "otel-endpoint-insecure", false, "use Open Telemetry HTTP endpoint (for development only)")
cmd.Flags().BoolVar(&noSentry, "no-sentry", false, "disable sentry")
cmd.Flags().StringVar(&licenseFile, "license", "", "Path to offline license file or directory")
Expand Down

0 comments on commit 099fc0f

Please sign in to comment.