|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package otlploghttp // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp" |
| 5 | + |
| 6 | +import ( |
| 7 | + "crypto/tls" |
| 8 | + "net/http" |
| 9 | + "net/url" |
| 10 | + "time" |
| 11 | +) |
| 12 | + |
| 13 | +// Option applies an option to the Exporter. |
| 14 | +type Option interface { |
| 15 | + applyHTTPOption(config) config |
| 16 | +} |
| 17 | + |
| 18 | +type config struct { |
| 19 | + // TODO: implement. |
| 20 | +} |
| 21 | + |
| 22 | +func newConfig(options []Option) config { |
| 23 | + var c config |
| 24 | + for _, opt := range options { |
| 25 | + c = opt.applyHTTPOption(c) |
| 26 | + } |
| 27 | + return c |
| 28 | +} |
| 29 | + |
| 30 | +// WithEndpoint sets the target endpoint the Exporter will connect to. This |
| 31 | +// endpoint is specified as a host and optional port, no path or scheme should |
| 32 | +// be included (see WithInsecure and WithURLPath). |
| 33 | +// |
| 34 | +// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT |
| 35 | +// environment variable is set, and this option is not passed, that variable |
| 36 | +// value will be used. If both are set, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT |
| 37 | +// will take precedence. |
| 38 | +// |
| 39 | +// By default, if an environment variable is not set, and this option is not |
| 40 | +// passed, "localhost:4318" will be used. |
| 41 | +func WithEndpoint(endpoint string) Option { |
| 42 | + // TODO: implement. |
| 43 | + return nil |
| 44 | +} |
| 45 | + |
| 46 | +// WithEndpointURL sets the target endpoint URL the Exporter will connect to. |
| 47 | +// |
| 48 | +// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT |
| 49 | +// environment variable is set, and this option is not passed, that variable |
| 50 | +// value will be used. If both are set, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT |
| 51 | +// will take precedence. |
| 52 | +// |
| 53 | +// If both this option and WithEndpoint are used, the last used option will |
| 54 | +// take precedence. |
| 55 | +// |
| 56 | +// If an invalid URL is provided, the default value will be kept. |
| 57 | +// |
| 58 | +// By default, if an environment variable is not set, and this option is not |
| 59 | +// passed, "localhost:4318" will be used. |
| 60 | +func WithEndpointURL(u string) Option { |
| 61 | + // TODO: implement. |
| 62 | + return nil |
| 63 | +} |
| 64 | + |
| 65 | +// Compression describes the compression used for payloads sent to the |
| 66 | +// collector. |
| 67 | +type Compression int |
| 68 | + |
| 69 | +// WithCompression sets the compression strategy the Exporter will use to |
| 70 | +// compress the HTTP body. |
| 71 | +// |
| 72 | +// If the OTEL_EXPORTER_OTLP_COMPRESSION or |
| 73 | +// OTEL_EXPORTER_OTLP_LOGS_COMPRESSION environment variable is set, and |
| 74 | +// this option is not passed, that variable value will be used. That value can |
| 75 | +// be either "none" or "gzip". If both are set, |
| 76 | +// OTEL_EXPORTER_OTLP_LOGS_COMPRESSION will take precedence. |
| 77 | +// |
| 78 | +// By default, if an environment variable is not set, and this option is not |
| 79 | +// passed, no compression strategy will be used. |
| 80 | +func WithCompression(compression Compression) Option { |
| 81 | + // TODO: implement. |
| 82 | + return nil |
| 83 | +} |
| 84 | + |
| 85 | +// WithURLPath sets the URL path the Exporter will send requests to. |
| 86 | +// |
| 87 | +// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT |
| 88 | +// environment variable is set, and this option is not passed, the path |
| 89 | +// contained in that variable value will be used. If both are set, |
| 90 | +// OTEL_EXPORTER_OTLP_LOGS_ENDPOINT will take precedence. |
| 91 | +// |
| 92 | +// By default, if an environment variable is not set, and this option is not |
| 93 | +// passed, "/v1/logs" will be used. |
| 94 | +func WithURLPath(urlPath string) Option { |
| 95 | + // TODO: implement. |
| 96 | + return nil |
| 97 | +} |
| 98 | + |
| 99 | +// WithTLSClientConfig sets the TLS configuration the Exporter will use for |
| 100 | +// HTTP requests. |
| 101 | +// |
| 102 | +// If the OTEL_EXPORTER_OTLP_CERTIFICATE or |
| 103 | +// OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE environment variable is set, and |
| 104 | +// this option is not passed, that variable value will be used. The value will |
| 105 | +// be parsed the filepath of the TLS certificate chain to use. If both are |
| 106 | +// set, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE will take precedence. |
| 107 | +// |
| 108 | +// By default, if an environment variable is not set, and this option is not |
| 109 | +// passed, the system default configuration is used. |
| 110 | +func WithTLSClientConfig(tlsCfg *tls.Config) Option { |
| 111 | + // TODO: implement. |
| 112 | + return nil |
| 113 | +} |
| 114 | + |
| 115 | +// WithInsecure disables client transport security for the Exporter's HTTP |
| 116 | +// connection. |
| 117 | +// |
| 118 | +// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT |
| 119 | +// environment variable is set, and this option is not passed, that variable |
| 120 | +// value will be used to determine client security. If the endpoint has a |
| 121 | +// scheme of "http" or "unix" client security will be disabled. If both are |
| 122 | +// set, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT will take precedence. |
| 123 | +// |
| 124 | +// By default, if an environment variable is not set, and this option is not |
| 125 | +// passed, client security will be used. |
| 126 | +func WithInsecure() Option { |
| 127 | + // TODO: implement. |
| 128 | + return nil |
| 129 | +} |
| 130 | + |
| 131 | +// WithHeaders will send the provided headers with each HTTP requests. |
| 132 | +// |
| 133 | +// If the OTEL_EXPORTER_OTLP_HEADERS or OTEL_EXPORTER_OTLP_LOGS_HEADERS |
| 134 | +// environment variable is set, and this option is not passed, that variable |
| 135 | +// value will be used. The value will be parsed as a list of key value pairs. |
| 136 | +// These pairs are expected to be in the W3C Correlation-Context format |
| 137 | +// without additional semi-colon delimited metadata (i.e. "k1=v1,k2=v2"). If |
| 138 | +// both are set, OTEL_EXPORTER_OTLP_LOGS_HEADERS will take precedence. |
| 139 | +// |
| 140 | +// By default, if an environment variable is not set, and this option is not |
| 141 | +// passed, no user headers will be set. |
| 142 | +func WithHeaders(headers map[string]string) Option { |
| 143 | + // TODO: implement. |
| 144 | + return nil |
| 145 | +} |
| 146 | + |
| 147 | +// WithTimeout sets the max amount of time an Exporter will attempt an export. |
| 148 | +// |
| 149 | +// This takes precedence over any retry settings defined by WithRetry. Once |
| 150 | +// this time limit has been reached the export is abandoned and the log data is |
| 151 | +// dropped. |
| 152 | +// |
| 153 | +// If the OTEL_EXPORTER_OTLP_TIMEOUT or OTEL_EXPORTER_OTLP_LOGS_TIMEOUT |
| 154 | +// environment variable is set, and this option is not passed, that variable |
| 155 | +// value will be used. The value will be parsed as an integer representing the |
| 156 | +// timeout in milliseconds. If both are set, |
| 157 | +// OTEL_EXPORTER_OTLP_LOGS_TIMEOUT will take precedence. |
| 158 | +// |
| 159 | +// By default, if an environment variable is not set, and this option is not |
| 160 | +// passed, a timeout of 10 seconds will be used. |
| 161 | +func WithTimeout(duration time.Duration) Option { |
| 162 | + // TODO: implement. |
| 163 | + return nil |
| 164 | +} |
| 165 | + |
| 166 | +// RetryConfig defines configuration for retrying the export of log data that |
| 167 | +// failed. |
| 168 | +type RetryConfig struct { |
| 169 | + // TODO: implement. |
| 170 | +} |
| 171 | + |
| 172 | +// WithRetry sets the retry policy for transient retryable errors that are |
| 173 | +// returned by the target endpoint. |
| 174 | +// |
| 175 | +// If the target endpoint responds with not only a retryable error, but |
| 176 | +// explicitly returns a backoff time in the response, that time will take |
| 177 | +// precedence over these settings. |
| 178 | +// |
| 179 | +// If unset, the default retry policy will be used. It will retry the export |
| 180 | +// 5 seconds after receiving a retryable error and increase exponentially |
| 181 | +// after each error for no more than a total time of 1 minute. |
| 182 | +func WithRetry(rc RetryConfig) Option { |
| 183 | + // TODO: implement. |
| 184 | + return nil |
| 185 | +} |
| 186 | + |
| 187 | +// HTTPTransportProxyFunc is a function that resolves which URL to use as proxy |
| 188 | +// for a given request. This type is compatible with http.Transport.Proxy and |
| 189 | +// can be used to set a custom proxy function to the OTLP HTTP client. |
| 190 | +type HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) |
| 191 | + |
| 192 | +// WithProxy sets the Proxy function the client will use to determine the |
| 193 | +// proxy to use for an HTTP request. If this option is not used, the client |
| 194 | +// will use [http.ProxyFromEnvironment]. |
| 195 | +func WithProxy(pf HTTPTransportProxyFunc) Option { |
| 196 | + // TODO: implement. |
| 197 | + return nil |
| 198 | +} |
0 commit comments