diff --git a/installer/examples/full-config.yaml b/installer/examples/full-config.yaml index ff9d6f09..03c29deb 100644 --- a/installer/examples/full-config.yaml +++ b/installer/examples/full-config.yaml @@ -28,6 +28,9 @@ tracing: install: true honeycombDataset: "fake-dataset" honeycombAPIKey: "fake-key" + extraSpanAttributes: + preview: test + exampleKey: exampleValue werft: installServiceMonitors: false imports: diff --git a/installer/pkg/components/otel-collector/configmap.go b/installer/pkg/components/otel-collector/configmap.go index 281ebd94..1df122c0 100644 --- a/installer/pkg/components/otel-collector/configmap.go +++ b/installer/pkg/components/otel-collector/configmap.go @@ -10,7 +10,40 @@ import ( "github.com/gitpod-io/observability/installer/pkg/common" ) -var configMapData = `receivers: +const extraAttributesProcessor = "attributes" + +func configMap(ctx *common.RenderContext) ([]runtime.Object, error) { + var receiversConfig = buildReceiversConfig(ctx) + var processorsConfig = buildProcessorsConfig(ctx) + var exportersConfig = buildExportersConfig(ctx) + var extensionsConfig = buildExtensionsConfig(ctx) + var serviceConfig = buildServiceConfig(ctx) + var config = fmt.Sprintf(`%s +%s +%s +%s +%s`, receiversConfig, processorsConfig, exportersConfig, extensionsConfig, serviceConfig) + + return []runtime.Object{ + &corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "v1", + Kind: "ConfigMap", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: Name, + Namespace: Namespace, + Labels: common.Labels(Name, Component, App, Version), + }, + Data: map[string]string{ + "collector.yaml": config, + }, + }, + }, nil +} + +func buildReceiversConfig(ctx *common.RenderContext) string { + return `receivers: jaeger: protocols: thrift_http: @@ -19,44 +52,62 @@ var configMapData = `receivers: protocols: grpc: # on port 4317 http: # on port 4318 -exporters: +` +} + +func buildProcessorsConfig(ctx *common.RenderContext) string { + var processorsConfig = "" + if ctx.Config.Tracing.ExtraSpanAttributes != nil { + processorsConfig = fmt.Sprintf(`processors: + %s: + actions:`, extraAttributesProcessor) + + var keyValueAttributeTemplate = ` + - key: '%s' + value: %s + action: insert` + for key, value := range ctx.Config.Tracing.ExtraSpanAttributes { + processorsConfig += fmt.Sprintf(keyValueAttributeTemplate, key, value) + } + } + + return processorsConfig +} + +func buildExportersConfig(ctx *common.RenderContext) string { + return fmt.Sprintf(`exporters: otlp: endpoint: "api.honeycomb.io:443" headers: "x-honeycomb-team": "%s" - "x-honeycomb-dataset": "%s" + "x-honeycomb-dataset": "%s"`, + ctx.Config.Tracing.HoneycombAPIKey, ctx.Config.Tracing.HoneycombDataset) +} -extensions: +func buildExtensionsConfig(ctx *common.RenderContext) string { + return `extensions: health_check: pprof: - zpages: -service: + zpages:` +} + +func buildServiceConfig(ctx *common.RenderContext) string { + var serviceTemplate = `service: telemetry: logs: level: "debug" extensions: [health_check, pprof, zpages] pipelines: traces: - receivers: [jaeger, otlp] - processors: [ ] - exporters: ["otlp"] + receivers: [jaeger, otlp] + processors: [%s] + exporters: ["otlp"] ` + var processors = "" -func configMap(ctx *common.RenderContext) ([]runtime.Object, error) { - return []runtime.Object{ - &corev1.ConfigMap{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "v1", - Kind: "ConfigMap", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: Name, - Namespace: Namespace, - Labels: common.Labels(Name, Component, App, Version), - }, - Data: map[string]string{ - "collector.yaml": fmt.Sprintf(configMapData, ctx.Config.Tracing.HoneycombAPIKey, ctx.Config.Tracing.HoneycombDataset), - }, - }, - }, nil + if ctx.Config.Tracing.ExtraSpanAttributes != nil { + processors = extraAttributesProcessor + } + + return fmt.Sprintf(serviceTemplate, processors) } diff --git a/installer/pkg/config/config.go b/installer/pkg/config/config.go index 84432028..ccdf38a0 100644 --- a/installer/pkg/config/config.go +++ b/installer/pkg/config/config.go @@ -92,9 +92,10 @@ type Config struct { } type Tracing struct { - Install bool `json:"install"` - HoneycombAPIKey string `json:"honeycombAPIKey,omitempty"` - HoneycombDataset string `json:"honeycombDataset,omitempty"` + Install bool `json:"install"` + HoneycombAPIKey string `json:"honeycombAPIKey,omitempty"` + HoneycombDataset string `json:"honeycombDataset,omitempty"` + ExtraSpanAttributes map[string]string `json:"extraSpanAttributes,omitempty"` } type Alerting struct {