open-telemetry / open-telemetry/opentelemetry-cpp

Update OtlpGrpcClientOptions to populate options for gRPC client sharing

Open
#4,239 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Stale triage/accepted
Dominant language
C++
Stars
1.4k
Forks
632
Avg merge
1d 13h
Merged PRs (30d)
75

Description

Problem:

OtlpGrpcClientOptions has only a = default constructor and it initializes all options to null or c++ default values. The exporter specific options classes read environment variables and set the otel-spec defined defaults. This makes it challenging to construct a standalone OtlpGrpcClient with spec-compliant defaults when sharing the client among multiple exporters.

Desired use case:

Construct a gRPC client and share it with all three signal exporters.

OtlpGrpcClientOptions client_opts;  // this should read env vars or set spec default values
auto shared_client = OtlpGrpcClientFactory::Create(client_opts);

// use a new constructor of signal options classes copy from the shared client options
// signal specific constructors override options that are not fixed at client creation
OtlpGrpcExporterOptions          trace_opts(client_opts);         
OtlpGrpcMetricExporterOptions    metric_opts(client_opts);  
OtlpGrpcLogRecordExporterOptions log_opts(client_opts);   

auto trace_exporter  = OtlpGrpcExporterFactory::Create(trace_opts, shared_client);
auto metric_exporter = OtlpGrpcMetricExporterFactory::Create(metric_opts, shared_client);
auto log_exporter    = OtlpGrpcLogRecordExporterFactory::Create(log_opts, shared_client);

Proposed change:

  • Add helpers in otlp_environment.h/cc, that read the OTLP signal independent environment variables (OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TIMEOUT, ...) and fall back to spec defaults (endpoint=http://localhost:4317, ...) for all options needed by the grpc client.

  • Add a default constructor to OtlpGrpcClientOptions in a .cc file that uses those generic helpers to populate the options

  • Add a void* constructor to OtlpGrpcClientOptions that skips populating the options for use with the void* constructors of signal specific options classes.

  • Add constructors for each OtlpGrpcClientOptions derived class that takes a OtlpGrpcClientOptions instance and copies options fixed on client creation then overrides signal-specific options as required. See the table below for which options may be overridden when a shared client is used.

gRPC Client Option Exporter Options can override with shared gRPC client?
endpoint No
SSL fields (7) No
credentials No
user_agent No
channel_arguments No
max_threads No
compression No
Retry policy fields (4) No
timeout Yes
metadata Yes
max_concurrent_requests Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with otlp_environment.h/cc and the OtlpGrpcClientOptions and signal-specific option classes described in the issue. Trace how current exporter options read environment variables, then implement and verify the shared-client constructors and option-copying behavior against the override table, including the listed OTLP defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, grpc
Domain
backend-api-design, distributed-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.