mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-02 23:31:08 +08:00
The `http.Client.Transport` created in `newWebClient` wraps a chain of `http.RoundTripper` over an underlying `http.Transport`. Since we cannot guarantee that each `http.RoundTipper` has a `CloseIdleConnections` method the usage of `defer clt.CloseIdleConnections()` does not guarantee that the http connections created during Find/Ping/etc are closed. To prevent leaking connections implementations of `http.RoundTripper` have added a `CloseIdleConnections` method added that forwards the request on to the wrapped interface. The `otelhttp.Transport` does not implement this method either so care has been taken to wrap it in a `http.RoundTripper` which will call the root transport in `enforceCloseIdleConnections`. An upstream issue has been filed with otelhttp: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/3543 to get the method added to their `Transport` implementation. This wasn't noticed prior to upgrading to go1.20 becuase prior to [this](https://github.com/golang/go/commit/4e7e7ae1406c70d9cc0809ec11105a55a60a0b70) commit the `ReadHeaderTimeout` set on the Proxy web api http.Server would cause the connection to appear idle and get terminated by the server. `TestWebClientClosesIdleConnections` was added to capture the leak in connections as reported in #22757 and prevent any regressions.
50 lines
1.9 KiB
Go
50 lines
1.9 KiB
Go
// Copyright 2022 Gravitational, Inc
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package tracing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/propagation"
|
|
oteltrace "go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// PropagationContext contains tracing information to be passed across service boundaries
|
|
type PropagationContext map[string]string
|
|
|
|
// TraceParent is the name of the header or query parameter that contains
|
|
// tracing context across service boundaries.
|
|
const TraceParent = "traceparent"
|
|
|
|
// PropagationContextFromContext creates a PropagationContext from the given context.Context. If the context
|
|
// does not contain any tracing information, the PropagationContext will be empty.
|
|
func PropagationContextFromContext(ctx context.Context, opts ...Option) PropagationContext {
|
|
carrier := propagation.MapCarrier{}
|
|
NewConfig(opts).TextMapPropagator.Inject(ctx, &carrier)
|
|
return PropagationContext(carrier)
|
|
}
|
|
|
|
// WithPropagationContext injects any tracing information from the given PropagationContext into the
|
|
// given context.Context.
|
|
func WithPropagationContext(ctx context.Context, pc PropagationContext, opts ...Option) context.Context {
|
|
return NewConfig(opts).TextMapPropagator.Extract(ctx, propagation.MapCarrier(pc))
|
|
}
|
|
|
|
// DefaultProvider returns the global default TracerProvider.
|
|
func DefaultProvider() oteltrace.TracerProvider {
|
|
return otel.GetTracerProvider()
|
|
}
|