Skip to content

Commit 3541726

Browse files
authored
feat: Expose otel headers and url_path as flags (#1430)
This is a minor improvement to expose otel headers and url_path as flags. I tested it with OpenObserve - https://openobserve.ai/docs/ingestion/traces/go/#clone Example running a plugin with OpenObserve running locally ``` go run main.go serve --otel-endpoint localhost:5080 --otel-endpoint-headers "Authorization: Basic TOKEN" --otel-endpoint-insecure --otel-endpoint-urlpath "/api/default/v1/traces" ``` <img width="1452" alt="image" src="https://github.com/cloudquery/plugin-sdk/assets/16490766/966bee3c-ade7-42a4-ba7d-568fd912b81d">
1 parent b50e9ac commit 3541726

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

serve/plugin.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
118118
var network string
119119
var noSentry bool
120120
var otelEndpoint string
121+
var otelEndpointHeaders []string
121122
var otelEndpointInsecure bool
123+
var otelEndpointURLPath string
122124
logLevel := newEnum([]string{"trace", "debug", "info", "warn", "error"}, "info")
123125
logFormat := newEnum([]string{"text", "json"}, "text")
124126
telemetryLevel := newEnum([]string{"none", "errors", "stats", "all"}, "all")
@@ -153,6 +155,21 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
153155
if otelEndpointInsecure {
154156
opts = append(opts, otlptracehttp.WithInsecure())
155157
}
158+
if len(otelEndpointHeaders) > 0 {
159+
headers := make(map[string]string, len(otelEndpointHeaders))
160+
for _, h := range otelEndpointHeaders {
161+
parts := strings.SplitN(h, ":", 2)
162+
if len(parts) != 2 {
163+
return fmt.Errorf("invalid header %q", h)
164+
}
165+
headers[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
166+
}
167+
opts = append(opts, otlptracehttp.WithHeaders(headers))
168+
}
169+
if otelEndpointURLPath != "" {
170+
opts = append(opts, otlptracehttp.WithURLPath(otelEndpointURLPath))
171+
}
172+
156173
client := otlptracehttp.NewClient(opts...)
157174
exp, err := otlptrace.New(cmd.Context(), client)
158175
if err != nil {
@@ -275,6 +292,8 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
275292
cmd.Flags().Var(logLevel, "log-level", fmt.Sprintf("log level. one of: %s", strings.Join(logLevel.Allowed, ",")))
276293
cmd.Flags().Var(logFormat, "log-format", fmt.Sprintf("log format. one of: %s", strings.Join(logFormat.Allowed, ",")))
277294
cmd.Flags().StringVar(&otelEndpoint, "otel-endpoint", "", "Open Telemetry HTTP collector endpoint")
295+
cmd.Flags().StringVar(&otelEndpointURLPath, "otel-endpoint-urlpath", "", "Open Telemetry HTTP collector endpoint URL path")
296+
cmd.Flags().StringArrayVar(&otelEndpointHeaders, "otel-endpoint-headers", []string{}, "Open Telemetry HTTP collector endpoint headers")
278297
cmd.Flags().BoolVar(&otelEndpointInsecure, "otel-endpoint-insecure", false, "use Open Telemetry HTTP endpoint (for development only)")
279298
cmd.Flags().BoolVar(&noSentry, "no-sentry", false, "disable sentry")
280299
sendErrors := funk.ContainsString([]string{"all", "errors"}, telemetryLevel.String())

0 commit comments

Comments
 (0)