Skip to content

Commit a51f292

Browse files
authored
Add changelog for confighttp ErrorLog update (#12172)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Added Zap as the default error logger in `confighttp.ToServer()` to ensure consistency in logging and to prevent errors from being printed using a different logger. This change configures the `ErrorLog` field of the `http.Server` to use a logger backed by Zap, which is initialized with the provided logger in `TelemetrySettings`. If the logger creation fails, the function now returns `nil, err` to prevent any undefined behavior from occurring due to an incomplete setup of the logger. <!-- Issue number if applicable --> #### Link to tracking issue Fixes #11820 <!--Describe the documentation added.--> #### Documentation Updated the changelog with information regarding the new default error logger for `confighttp`. Added details to internal documentation to reflect the change and ensure proper usage of the new logging system in server configuration.
1 parent c400731 commit a51f292

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
change_type: bug_fix
2+
3+
component: confighttp
4+
5+
note: "confighttp.ToServer now sets ErrorLog with a default logger backed by Zap"
6+
7+
issues: [11820]
8+
9+
subtext: |
10+
11+
This change ensures that the http.Server's ErrorLog is correctly set using Zap's logger at the error level, addressing the issue of error logs being printed using a different logger.
12+
13+
change_logs: []

config/confighttp/confighttp.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/rs/cors"
1919
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2020
"go.opentelemetry.io/otel"
21+
"go.uber.org/zap"
22+
"go.uber.org/zap/zapcore"
2123
"golang.org/x/net/http2"
2224
"golang.org/x/net/publicsuffix"
2325

@@ -489,15 +491,21 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin
489491
includeMetadata: hss.IncludeMetadata,
490492
}
491493

494+
errorLog, err := zap.NewStdLogAt(settings.Logger, zapcore.ErrorLevel)
495+
if err != nil {
496+
return nil, err // If an error occurs while creating the logger, return nil and the error
497+
}
498+
492499
server := &http.Server{
493500
Handler: handler,
494501
ReadTimeout: hss.ReadTimeout,
495502
ReadHeaderTimeout: hss.ReadHeaderTimeout,
496503
WriteTimeout: hss.WriteTimeout,
497504
IdleTimeout: hss.IdleTimeout,
505+
ErrorLog: errorLog,
498506
}
499507

500-
return server, nil
508+
return server, err
501509
}
502510

503511
func responseHeadersHandler(handler http.Handler, headers map[string]configopaque.String) http.Handler {

0 commit comments

Comments
 (0)