-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add otel support #25862
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
Draft
xBlaz3kx
wants to merge
2
commits into
evcc-io:master
Choose a base branch
from
xBlaz3kx:feat/observability
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: add otel support #25862
+217
−8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The
Config.Protocolcomment says gRPC is the default, butInitcurrently usescfg.Protocoldirectly and will treat an empty string as an error; either defaultprotocol := cfg.Protocol; if protocol == "" { protocol = "grpc" }or update the comment/config to reflect that it’s required. - The
Config.Headersfield is defined but never used when constructing the OTLP exporters; if you intend to support custom headers (for auth, tenancy, etc.), plumb these intootlptracegrpc.New/otlptracehttp.New, or remove the field for now to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `Config.Protocol` comment says gRPC is the default, but `Init` currently uses `cfg.Protocol` directly and will treat an empty string as an error; either default `protocol := cfg.Protocol; if protocol == "" { protocol = "grpc" }` or update the comment/config to reflect that it’s required.
- The `Config.Headers` field is defined but never used when constructing the OTLP exporters; if you intend to support custom headers (for auth, tenancy, etc.), plumb these into `otlptracegrpc.New` / `otlptracehttp.New`, or remove the field for now to avoid confusion.
## Individual Comments
### Comment 1
<location> `util/otel/otel.go:44-45` </location>
<code_context>
+ var exporter sdktrace.SpanExporter
+ var err error
+
+ // Default to grpc if protocol not specified
+ protocol := cfg.Protocol
+ switch protocol {
+ case "grpc":
</code_context>
<issue_to_address>
**issue (bug_risk):** The protocol comment and implementation diverge; empty protocol currently fails instead of defaulting to gRPC.
Because `protocol := cfg.Protocol` goes straight into the `switch`, an empty string will fall into `default` and return an error, effectively making `Protocol` mandatory whenever otel is enabled. To match the comment, initialize a default first, e.g.:
```go
actionProtocol := cfg.Protocol
if actionProtocol == "" {
actionProtocol = "grpc"
}
```
Also consider using the resolved value (e.g., `actionProtocol`) in the final log line instead of the raw config field.
</issue_to_address>
### Comment 2
<location> `util/otel/otel.go:28` </location>
<code_context>
+ Endpoint string `json:"endpoint"`
+ Protocol string `json:"protocol"` // "grpc" or "http"
+ Insecure bool `json:"insecure"`
+ Headers map[string]string
+}
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Configured OTLP headers are accepted but never applied to the exporters.
The `Headers` field is exposed on `Config` but never used when creating the gRPC/HTTP exporters. If it’s meant for auth/metadata, it should be passed into the exporter options (e.g., `otlptracegrpc.WithHeaders(cfg.Headers)` / `otlptracehttp.WithHeaders(cfg.Headers)`). Otherwise, consider removing it from `Config` to avoid a misleading, no-op setting.
Suggested implementation:
```golang
// Config holds OpenTelemetry configuration
type Config struct {
Enabled bool `json:"enabled"`
Endpoint string `json:"endpoint"`
Protocol string `json:"protocol"` // "grpc" or "http"
Insecure bool `json:"insecure"`
Headers map[string]string `json:"headers,omitempty"`
```
```golang
opts := []otlptracegrpc.Option{
otlptracegrpc.WithEndpoint(cfg.Endpoint),
}
if len(cfg.Headers) > 0 {
opts = append(opts, otlptracegrpc.WithHeaders(cfg.Headers))
}
```
```golang
opts := []otlptracehttp.Option{
otlptracehttp.WithEndpoint(cfg.Endpoint),
}
if len(cfg.Headers) > 0 {
opts = append(opts, otlptracehttp.WithHeaders(cfg.Headers))
}
```
If the option slices for gRPC/HTTP exporters are named differently or constructed inline (e.g., directly in `otlptracegrpc.New` / `otlptracehttp.New` calls), you’ll need to adapt the `SEARCH` patterns accordingly and still ensure that `otlptracegrpc.WithHeaders(cfg.Headers)` and `otlptracehttp.WithHeaders(cfg.Headers)` are appended to the respective option lists whenever `len(cfg.Headers) > 0`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
4686903 to
e42339d
Compare
e42339d to
f5fe145
Compare
f5fe145 to
065a0ed
Compare
Member
|
+1% binary size and quite some additional dependencies. Apart from being an interesting technology- I'd like to better understand how one would actually utilize this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Initial OpenTelemetry support (config, init, http API tracing).
Useful for complex scenario debugging (instead of relying solely on logs).
Ran it with the following compose:
This section should also be added to
evcc.yaml