Skip to content

Commit

Permalink
fix: panic when missing metrics or traces entries
Browse files Browse the repository at this point in the history
  • Loading branch information
dhontecillas committed May 24, 2024
1 parent f01fb8f commit c48a695
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lura/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@ 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
}
reportHeaders := false
if backendOpts.Traces != nil && backendOpts.Traces.ReportHeaders {
reportHeaders = true
}

gs := otelCfg.BackendOTEL(cfg)
urlPattern := kotelconfig.NormalizeURLPattern(cfg.URLPattern)
Expand All @@ -146,7 +152,7 @@ func BackendFactory(bf proxy.BackendFactory) proxy.BackendFactory {
attribute.String("krakend.endpoint.route", parentEndpoint),
attribute.String("krakend.endpoint.method", cfg.ParentEndpointMethod),
}
return middleware(gs, !backendOpts.Metrics.DisableStage, !backendOpts.Traces.DisableStage,
"backend", urlPattern, attrs, backendOpts.Traces.ReportHeaders)(next)
return middleware(gs, !metricsDisabled, !tracesDisabled,
"backend", urlPattern, attrs, reportHeaders)(next)
}
}

0 comments on commit c48a695

Please sign in to comment.