Skip to content
Closed
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions .chloggen/feat_zipkin-receiver-disable-keep-alives.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: zipkinreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add `disable_keep_alives` configuration option to control HTTP keep-alive behavior

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [42531]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
This allows users to disable HTTP keep-alive connections in the Zipkin receiver.
When disabled, the server will close connections after each request, which can
help with resource management in high-load scenarios or when working with certain
load balancers. The feature is disabled by default to maintain backward compatibility.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
9 changes: 9 additions & 0 deletions receiver/zipkinreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ receivers:
zipkin:
```

To disable HTTP keep-alive connections:

```yaml
receivers:
zipkin:
disable_keep_alives: true
```

The following settings are configurable:

- `endpoint` (default = localhost:9411): host:port on which the receiver is going to receive data.See our [security best practices doc](https://opentelemetry.io/docs/security/config-best-practices/#protect-against-denial-of-service-attacks) to understand how to set the endpoint in different environments. You can review the [full list of `ServerConfig`](https://github.com/open-telemetry/opentelemetry-collector/tree/main/config/confighttp).
- `parse_string_tags` (default = false): if enabled, the receiver will attempt to parse string tags/binary annotations into int/bool/float.
- `disable_keep_alives` (default = false): if true, HTTP keep-alive is disabled. When disabled, the server will close connections after each request.

## Advanced Configuration

Expand Down
2 changes: 2 additions & 0 deletions receiver/zipkinreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Config struct {
// If enabled the zipkin receiver will attempt to parse string tags/binary annotations into int/bool/float.
// Disabled by default
ParseStringTags bool `mapstructure:"parse_string_tags"`
// If true, HTTP keep-alive is disabled. By default, keep-alive is enabled.
DisableKeepAlives bool `mapstructure:"disable_keep_alives"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to be part of zipkin config and not confighttp.ServerConfig?

@ghost ghost Sep 7, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i now understood, after it will be added to confighttp.ServerConfig, this would make it available to all HTTP receivers not just Zipkin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, please open an issue in https://github.com/open-telemetry/opentelemetry-collector and link it here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually already opened a PR for this here: open-telemetry/opentelemetry-collector#13783


// prevent unkeyed literal initialization
_ struct{}
Expand Down
9 changes: 9 additions & 0 deletions receiver/zipkinreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func TestLoadConfig(t *testing.T) {
ParseStringTags: true,
},
},
{
id: component.NewIDWithName(metadata.Type, "disable_keep_alives"),
expected: &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: defaultHTTPEndpoint,
},
DisableKeepAlives: true,
},
},
}

for _, tt := range tests {
Expand Down
2 changes: 2 additions & 0 deletions receiver/zipkinreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ zipkin/customname:
endpoint: "localhost:8765"
zipkin/parse_strings:
parse_string_tags: true
zipkin/disable_keep_alives:
disable_keep_alives: true
5 changes: 5 additions & 0 deletions receiver/zipkinreceiver/trace_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (zr *zipkinReceiver) Start(ctx context.Context, host component.Host) error
return err
}

// Apply keep-alive setting to the HTTP server
if zr.config.DisableKeepAlives {
zr.server.SetKeepAlivesEnabled(false)
}

var listener net.Listener
listener, err = zr.config.ToListener(ctx)
if err != nil {
Expand Down
54 changes: 54 additions & 0 deletions receiver/zipkinreceiver/trace_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,57 @@ func TestFromBytesWithNoTimestamp(t *testing.T) {
assert.True(t, mapContainedKey)
assert.True(t, wasAbsent.Bool())
}

func TestKeepAliveConfig(t *testing.T) {
tests := []struct {
name string
disableKeepAlives bool
expectedEnabled bool
}{
{
name: "keep-alive enabled by default",
disableKeepAlives: false,
expectedEnabled: true,
},
{
name: "keep-alive disabled when configured",
disableKeepAlives: true,
expectedEnabled: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Get a random port for testing
listener, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
addr := listener.Addr().String()
require.NoError(t, listener.Close())

cfg := &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: addr,
},
DisableKeepAlives: tt.disableKeepAlives,
}

sink := &consumertest.TracesSink{}
r, err := newReceiver(cfg, sink, receivertest.NewNopSettings(metadata.Type))
require.NoError(t, err)

require.NoError(t, r.Start(t.Context(), componenttest.NewNopHost()))
t.Cleanup(func() {
require.NoError(t, r.Shutdown(t.Context()))
})

// Make a request to verify the server starts successfully
body := `[{"traceId":"1","id":"2","name":"test","timestamp":1234567890123456,"duration":1000000}]`
resp, err := http.Post(fmt.Sprintf("http://%s/api/v2/spans", addr), "application/json", bytes.NewBufferString(body))
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
assert.NotNil(t, r.server, "HTTP server should be initialized")
assert.Equal(t, tt.disableKeepAlives, cfg.DisableKeepAlives, "Configuration should match expected value")
})
}
}
Loading