Skip to content

Commit

Permalink
Make it possible to add new span attributes through Otel-Collector
Browse files Browse the repository at this point in the history
Signed-off-by: ArthurSens <arthursens2005@gmail.com>
  • Loading branch information
ArthurSens committed Sep 21, 2022
1 parent b626341 commit f580b23
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 29 deletions.
3 changes: 3 additions & 0 deletions installer/examples/full-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ tracing:
install: true
honeycombDataset: "fake-dataset"
honeycombAPIKey: "fake-key"
extraSpanAttributes:
preview: test
exampleKey: exampleValue
werft:
installServiceMonitors: false
imports:
Expand Down
103 changes: 77 additions & 26 deletions installer/pkg/components/otel-collector/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}
7 changes: 4 additions & 3 deletions installer/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f580b23

Please sign in to comment.