mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
Fixes https://github.com/open-telemetry/opentelemetry-collector/issues/15178 `Config.Protocols` is now a named field instead of an anonymous embedded field according to our [coding guidelines](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/coding-guidelines.md#avoid-embedded-structs) Access to `cfg.GRPC` and `cfg.HTTP` must be updated to `cfg.Protocols.GRPC` and `cfg.Protocols.HTTP`.
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package otlpreceiver // import "go.opentelemetry.io/collector/receiver/otlpreceiver"
|
|
|
|
import (
|
|
"encoding"
|
|
"errors"
|
|
"fmt"
|
|
"net/url"
|
|
"path"
|
|
|
|
"go.opentelemetry.io/collector/component"
|
|
"go.opentelemetry.io/collector/config/configgrpc"
|
|
"go.opentelemetry.io/collector/config/confighttp"
|
|
"go.opentelemetry.io/collector/config/configoptional"
|
|
)
|
|
|
|
type SanitizedURLPath string
|
|
|
|
var _ encoding.TextUnmarshaler = (*SanitizedURLPath)(nil)
|
|
|
|
func (s *SanitizedURLPath) UnmarshalText(text []byte) error {
|
|
u, err := url.Parse(string(text))
|
|
if err != nil {
|
|
return fmt.Errorf("invalid HTTP URL path set for signal: %w", err)
|
|
}
|
|
|
|
if !path.IsAbs(u.Path) {
|
|
u.Path = "/" + u.Path
|
|
}
|
|
|
|
*s = SanitizedURLPath(u.Path)
|
|
return nil
|
|
}
|
|
|
|
type HTTPConfig struct {
|
|
ServerConfig confighttp.ServerConfig `mapstructure:",squash"`
|
|
|
|
// The URL path to receive traces on. If omitted "/v1/traces" will be used.
|
|
TracesURLPath SanitizedURLPath `mapstructure:"traces_url_path,omitempty"`
|
|
|
|
// The URL path to receive metrics on. If omitted "/v1/metrics" will be used.
|
|
MetricsURLPath SanitizedURLPath `mapstructure:"metrics_url_path,omitempty"`
|
|
|
|
// The URL path to receive logs on. If omitted "/v1/logs" will be used.
|
|
LogsURLPath SanitizedURLPath `mapstructure:"logs_url_path,omitempty"`
|
|
|
|
// prevent unkeyed literal initialization
|
|
_ struct{}
|
|
}
|
|
|
|
// Protocols is the configuration for the supported protocols.
|
|
type Protocols struct {
|
|
GRPC configoptional.Optional[configgrpc.ServerConfig] `mapstructure:"grpc"`
|
|
HTTP configoptional.Optional[HTTPConfig] `mapstructure:"http"`
|
|
// prevent unkeyed literal initialization
|
|
_ struct{}
|
|
}
|
|
|
|
// Config defines configuration for OTLP receiver.
|
|
type Config struct {
|
|
// Protocols is the configuration for the supported protocols, currently gRPC and HTTP (Proto and JSON).
|
|
Protocols Protocols `mapstructure:"protocols"`
|
|
// prevent unkeyed literal initialization
|
|
_ struct{}
|
|
}
|
|
|
|
var _ component.Config = (*Config)(nil)
|
|
|
|
// Validate checks the receiver configuration is valid
|
|
func (cfg *Config) Validate() error {
|
|
if !cfg.Protocols.GRPC.HasValue() && !cfg.Protocols.HTTP.HasValue() {
|
|
return errors.New("must specify at least one protocol when using the OTLP receiver")
|
|
}
|
|
return nil
|
|
}
|