This commit is contained in:
parent
042fd221c4
commit
b4412a461f
@ -81,9 +81,9 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
l := zerolog.Ctx(aw.appCtx)
|
l := zerolog.Ctx(aw.appCtx)
|
||||||
tracer := otel.GetTracer(aw.appCtx, p.Name()+".http.handler")
|
tracer := otel.GetTracer(aw.appCtx, p.Name()+".http.handler")
|
||||||
|
|
||||||
ctx, span := tracer.Start(r.Context(), p.Name()+".update")
|
ctx, updateSpan := tracer.Start(r.Context(), p.Name()+".update")
|
||||||
span.SetAttributes(attribute.String("provider", p.Name()))
|
updateSpan.SetAttributes(attribute.String("provider", p.Name()))
|
||||||
defer span.End()
|
defer updateSpan.End()
|
||||||
|
|
||||||
l.Trace().Str("p", p.Name()).
|
l.Trace().Str("p", p.Name()).
|
||||||
Any("query", r.URL.Query()).Send()
|
Any("query", r.URL.Query()).Send()
|
||||||
@ -92,8 +92,8 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
update, err := p.ReqToWeather(ctx, r)
|
update, err := p.ReqToWeather(ctx, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Err(err).Send()
|
l.Err(err).Send()
|
||||||
span.RecordError(err)
|
updateSpan.RecordError(err)
|
||||||
span.SetStatus(codes.Error,
|
updateSpan.SetStatus(codes.Error,
|
||||||
fmt.Sprintf("failed to handle %s update: %s",
|
fmt.Sprintf("failed to handle %s update: %s",
|
||||||
p.Name(), err.Error()))
|
p.Name(), err.Error()))
|
||||||
|
|
||||||
@ -106,13 +106,7 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
aw.enrichUpdate(ctx, p, update)
|
aw.enrichUpdate(ctx, p, update)
|
||||||
|
|
||||||
// Update metrics
|
// Update metrics
|
||||||
ctx, updateSpan := tracer.Start(ctx, p.Name()+".update.metrics")
|
aw.metricsUpdate(ctx, p, update)
|
||||||
if aw.metrics == nil {
|
|
||||||
aw.InitMetrics()
|
|
||||||
}
|
|
||||||
aw.metrics.Update(update)
|
|
||||||
updateSpan.SetStatus(codes.Ok, "")
|
|
||||||
updateSpan.End()
|
|
||||||
|
|
||||||
l.Debug().
|
l.Debug().
|
||||||
Str("provider", p.Name()).
|
Str("provider", p.Name()).
|
||||||
@ -128,6 +122,24 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aw *AmbientWeather) metricsUpdate(
|
||||||
|
ctx context.Context,
|
||||||
|
p provider.AmbientProvider,
|
||||||
|
update *weather.WeatherUpdate,
|
||||||
|
) {
|
||||||
|
tracer := otel.GetTracer(aw.appCtx, p.Name()+".http.handler")
|
||||||
|
_, metricsSpan := tracer.Start(ctx, p.Name()+".update.metrics")
|
||||||
|
|
||||||
|
if aw.metrics == nil {
|
||||||
|
aw.InitMetrics()
|
||||||
|
}
|
||||||
|
|
||||||
|
aw.metrics.Update(update)
|
||||||
|
|
||||||
|
metricsSpan.SetStatus(codes.Ok, "")
|
||||||
|
metricsSpan.End()
|
||||||
|
}
|
||||||
|
|
||||||
func (aw *AmbientWeather) enrichUpdate(
|
func (aw *AmbientWeather) enrichUpdate(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
p provider.AmbientProvider,
|
p provider.AmbientProvider,
|
||||||
@ -137,7 +149,7 @@ func (aw *AmbientWeather) enrichUpdate(
|
|||||||
|
|
||||||
// Calculate any fields that may be missing
|
// Calculate any fields that may be missing
|
||||||
// such as dew point and wind chill
|
// such as dew point and wind chill
|
||||||
ctx, enrichSpan := tracer.Start(ctx, p.Name()+".update.enrich")
|
_, enrichSpan := tracer.Start(ctx, p.Name()+".update.enrich")
|
||||||
defer enrichSpan.End()
|
defer enrichSpan.End()
|
||||||
|
|
||||||
update.Enrich()
|
update.Enrich()
|
||||||
@ -161,7 +173,7 @@ func (aw *AmbientWeather) proxyUpdate(
|
|||||||
tracer := otel.GetTracer(aw.appCtx, p.Name()+".http.handler")
|
tracer := otel.GetTracer(aw.appCtx, p.Name()+".http.handler")
|
||||||
station := update.StationConfig
|
station := update.StationConfig
|
||||||
|
|
||||||
ctx, proxySpan := tracer.Start(ctx, p.Name()+".update.proxy", trace.WithAttributes(
|
_, proxySpan := tracer.Start(ctx, p.Name()+".update.proxy", trace.WithAttributes(
|
||||||
attribute.Bool("proxyToWunderground", station.ProxyToWunderground),
|
attribute.Bool("proxyToWunderground", station.ProxyToWunderground),
|
||||||
attribute.Bool("proxyToAWN", station.ProxyToAWN),
|
attribute.Bool("proxyToAWN", station.ProxyToAWN),
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user