Skip to content

Make it possible to add new span attributes through Otel-Collector #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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