From 78056c9e02e14df444722a2d8c30eac87ee2fb76 Mon Sep 17 00:00:00 2001 From: Lalit Date: Wed, 8 Sep 2021 14:27:59 -0700 Subject: [PATCH 1/5] add documentation for GRPC Env variables --- exporters/otlp/README.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/exporters/otlp/README.md b/exporters/otlp/README.md index 8c6efe90d3..79d983bead 100644 --- a/exporters/otlp/README.md +++ b/exporters/otlp/README.md @@ -42,11 +42,27 @@ options.url = "localhost:12345"; auto exporter = std::unique_ptr(new otlp::OtlpHttpExporter(options)); ``` -### Configuration options +### Configuration options ( OTLP GRPC Exporter ) -| Option | Default | -| ------------ |----------------- | -| `endpoint` | `localhost:4317` | +| Option | Env Variable |Default | Description | +| ------------ |---------------|------------ |----------------| +| `endpoint` | `OTEL_EXPORTER_OTLP_GRPC_ENDPOINT` |`localhost:4317` | The OTLP GRPC endpoint to connect to | +| `use_ssl_credentials` | `OTEL_EXPORTER_OTLP_GRPC_SSL_ENABLE` | `false` | Whether the endpoint is SSL enabled | +| `ssl_credentials_cacert_path` | n/a | `""` | SSL Certificate file path | +| `ssl_credentials_cacert_as_string` | `OTEL_EXPORTER_OTLP_GRPC_SSL_CERTIFICATE` | `""` | SSL Certifcate as in-memory string | + +Note: These env variables names are not same as in [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.0.0/specification/protocol/exporter.md). +And there is no plan to remove them when the support for environment variables as required by specification is added. + +### Configuration options ( OTLP HTTP Exporter ) + +| Option | Env Variable |Default | Description | +| ------------ |-----|------------ |------| +| `url` | n/a | `http://localhost:4317/v1/traces` | The OTLP HTTP endpoint to connect to | +| `content_type` | n/a | `application/json` | Data format used - JSON or Binary | +| `json_bytes_mapping` | n/a | `JsonBytesMappingKind::kHexId` | Encoding used for trace_id and span_id | +| `use_json_name` | n/a | `false` | Whether to use json name of protobuf field to set the key of json | +| `timeout` | n/a | `3000 ms` | http timeout | ## Example From be95e8411422e89d73082ee1a3e81078a0aa7dfc Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 8 Sep 2021 14:48:17 -0700 Subject: [PATCH 2/5] Update exporters/otlp/README.md Co-authored-by: Tom Tan --- exporters/otlp/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/README.md b/exporters/otlp/README.md index 79d983bead..f17849c3ed 100644 --- a/exporters/otlp/README.md +++ b/exporters/otlp/README.md @@ -51,7 +51,7 @@ auto exporter = std::unique_ptr(new otlp::OtlpHttpExport | `ssl_credentials_cacert_path` | n/a | `""` | SSL Certificate file path | | `ssl_credentials_cacert_as_string` | `OTEL_EXPORTER_OTLP_GRPC_SSL_CERTIFICATE` | `""` | SSL Certifcate as in-memory string | -Note: These env variables names are not same as in [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.0.0/specification/protocol/exporter.md). +Note: These environment variable names are not same as in [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.0.0/specification/protocol/exporter.md). And there is no plan to remove them when the support for environment variables as required by specification is added. ### Configuration options ( OTLP HTTP Exporter ) From 8123f60d090c297b6b22beec18a2d04edee40313 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 8 Sep 2021 15:14:26 -0700 Subject: [PATCH 3/5] Update exporters/otlp/README.md Co-authored-by: Tom Tan --- exporters/otlp/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/README.md b/exporters/otlp/README.md index f17849c3ed..e7bfb4ccc4 100644 --- a/exporters/otlp/README.md +++ b/exporters/otlp/README.md @@ -62,7 +62,7 @@ And there is no plan to remove them when the support for environment variables a | `content_type` | n/a | `application/json` | Data format used - JSON or Binary | | `json_bytes_mapping` | n/a | `JsonBytesMappingKind::kHexId` | Encoding used for trace_id and span_id | | `use_json_name` | n/a | `false` | Whether to use json name of protobuf field to set the key of json | -| `timeout` | n/a | `3000 ms` | http timeout | +| `timeout` | n/a | `30000 ms` | http timeout | ## Example From 8cdba65d26b452e738d0a1544bc188ba0bf29e30 Mon Sep 17 00:00:00 2001 From: Lalit Date: Thu, 9 Sep 2021 14:44:32 -0700 Subject: [PATCH 4/5] spec compliant env var --- exporters/otlp/README.md | 15 ++--- .../exporters/otlp/otlp_grpc_exporter.h | 60 ++++++++++++++----- exporters/otlp/src/otlp_grpc_exporter.cc | 1 + .../otlp/test/otlp_grpc_exporter_test.cc | 18 +++--- 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/exporters/otlp/README.md b/exporters/otlp/README.md index 79d983bead..35e5a6c45e 100644 --- a/exporters/otlp/README.md +++ b/exporters/otlp/README.md @@ -46,13 +46,14 @@ auto exporter = std::unique_ptr(new otlp::OtlpHttpExport | Option | Env Variable |Default | Description | | ------------ |---------------|------------ |----------------| -| `endpoint` | `OTEL_EXPORTER_OTLP_GRPC_ENDPOINT` |`localhost:4317` | The OTLP GRPC endpoint to connect to | -| `use_ssl_credentials` | `OTEL_EXPORTER_OTLP_GRPC_SSL_ENABLE` | `false` | Whether the endpoint is SSL enabled | -| `ssl_credentials_cacert_path` | n/a | `""` | SSL Certificate file path | -| `ssl_credentials_cacert_as_string` | `OTEL_EXPORTER_OTLP_GRPC_SSL_CERTIFICATE` | `""` | SSL Certifcate as in-memory string | - -Note: These env variables names are not same as in [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.0.0/specification/protocol/exporter.md). -And there is no plan to remove them when the support for environment variables as required by specification is added. +| `endpoint` | `OTEL_EXPORTER_OTLP_ENDPOINT` | `http://localhost:4317`| The OTLP GRPC endpoint to connect to | +| | `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | | | +| `use_ssl_credentials` | `OTEL_EXPORTER_OTLP_SSL_ENABLE`| `false` | Whether the endpoint is SSL enabled | +| | `OTEL_EXPORTER_OTLP_TRACES_SSL_ENABLE` | | | +| `ssl_credentials_cacert_path` | `OTEL_EXPORTER_OTLP_CERTIFICATE` | `""` | SSL Certificate file path | +| | `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` | | | +| `ssl_credentials_cacert_as_string` | `OTEL_EXPORTER_OTLP_CERTIFICATE_STRING` | `""` | SSL Certifcate as in-memory string | +| | `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE_STRING` | | | | ### Configuration options ( OTLP HTTP Exporter ) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h index 31ad058c6d..af3c97b4ab 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h @@ -19,19 +19,30 @@ namespace exporter namespace otlp { -inline const std::string GetOtlpGrpcDefaultEndpoint() +inline const std::string GetOtlpDefaultEndpoint() { - constexpr char kOtlpGrpcEndpointEnv[] = "OTEL_EXPORTER_OTLP_GRPC_ENDPOINT"; - constexpr char kOtlpGrpcEndpointDefault[] = "localhost:4317"; + constexpr char kOtlpTracesEndpointEnv[] = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"; + constexpr char kOtlpEndpointEnv[] = "OTEL_EXPORTER_OTLP_ENDPOINT"; + constexpr char kOtlpEndpointDefault[] = "http://localhost:4317"; - auto endpoint = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpGrpcEndpointEnv); - return endpoint.size() ? endpoint : kOtlpGrpcEndpointDefault; + auto endpoint = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpTracesEndpointEnv); + if (endpoint.size() == 0) + { + endpoint = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpEndpointEnv); + } + return endpoint.size() ? endpoint : kOtlpEndpointDefault; } -inline const bool GetOtlpGrpcDefaultIsSslEnable() +inline const bool GetOtlpDefaultIsSslEnable() { - constexpr char kOtlpGrpcIsSslEnableEnv[] = "OTEL_EXPORTER_OTLP_GRPC_SSL_ENABLE"; - auto ssl_enable = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpGrpcIsSslEnableEnv); + constexpr char kOtlpTracesIsSslEnableEnv[] = "OTEL_EXPORTER_OTLP_TRACES_SSL_ENABLE"; + constexpr char kOtlpIsSslEnableEnv[] = "OTEL_EXPORTER_OTLP_SSL_ENABLE"; + + auto ssl_enable = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpTracesIsSslEnableEnv); + if (ssl_enable.size() == 0) + { + ssl_enable = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpIsSslEnableEnv); + } if (ssl_enable == "True" || ssl_enable == "TRUE" || ssl_enable == "true" || ssl_enable == "1") { return true; @@ -39,10 +50,29 @@ inline const bool GetOtlpGrpcDefaultIsSslEnable() return false; } -inline const std::string GetOtlpGrpcDefaultSslCertificate() +inline const std::string GetOtlpDefaultSslCertificatePath() +{ + constexpr char kOtlpTracesSslCertificate[] = "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE"; + constexpr char kOtlpSslCertificate[] = "OTEL_EXPORTER_OTLP_CERTIFICATE "; + auto ssl_cert_path = + opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpTracesSslCertificate); + if (ssl_cert_path.size() == 0) + { + ssl_cert_path = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpSslCertificate); + } + return ssl_cert_path.size() ? ssl_cert_path : ""; +} + +inline const std::string GetOtlpDefaultSslCertificateString() { - constexpr char kOtlpGrpcSslCertificate[] = "OTEL_EXPORTER_OTLP_GRPC_SSL_CERTIFICATE"; - auto ssl_cert = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpGrpcSslCertificate); + constexpr char kOtlpTracesSslCertificateString[] = "OTEL_EXPORTER_OTLP_CERTIFICATE_STRING"; + constexpr char kOtlpSslCertificateString[] = "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE_STRING "; + auto ssl_cert = + opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpTracesSslCertificateString); + if (ssl_cert.size() == 0) + { + ssl_cert = opentelemetry::sdk::common::GetEnvironmentVariable(kOtlpSslCertificateString); + } return ssl_cert.size() ? ssl_cert : ""; } @@ -52,15 +82,15 @@ inline const std::string GetOtlpGrpcDefaultSslCertificate() struct OtlpGrpcExporterOptions { // The endpoint to export to. By default the OpenTelemetry Collector's default endpoint. - std::string endpoint = GetOtlpGrpcDefaultEndpoint(); + std::string endpoint = GetOtlpDefaultEndpoint(); // By default when false, uses grpc::InsecureChannelCredentials(); If true, // uses ssl_credentials_cacert_path if non-empty, else uses ssl_credentials_cacert_as_string - bool use_ssl_credentials = GetOtlpGrpcDefaultIsSslEnable(); + bool use_ssl_credentials = GetOtlpDefaultIsSslEnable(); // ssl_credentials_cacert_path specifies path to .pem file to be used for SSL encryption. - std::string ssl_credentials_cacert_path = ""; + std::string ssl_credentials_cacert_path = GetOtlpDefaultSslCertificatePath(); // ssl_credentials_cacert_as_string in-memory string representation of .pem file to be used for // SSL encryption. - std::string ssl_credentials_cacert_as_string = GetOtlpGrpcDefaultSslCertificate(); + std::string ssl_credentials_cacert_as_string = GetOtlpDefaultSslCertificateString(); }; /** diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index 2d522ca3cd..dec65fadda 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -59,6 +59,7 @@ std::unique_ptr MakeServiceStub const OtlpGrpcExporterOptions &options) { std::shared_ptr channel; + if (options.use_ssl_credentials) { grpc::SslCredentialsOptions ssl_opts; diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index d2b999382a..23c27242be 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -139,12 +139,12 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigSslCredentialsTest) TEST_F(OtlpGrpcExporterTestPeer, ConfigFromEnv) { const std::string cacert_str = "--begin and end fake cert--"; - const std::string cacert_env = "OTEL_EXPORTER_OTLP_GRPC_SSL_CERTIFICATE=" + cacert_str; + const std::string cacert_env = "OTEL_EXPORTER_OTLP_CERTIFICATE_STRING=" + cacert_str; putenv(const_cast(cacert_env.data())); - char ssl_enable_env[] = "OTEL_EXPORTER_OTLP_GRPC_SSL_ENABLE=True"; + char ssl_enable_env[] = "OTEL_EXPORTER_OTLP_SSL_ENABLE=True"; putenv(ssl_enable_env); const std::string endpoint = "http://localhost:9999"; - const std::string endpoint_env = "OTEL_EXPORTER_OTLP_GRPC_ENDPOINT=" + endpoint; + const std::string endpoint_env = "OTEL_EXPORTER_OTLP_ENDPOINT=" + endpoint; putenv(const_cast(endpoint_env.data())); std::unique_ptr exporter(new OtlpGrpcExporter()); @@ -152,14 +152,14 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigFromEnv) EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); # if defined(_MSC_VER) - putenv("OTEL_EXPORTER_OTLP_GRPC_ENDPOINT="); - putenv("OTEL_EXPORTER_OTLP_GRPC_SSL_CERTIFICATE="); - putenv("OTEL_EXPORTER_OTLP_GRPC_SSL_ENABLE="); + putenv("OTEL_EXPORTER_OTLP_ENDPOINT="); + putenv("OTEL_EXPORTER_OTLP_CERTIFICATE_STRING="); + putenv("OTEL_EXPORTER_OTLP_SSL_ENABLE="); # else - unsetenv("OTEL_EXPORTER_OTLP_GRPC_ENDPOINT"); - unsetenv("OTEL_EXPORTER_OTLP_GRPC_SSL_CERTIFICATE"); - unsetenv("OTEL_EXPORTER_OTLP_GRPC_SSL_ENABLE"); + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_CERTIFICATE_STRING"); + unsetenv("OTEL_EXPORTER_OTLP_SSL_ENABLE"); # endif } From 9f3d016f2c5c07f5e6600119dca8cbf05d49756d Mon Sep 17 00:00:00 2001 From: Lalit Date: Thu, 9 Sep 2021 15:11:39 -0700 Subject: [PATCH 5/5] markdown lint --- exporters/otlp/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/exporters/otlp/README.md b/exporters/otlp/README.md index c2c4870cbe..7bb5fd951b 100644 --- a/exporters/otlp/README.md +++ b/exporters/otlp/README.md @@ -55,7 +55,6 @@ auto exporter = std::unique_ptr(new otlp::OtlpHttpExport | `ssl_credentials_cacert_as_string` | `OTEL_EXPORTER_OTLP_CERTIFICATE_STRING` | `""` | SSL Certifcate as in-memory string | | | `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE_STRING` | | | | - ### Configuration options ( OTLP HTTP Exporter ) | Option | Env Variable |Default | Description |