Dial creates client connections and clients based on config. Dial is expected to be called only once.
(ctx context.Context, opts ...grpc.DialOption)
| 45 | // Dial creates client connections and clients based on config. |
| 46 | // Dial is expected to be called only once. |
| 47 | func (f *Forwarder) Dial(ctx context.Context, opts ...grpc.DialOption) error { |
| 48 | f.mu.Lock() |
| 49 | defer f.mu.Unlock() |
| 50 | |
| 51 | if f.initialized { |
| 52 | return errors.New("already initialized") |
| 53 | } |
| 54 | |
| 55 | connections := make(map[string]*grpc.ClientConn) |
| 56 | clients := make(map[string]ptraceotlp.GRPCClient, len(f.cfg.Endpoints)) |
| 57 | for _, endpoint := range f.cfg.Endpoints { |
| 58 | client, conn, err := f.newTraceOTLPGRPCClientAndConn(ctx, endpoint, f.cfg.TLS, opts...) |
| 59 | if err != nil { |
| 60 | return fmt.Errorf("failed to create new trace otlp grpc client: %w", err) |
| 61 | } |
| 62 | |
| 63 | connections[endpoint] = conn |
| 64 | clients[endpoint] = client |
| 65 | } |
| 66 | |
| 67 | f.connections = connections |
| 68 | f.clients = clients |
| 69 | f.initialized = true |
| 70 | |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | func (f *Forwarder) ForwardTraces(ctx context.Context, traces ptrace.Traces) error { |
| 75 | req := ptraceotlp.NewExportRequestFromTraces(traces) |