Skip to content

Commit

Permalink
Merge pull request #30 from krakend/fix_backend_level_options
Browse files Browse the repository at this point in the history
fix: panic when missing metrics or traces entries
  • Loading branch information
dhontecillas authored Jul 2, 2024
2 parents 18271f3 + 552fe65 commit d24a596
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lura/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ func BackendFactory(bf proxy.BackendFactory) proxy.BackendFactory {
return next
}
backendOpts := otelCfg.BackendOpts(cfg)
if backendOpts.Metrics.DisableStage && backendOpts.Traces.DisableStage {
metricsDisabled := backendOpts != nil && backendOpts.Metrics != nil && backendOpts.Metrics.DisableStage
tracesDisabled := backendOpts != nil && backendOpts.Traces != nil && backendOpts.Traces.DisableStage
if metricsDisabled && tracesDisabled {
return next
}

Expand All @@ -171,19 +173,25 @@ func BackendFactory(bf proxy.BackendFactory) proxy.BackendFactory {
// Add configured static attributes
metricsAttrs := attrs
tracesAttrs := attrs
for _, kv := range backendOpts.Metrics.StaticAttributes {
if len(kv.Key) > 0 && len(kv.Value) > 0 {
metricsAttrs = append(metricsAttrs, attribute.String(kv.Key, kv.Value))
if backendOpts.Metrics != nil {
for _, kv := range backendOpts.Metrics.StaticAttributes {
if len(kv.Key) > 0 && len(kv.Value) > 0 {
metricsAttrs = append(metricsAttrs, attribute.String(kv.Key, kv.Value))
}
}
}

for _, kv := range backendOpts.Traces.StaticAttributes {
if len(kv.Key) > 0 && len(kv.Value) > 0 {
tracesAttrs = append(tracesAttrs, attribute.String(kv.Key, kv.Value))
reportHeaders := false
if backendOpts.Traces != nil {
reportHeaders = backendOpts.Traces.ReportHeaders
for _, kv := range backendOpts.Traces.StaticAttributes {
if len(kv.Key) > 0 && len(kv.Value) > 0 {
tracesAttrs = append(tracesAttrs, attribute.String(kv.Key, kv.Value))
}
}
}

return middleware(gs, !backendOpts.Metrics.DisableStage, !backendOpts.Traces.DisableStage,
"backend", urlPattern, metricsAttrs, tracesAttrs, backendOpts.Traces.ReportHeaders)(next)
return middleware(gs, !metricsDisabled, !tracesDisabled,
"backend", urlPattern, metricsAttrs, tracesAttrs, reportHeaders)(next)
}
}

0 comments on commit d24a596

Please sign in to comment.