Files
telemetry/config/confighttp/confighttp_example_test.go
a46b19a87d confighttp: add support for binding unix sockets (#14248)
#### Description

Embed `confignet.AddrConfig` in `confighttp.ServerConfig`, replacing the
`Endpoint` field. This introduces the "transport" config attribute,
which can be set to "unix" for binding a Unix domain socket.

#### Link to tracking issue

Fixes #8752
Fixes #14187

#### Testing

```bash
$ ./bin/otelcorecol_linux_amd64 \
    --config examples/local/otel-config.yaml \
    --set receivers::otlp::protocols::http::transport=unix \
    --set receivers::otlp::protocols::http::endpoint=\"@otlphttp\"
```

```bash
$ curl --abstract-unix-socket otlphttp http://testing.invalid:1234/v1/traces
405 method not allowed, supported: [POST]
```

#### Documentation

Updated README.md

---------

Co-authored-by: Antoine Toulme <[email protected]>
2026-01-14 11:54:55 +00:00

37 lines
760 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package confighttp
import (
"context"
"net/http"
"go.opentelemetry.io/collector/component/componenttest"
)
func ExampleServerConfig() {
settings := NewDefaultServerConfig()
settings.NetAddr.Endpoint = "localhost:443"
// Typically obtained as an argument of Component.Start()
host := componenttest.NewNopHost()
s, err := settings.ToServer(
context.Background(),
host.GetExtensions(),
componenttest.NewNopTelemetrySettings(),
http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
if err != nil {
panic(err)
}
l, err := settings.ToListener(context.Background())
if err != nil {
panic(err)
}
if err = s.Serve(l); err != nil {
panic(err)
}
}