Skip to content
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

fix: panic when missing metrics or traces entries #30

Merged
merged 3 commits into from
Jul 2, 2024
Merged
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
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)
}
}
Loading