Skip to content

Commit 1bd93b4

Browse files
committed
Make it possible to add new span attributes through Otel-Collector
Signed-off-by: ArthurSens <[email protected]>
1 parent b626341 commit 1bd93b4

File tree

3 files changed

+84
-29
lines changed

3 files changed

+84
-29
lines changed

installer/examples/full-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ tracing:
2828
install: true
2929
honeycombDataset: "fake-dataset"
3030
honeycombAPIKey: "fake-key"
31+
extraSpanAttributes:
32+
preview: test
33+
exampleKey: exampleValue
3134
werft:
3235
installServiceMonitors: false
3336
imports:

installer/pkg/components/otel-collector/configmap.go

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,40 @@ import (
1010
"github.com/gitpod-io/observability/installer/pkg/common"
1111
)
1212

13-
var configMapData = `receivers:
13+
const extraAttributesProcessor = "extraAttributes"
14+
15+
func configMap(ctx *common.RenderContext) ([]runtime.Object, error) {
16+
var receiversConfig = buildReceiversConfig(ctx)
17+
var processorsConfig = buildProcessorsConfig(ctx)
18+
var exportersConfig = buildExportersConfig(ctx)
19+
var extensionsConfig = buildExtensionsConfig(ctx)
20+
var serviceConfig = buildServiceConfig(ctx)
21+
var config = fmt.Sprintf(`%s
22+
%s
23+
%s
24+
%s
25+
%s`, receiversConfig, processorsConfig, exportersConfig, extensionsConfig, serviceConfig)
26+
27+
return []runtime.Object{
28+
&corev1.ConfigMap{
29+
TypeMeta: metav1.TypeMeta{
30+
APIVersion: "v1",
31+
Kind: "ConfigMap",
32+
},
33+
ObjectMeta: metav1.ObjectMeta{
34+
Name: Name,
35+
Namespace: Namespace,
36+
Labels: common.Labels(Name, Component, App, Version),
37+
},
38+
Data: map[string]string{
39+
"collector.yaml": config,
40+
},
41+
},
42+
}, nil
43+
}
44+
45+
func buildReceiversConfig(ctx *common.RenderContext) string {
46+
return `receivers:
1447
jaeger:
1548
protocols:
1649
thrift_http:
@@ -19,44 +52,62 @@ var configMapData = `receivers:
1952
protocols:
2053
grpc: # on port 4317
2154
http: # on port 4318
22-
exporters:
55+
`
56+
}
57+
58+
func buildProcessorsConfig(ctx *common.RenderContext) string {
59+
var processorsConfig = ""
60+
if ctx.Config.Tracing.ExtraSpanAttributes != nil {
61+
processorsConfig = fmt.Sprintf(`processors:
62+
%s:
63+
actions:`, extraAttributesProcessor)
64+
65+
var keyValueAttributeTemplate = `
66+
- key: '%s'
67+
value: %s
68+
action: insert`
69+
for key, value := range ctx.Config.Tracing.ExtraSpanAttributes {
70+
processorsConfig += fmt.Sprintf(keyValueAttributeTemplate, key, value)
71+
}
72+
}
73+
74+
return processorsConfig
75+
}
76+
77+
func buildExportersConfig(ctx *common.RenderContext) string {
78+
return fmt.Sprintf(`exporters:
2379
otlp:
2480
endpoint: "api.honeycomb.io:443"
2581
headers:
2682
"x-honeycomb-team": "%s"
27-
"x-honeycomb-dataset": "%s"
83+
"x-honeycomb-dataset": "%s"`,
84+
ctx.Config.Tracing.HoneycombAPIKey, ctx.Config.Tracing.HoneycombDataset)
85+
}
2886

29-
extensions:
87+
func buildExtensionsConfig(ctx *common.RenderContext) string {
88+
return `extensions:
3089
health_check:
3190
pprof:
32-
zpages:
33-
service:
91+
zpages:`
92+
}
93+
94+
func buildServiceConfig(ctx *common.RenderContext) string {
95+
var serviceTemplate = `service:
3496
telemetry:
3597
logs:
3698
level: "debug"
3799
extensions: [health_check, pprof, zpages]
38100
pipelines:
39101
traces:
40-
receivers: [jaeger, otlp]
41-
processors: [ ]
42-
exporters: ["otlp"]
102+
receivers: [jaeger, otlp]
103+
processors: [%s]
104+
exporters: ["otlp"]
43105
`
106+
var processors = ""
44107

45-
func configMap(ctx *common.RenderContext) ([]runtime.Object, error) {
46-
return []runtime.Object{
47-
&corev1.ConfigMap{
48-
TypeMeta: metav1.TypeMeta{
49-
APIVersion: "v1",
50-
Kind: "ConfigMap",
51-
},
52-
ObjectMeta: metav1.ObjectMeta{
53-
Name: Name,
54-
Namespace: Namespace,
55-
Labels: common.Labels(Name, Component, App, Version),
56-
},
57-
Data: map[string]string{
58-
"collector.yaml": fmt.Sprintf(configMapData, ctx.Config.Tracing.HoneycombAPIKey, ctx.Config.Tracing.HoneycombDataset),
59-
},
60-
},
61-
}, nil
108+
if ctx.Config.Tracing.ExtraSpanAttributes != nil {
109+
processors = extraAttributesProcessor
110+
}
111+
112+
return fmt.Sprintf(serviceTemplate, processors)
62113
}

installer/pkg/config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ type Config struct {
9292
}
9393

9494
type Tracing struct {
95-
Install bool `json:"install"`
96-
HoneycombAPIKey string `json:"honeycombAPIKey,omitempty"`
97-
HoneycombDataset string `json:"honeycombDataset,omitempty"`
95+
Install bool `json:"install"`
96+
HoneycombAPIKey string `json:"honeycombAPIKey,omitempty"`
97+
HoneycombDataset string `json:"honeycombDataset,omitempty"`
98+
ExtraSpanAttributes map[string]string `json:"extraSpanAttributes,omitempty"`
9899
}
99100

100101
type Alerting struct {

0 commit comments

Comments
 (0)