Skip to content

Commit

Permalink
Improve logging of component start errors (#10440)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Improved logging of component start errors, so the log lines appear
where they chronologically happen, rather than at the end. They also use
the component logger, which makes them look nicer.

Output before change:
```text
2024-06-19T14:15:30.822+0200    info    [email protected]/service.go:115 Setting up own telemetry...
2024-06-19T14:15:30.822+0200    info    [email protected]/telemetry.go:96        Serving metrics {"address": ":8888", "level": "Normal"}
2024-06-19T14:15:30.823+0200    info    [email protected]/service.go:182 Starting otelcorecol... {"Version": "0.103.0-dev", "NumCPU": 32}
2024-06-19T14:15:30.823+0200    info    extensions/extensions.go:35     Starting extensions...
2024-06-19T14:15:30.823+0200    info    [email protected]/service.go:245 Starting shutdown...
2024-06-19T14:15:30.823+0200    info    extensions/extensions.go:61     Stopping extensions...
2024-06-19T14:15:30.823+0200    info    [email protected]/service.go:259 Shutdown complete.
Error: cannot start pipelines: failed to resolve authenticator "oauth2client": authenticator not found
2024/06/19 14:15:30 collector server run finished with error: cannot start pipelines: failed to resolve authenticator "oauth2client": authenticator not found
```

Output after change:
```
2024-06-19T14:25:18.324+0200    info    [email protected]/service.go:115 Setting up own telemetry...
2024-06-19T14:25:18.325+0200    info    [email protected]/telemetry.go:96        Serving metrics {"address": ":8888", "level": "Normal"}
2024-06-19T14:25:18.326+0200    info    [email protected]/service.go:182 Starting otelcorecol... {"Version": "0.103.0-dev", "NumCPU": 32}
2024-06-19T14:25:18.326+0200    info    extensions/extensions.go:35     Starting extensions...
2024-06-19T14:25:18.326+0200    error   graph/graph.go:428      Failed to start component       {"error": "failed to resolve authenticator \"oauth2client\": authenticator not found", "type": "Exporter", "id": "otlphttp"}
2024-06-19T14:25:18.326+0200    info    [email protected]/service.go:245 Starting shutdown...
2024-06-19T14:25:18.326+0200    info    extensions/extensions.go:61     Stopping extensions...
2024-06-19T14:25:18.326+0200    info    [email protected]/service.go:259 Shutdown complete.
Error: cannot start pipelines: failed to resolve authenticator "oauth2client": authenticator not found
2024/06/19 14:25:18 collector server run finished with error: cannot start pipelines: failed to resolve authenticator "oauth2client": authenticator not found

```

We've added the following line:
```
2024-06-19T14:25:18.326+0200    error   graph/graph.go:428      Failed to start component       {"error": "failed to resolve authenticator \"oauth2client\": authenticator not found", "type": "Exporter", "id": "otlphttp"}
```

For extensions, the new line looks like so:
```
2024-06-25T16:59:18.513+0200    error    extensions/extensions.go:54     Failed to start extension      {"kind": "extension", "name": "memory_limiter", "error": "failed to get memory limit"}
```

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #7078
  • Loading branch information
swiatekm authored Jul 18, 2024
1 parent 2d51bc4 commit fbadc23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions service/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sort"

"go.uber.org/multierr"
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
Expand Down Expand Up @@ -46,6 +47,8 @@ func (bes *Extensions) Start(ctx context.Context, host component.Host) error {
instanceID,
component.NewPermanentErrorEvent(err),
)
// We log with zap.AddStacktrace(zap.DPanicLevel) to avoid adding the stack trace to the error log
extLogger.WithOptions(zap.AddStacktrace(zap.DPanicLevel)).Error("Failed to start extension", zap.Error(err))
return err
}
bes.telemetry.Status.ReportOKIfStarting(instanceID)
Expand Down
9 changes: 9 additions & 0 deletions service/internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

"go.uber.org/multierr"
"go.uber.org/zap"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/topo"
Expand Down Expand Up @@ -70,6 +71,7 @@ func Build(ctx context.Context, set Settings) (*Graph, error) {
componentGraph: simple.NewDirectedGraph(),
pipelines: make(map[component.ID]*pipelineNodes, len(set.PipelineConfigs)),
instanceIDs: make(map[int64]*component.InstanceID),
telemetry: set.Telemetry,
}
for pipelineID := range set.PipelineConfigs {
pipelines.pipelines[pipelineID] = &pipelineNodes{
Expand Down Expand Up @@ -423,6 +425,13 @@ func (g *Graph) StartAll(ctx context.Context, host component.Host, reporter stat
instanceID,
component.NewPermanentErrorEvent(compErr),
)
// We log with zap.AddStacktrace(zap.DPanicLevel) to avoid adding the stack trace to the error log
g.telemetry.Logger.WithOptions(zap.AddStacktrace(zap.DPanicLevel)).
Error("Failed to start component",
zap.Error(compErr),
zap.String("type", instanceID.Kind.String()),
zap.String("id", instanceID.ID.String()),
)
return compErr
}

Expand Down

0 comments on commit fbadc23

Please sign in to comment.